1

I have a map with panning and zooming disabled, creating a bounding box. This map has a geojson layer with features and tooltips displaying underlying data.

The issue is when the user mouses over features on the outer edges of the visible map area, the tooltips are outside of the div view. Because there's no panning enabled, the user is SOL to see the tip.

How can I keep the tips within the visible map view bound by extents?

2

Take a look at the keepView option of the Popup layer. My guess is when you set it to true instead of the default false it will keep the tooltip/popup visible within the current map extent.

However if you can post the code you're working on in a fiddle, it would be helpful to test whether my assumption is correct.

  • What if the popup is outside the viewport ? – Stranded Kid Sep 18 '15 at 20:11
1

I have a similar case where user can not pan nor zoom, but still open popup.

Once you've zoomed on the data, you could do something like this :

var defaultBounds = map.getBounds();

then when a popup is opened, let the default popup panning go through (the map might be panned if the popup is outside viewport), and then, when the popup is closed

map.on("popupclose", function() {
    this.fitBounds(defaultBounds); // or yourLayer.getBounds() if you don't want to rely on "static" var
}, map);

This will pan back to original extent. I go with it and it's kinda fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.