Skip to content
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

zoomToEntity fails when selecting a relation from the search results #4276

Closed
bhousel opened this issue Aug 25, 2017 · 6 comments
Closed

zoomToEntity fails when selecting a relation from the search results #4276

bhousel opened this issue Aug 25, 2017 · 6 comments
Labels
bug A bug - let's fix this! help wanted For intermediate contributors, requires investigation or knowledge of iD code

Comments

@bhousel
Copy link
Member

bhousel commented Aug 25, 2017

screenshot 2017-08-25 11 49 44

What is supposed to happen:

You click on Philadelphia in the geocoder search results and the map moves to someplace around Philadelphia.

What happens:

The map doesn't actually go anywhere.

Why:

We fetch the Philadelphia relation from the OSM API using this zoomToEntity function:

iD/modules/core/context.js

Lines 118 to 126 in c0d224b

context.zoomToEntity = function(id, zoomTo) {
if (zoomTo !== false) {
this.loadEntity(id, function(err, result) {
if (err) return;
var entity = _.find(result.data, function(e) { return e.id === id; });
if (entity) { map.zoomTo(entity); }
});
}

It fetches the relation, but not the members, and so when map.zoomTo() tries to calculate an extent, it can't actually do this, and just returns without moving the map anywhere:

iD/modules/renderer/map.js

Lines 650 to 652 in c0d224b

map.zoomTo = function(entity, zoomLimits) {
var extent = entity.extent(context.graph());
if (!isFinite(extent.area())) return;

Interestingly, if you try these steps a second time, iD will actually go to Philadelphia because somehow some of its relation members got loaded. I'm curious about how/where that happens, because it's not something I expected.

@bhousel bhousel added the bug A bug - let's fix this! label Aug 25, 2017
@willemarcel
Copy link
Contributor

I couldn't reproduce with nodes, but this happens with ways that aren't part of relations.

@JamesKingdom
Copy link
Collaborator

The sidebar also opens and is buggy if you go direct to a relation from a url, here's an example.

You are left at zoom 2 at 0,0, and if anything updates, the sidebar closes and changes to Zoom in to edit

@bhousel bhousel added good first issue Best for first-time contributors. No experience necessary! Hacktoberfest labels Oct 1, 2017
@bhousel bhousel added help wanted For intermediate contributors, requires investigation or knowledge of iD code and removed good first issue Best for first-time contributors. No experience necessary! labels Oct 12, 2017
@Zverik
Copy link
Contributor

Zverik commented Oct 16, 2017

Heard a complaint about this from a fellow mapper. A test case: www.openstreetmap.org/edit?way=26233048 should zoom to way, but currently it shows the whole world. I understand this is not easy fixable and not of priority, but still it would be nice to have.

Maybe you could query the Overpass API for a quick fix? Something like [out:json];way(id:12345);out center;

@1ec5
Copy link
Collaborator

1ec5 commented Oct 16, 2017

The same thing happens if you search for a way or node ID, like w26233048. As in the original post, iD zooms and pans correctly the second time you search for that ID and select the result.

@bhousel
Copy link
Member Author

bhousel commented Nov 9, 2017

Looking at it more, the issue is probably this block of code.

We can delay fetching and parsing the tiles, but we shouldn't delay history.merge. The code below will call the loadTiles and loadEntity callbacks before those entities are actually merged into the graph. This is almost certainly causing a bunch of random issues, including the intermittent history restore and conflict resolution bugs some people are reporting.

iD/modules/core/context.js

Lines 114 to 144 in 9fa078b

/* Connection */
var entitiesLoaded = utilCallWhenIdle(function entitiesLoaded(err, result) {
if (!err) history.merge(result.data, result.extent);
});
context.preauth = function(options) {
if (connection) {
connection.switch(options);
}
return context;
};
context.loadTiles = utilCallWhenIdle(function(projection, dimensions, callback) {
function done(err, result) {
entitiesLoaded(err, result);
if (callback) callback(err, result);
}
if (connection) {
connection.loadTiles(projection, dimensions, done);
}
});
context.loadEntity = function(id, callback) {
function done(err, result) {
entitiesLoaded(err, result);
if (callback) callback(err, result);
}
if (connection) {
connection.loadEntity(id, done);
}
};

@Zverik
Copy link
Contributor

Zverik commented Nov 12, 2017

It works! Thank you, Bryan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug - let's fix this! help wanted For intermediate contributors, requires investigation or knowledge of iD code
Projects
None yet
Development

No branches or pull requests

5 participants