angularjsopenlayersgwt-openlayersangular-openlayers

How to fit screen on map by setting zoom level manually?


I am new in openlayer maps,When you click on checkbox it will fit the maker on screen with full zoom in but I want to fit maker on screen with zoom level 11.

map.getView().fit(source.getExtent(), map.getSize());

Solution

  • You want to use:

    map.getView().fit(markerSource.getExtent(), {"maxZoom":11} );
    

    The .getView() method returns a view. The .fit method modifies that view to fit the object. The first parameter is the extent, as you have it. But the second parameter takes the options, in this case you want to specify the maximum zoom. Note: there is no minimum zoom, if the feature you are zooming to requires a smaller zoom factor, this option will be ignored. See the documentation for possible options for the view.fit() method here.