​Force V-Leaflet to return the Bounds

I’m using v-leaflet a vaadin portlet of leaflet.
I need the “Bounds” to create a WMS query.
The problem is that the method “getBound” returns null if I don’t move tha map.
If I move the map there is a MoveEnd Listener that returns the Bounds values.

Is there a way to force the UI to return the Bounds ? Or a way to fire the event ?

Or is there a way to manually calculate the Bounds ?

The fastest way, and I think the only way, to get the bounds is to set them when you create the map.

     Point p2 = new Point(45.13900627477143, 10.0579833984375);
     Point p = new Point(46.4790684581251, 7.16583251953125);
     Bounds bbox = new Bounds(p, p2);
     leafletMap.zoomToExtent(bbox);

And obviously you have to refresh the values with a MoveEndListener.

Hi, IIRC, if you add MoveEndListener, it is notified about the rendered bounds right after the initial render. Without rendering the component, it is pretty much impossible to actually visible bounds of the slippy maps “viewport”. If you have fixed size map (which it usually isn’t in GIS apps) you might be able to test the value and then use that.

cheers,
matti

Hi,

I’m using v-leaflet 0.6.1 and I cannot confirm this behavior - after map is initially rendered in browser, my MoveEndListener is not fired, and I don’t see any data regarding map bounds sent back to server. (After creation, MoveEndListener works as expected when moving map with mouse)
What could be the issue?

Hi,

I have no idea. There shouldn’t be any relevant differences with github version vs 0.6.1 and and it works perfectly for me in e.g. this test case:
https://github.com/mstahv/v-leaflet/blob/master/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ZoomLimitTest.java

Which browser are you using? Which Vaadin version? Can you post a reduced test case? Those should help to track this down.

cheers,
matti

Thanks for your reply.

I used your test case code as a part of my application, and it is working. The problem is, it stops working if I set map width and height, for example:

LMap leafletMap = new LMap();
leafletMap.setWidth(400, Unit.PIXELS);
leafletMap.setHeight(400, Unit.PIXELS);

But map is not visible if I do not set its width and height explicitly. Is this not correct way to define its size?
(I’m using Vaadin version 7.4.3 and latest Chrome)

If is just the correct way. The “fixed” size setting seems to be to isssue. Should be pretty easy to workaround. Would you open an issue to the github page?

cheers,
matti

Opened new issue at:
https://github.com/mstahv/v-leaflet/issues/79