-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setBearing #278
Comments
I think the best way to do this is a combination of API and MapillaryJS. For the API, you'll want to take the coordinates you want to move close to, and make an API call using Here is an example:
This uses the same coordinates for both, and has a radius of 40 meters--default radius is 100 meters. You can also put two different sets of coordinates, for example you may want images on the west side of a river but looking at a point on the east side. The The API response will show the "best" image first, typically that is most directly in the camera angle's field of view, and nearest to the You will then grab the image key from the API response, and have the viewer call |
This is mostly an issue with 360 imagery, as this standard approach above works pretty well for regular images, but breaks down with 360.
Yep, that's exactly what I did, grabbing node.latLon and calculated the bearing, but without a setBearing method that approach is stalled. Open to other options in the API, if setBearing isn't necessarily the best way. |
@andrewharvey Thanks for the suggestion. When implementing
We do not plan to add a var mly = new Mapillary.Viewer(
'mly',
// Replace this with your own client ID from mapillary.com
'<your-client-id>',
null);
mly.moveToKey('Q1PJAgFZcr1iFgndBGcVaQ').then(
function(node) { setBearing(node); },
function(error) { console.error(error); });
function setBearing(node) {
if (!node.fullPano) {
// We are only interested in setting the bearing for full 360 panoramas.
return;
}
var nodeBearing = node.computedCA; // Computed node compass angle (equivalent
// to bearing) is used by mjs when placing
// the node in 3D space.
var desiredBearing = 90; // Your desired bearing.
var basicX = bearingToBasic(desiredBearing, nodeBearing);
var basicY = 0.5; // Vertical center
var center = [basicX, basicY];
mly.setCenter(center);
}
/**
* Convert a desired bearing to a basic X image coordinate for
* a specific node bearing.
*
* Works only for a full 360 panorama.
*/
function bearingToBasic(desiredBearing, nodeBearing) {
// 1. Take difference of desired bearing and node bearing in degrees.
// 2. Scale to basic coordinates.
// 3. Add 0.5 because node bearing corresponds to the center
// of the image. See
// https://mapillary.github.io/mapillary-js/classes/viewer.html
// for explanation of the basic coordinate system of an image.
var basic = (desiredBearing - nodeBearing) / 360 + 0.5;
// Wrap to a valid basic coordinate (on the [0, 1] interval).
// Needed when difference between desired bearing and node
// bearing is more than 180 degrees.
return wrap(basic, 0, 1);
}
/**
* Wrap a value on the interval [min, max].
*/
function wrap(value, min, max) {
var interval = (max - min);
while (value > max || value < min) {
if (value > max) {
value = value - interval;
} else if (value < min) {
value = value + interval;
}
}
return value;
}
// Resize the viewer when the window is resized.
window.addEventListener("resize", function() { mly.resize(); }); There is some extensive commenting in the code which makes it look a bit more verbose than it actually is. Let me know if you have any questions and whether this resolves your use case or not. |
Thanks for the code @oscarlorentzon, it works perfectly! Agreed this is only really useful for 360, but I think it would be nice to wrap it up so people building apps have a simpler interface, it's a lot of code at the moment and it's at a level deeper than I'd like. I'd even go one step higher and have a lookAt method, which given a lat,lon will automatically set the bearing based on the current nodes lat,lon. I'm not sure I get point 2:
Does that matter? The final coordinates passed to setCenter are internal details, so it doesn't matter if next time they make the call they are different. |
Point 2 is relevant when one wants to be able to share a specific viewpoint of the image that is consistent over time. That for example applies to sharing a link like https://www.mapillary.com/app/?lat=55.60292981583336&lng=13.013955345277736&z=17&pKey=_q5-pCxe74HohcPQiXXPZw&x=0.2727110367181517&y=0.4809297983683465&zoom=1.1795239380556855&focus=photo where the Also agree that it is a lot of code and quite deep. The |
This might unlock #156. At the moment we can moveCloseTo, but especially for 360 images we might need to set the bearing so that the image is looking at a given lat,lon.
The text was updated successfully, but these errors were encountered: