gwtopenlayersgwt-openlayers

Setting min and max zoomLevels (GWT-OpenLayers)


I want to set a minimum and a maximum zoom level in my map.

My first idea was to listen to 'zoomstart' events, but the org.gwtopenmaps.openlayers.client.Map class doesn't implement any listener with such event type. Then I tried to listen to 'zoomend' events. My idea was to check the zoomlevel after the zoom event and if it is higher/lower than a threshold value than i zoom to that threshold value. Example code:

    @Override
    public void onMapZoom(MapZoomEvent eventObject) {
        if (eventObject.getSource().getZoom() > 18) {
            eventObject.getSource().zoomTo(18);
        }
    }

But i found, the zoomTo event doesn't fire in this case. Has anybody got a solution to this problem?


Solution

  • Great idea Imreking.

    I have added this to the GWT-Openlayers library. So if you download the latest version from github now you can do :

    map.setMinMaxZoomLevel(6, 8);

    And you no longer need some javascript method in your own code.

    I actually also added a showcase but having difficulties uploading it to our website.

    Uploading the new showcase has now succeeded. See http://demo.gwt-openlayers.org/gwt_ol_showcase/GwtOpenLayersShowcase.html?example=Min%20max%20zoom%20example to see an example of newly added Map.setMinMaxZoomLevel(minZoom, maxZoom).