[OpenLayers-Users] on window size change - zoom the map instead of enlarging the extent

Eric Lemoine eric.lemoine at camptocamp.com
Wed Dec 2 12:06:26 EST 2009


On Wed, Dec 2, 2009 at 11:10 AM, Adrian Popa
<adrian_gh.popa at romtelecom.ro> wrote:
> Hello everyone,
>
> I would like to change the behavior of OpenLayers like this:
>
> Now, when the user resizes the browser window, the map  remains centered
> on the previous view, the zoom remains the same, and the edges of the
> map are downloaded.
>
> I would like on window resize, to keep the current view in the visible
> part on the map and just do a zoom to extent (for my current extent).
> The change should thus be in the zoom used.
>
> I want to know if this is possible (and if I can change a
> on-window-resize handler action), or if I need to build some ugly hack
> around it. A pointer to the relevant documentation or an example is
> highly appreciated.

You may want to try to override the Map's updateSize method. You can
do that either by overriding the updateSize method in your map
instance:

var map = new OpenLayers.Map("div", {
    updateSize: function() {
    }
});

or by creating a custom Map class:

CustomMap = OpenLayers.Class(OpenLayers.Map, {
    updateSize: function() {
    }
});

I'd recommend you look at the Map.resizeMap method to understand what
it does first.

Cheers,
-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com



More information about the Users mailing list