[OpenLayers-Users] Restrict map dragging to sceen size with an Image Layer

mhicauber mathieuhicauber at gmail.com
Sat Feb 15 04:33:52 PST 2014


Hi,

I'm a total newby to geographical things, so please excuse my lack of
knowledge.
I want to do a web page that displays an image that user can zoom / drag. On
this image, I want to display points an polygones that will trigger actions
when clicked.

Everything is working rather ok, I'm using ImageLayer to display my "map"
and I'm able to draw onto it (still fighting to catch click events on
features, but I think I'm not far to succeed.

But my main problem is that I can't manage to restrict the map to the screen
size and fordbid dragging it out of screen : whend displayed the map is OK
and fill the whole screen, but one can drag it on every directions and a
white border appear.

Can anyone tell my how I can implement such a feature ?

Below is my code to display the map :

 if (!map) {
            map = new OpenLayers.Map('map',
                {
                    controls: [
                        new OpenLayers.Control.Navigation(),
                        new OpenLayers.Control.ArgParser(),
                        new OpenLayers.Control.Attribution()
                    ]
                }
            );
        }

        if (!mapLayer) {
            mapLayer = new OpenLayers.Layer.Image(
                'City Lights',
                'images/VueMasse1080p.jpg',
                OpenLayers.Bounds.fromString("-160,-90.0,160,90.0"), // what
are those values ?
                new OpenLayers.Size(screenSize.width, screenSize.height),
                {
                    maxExtent:
OpenLayers.Bounds.fromString("-161,-90,161,90"),
                    restrictedExtent:
OpenLayers.Bounds.fromString("-161,-90,161,90")
                }
            );
            map.addLayer(mapLayer);
        }

I don't understand the different values I'm passing as Bounds attributes,
maxextent and restructedExtent. I've found those values by experimentation,
and I'd like to understand what I'm doing.

And below is a screenshot of the problem I'm talking about : on page load,
map is OK, but user is able to drag it outside of screen - and I'd lilke to
forbid this behavior. On the second image, this is the most far I'm allowed
to drag the map.

<http://osgeo-org.1560.x6.nabble.com/file/n5103961/S%C3%A9lection_097.png> 

<http://osgeo-org.1560.x6.nabble.com/file/n5103961/mapApp_-_Google_Chrome_098.png> 

Thank you very much for your help.







--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Restrict-map-dragging-to-sceen-size-with-an-Image-Layer-tp5103961.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list