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

Calling LMap.zoomToContent() throws exception on client side if map is empty #179

Open
dominic-simplan opened this issue Apr 30, 2018 · 2 comments

Comments

@dominic-simplan
Copy link

Calling LMap.zoomToContent() while the map is empty causes JavaScript errors on the client side:

SEVERE: Error in resize listener
com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'invalidateSize' of undefined
SEVERE: (TypeError) : Cannot read property 'addControl' of undefined
com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'addControl' of undefined
SEVERE: (TypeError) : Cannot read property 'setZIndex' of undefined
com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'setZIndex' of undefined
SEVERE: (TypeError) : Cannot read property 'addLayer' of undefined
com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'addLayer' of undefined

The getContentBounds() method returns an empty GeometryCollection, which seems to lead to Bounds with an infinity southeast coordinate in the zoomToExtent method (and therefore probably fails on the client side?):

Bounds bounds = JTSUtil.getBounds(geometry);
zoomToExtent(bounds);

Possible solution might be to add an !contentBounds.isEmpty() check to the zoomToContent() method?

@mstahv
Copy link
Owner

mstahv commented Jul 5, 2018

I can't reproduce the issue. Are you using the latest version? If not, can you provide a minimalistic code example to reproduce the issue?

@octavm
Copy link
Contributor

octavm commented Aug 13, 2018

Here is some code to reproduce the issue:

LPolyline lPolyline = new LPolyline(new LineString(new CoordinateArraySequence(new Coordinate[]{}),
				new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING))));
leafletMap.addLayer(lPolyline);
leafletMap.zoomToContent();

The getContentBounds returns "LINESTRING EMPTY", the contentBounds!=null check passes, in method zoomToExtent(), JTSUtil.getBounds(geometry), returns Bounds{southWestLng=1.7976931348623157E308, southWestLat=1.7976931348623157E308, northEastLng=-Infinity, northEastLat=-Infinity}.

As you can see the Bounds have infinite coordinate for northEastLng, and nortEastLat.

Then program flows into zoomToExtent(Bounds) method where RpcProxy is called with infinite coordinate Bounds and fails on the client side.

As @dominic-simplan suggests, a possible solution in LMap can be:

if (contentBounds != null && !contentBounds.isEmpty()) {
    zoomToExtent(contentBounds);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants