[OpenLayers-Users] display a border at the end of the world

杨华杰 yhjhoo at gmail.com
Mon Mar 18 18:37:44 PDT 2013


Hi

Just a final conclusion.

I use the graticule to display the grid on map

http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Control/Graticule-js.html

and restrict the display area on the map


maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
restrictedExtent: new OpenLayers.Bounds(-180, -90, 180, 90)



So here is the final one.




map = new OpenLayers.Map( 'map', {
                    controls: [
graticuleCtl,
                        new OpenLayers.Control.PanZoom(),
                        new OpenLayers.Control.EditingToolbar(vlayer)
                    ],
                    zoomOffset:14,
                    maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
restrictedExtent: new OpenLayers.Bounds(-180, -90, 180, 90)
                });

                var nav = new OpenLayers.Control.NavigationHistory();
                // parent control must be added to the map
                map.addControl(nav);


                map.events.register('zoomend', map, function(e){
if(map.getZoom()<3){
//map.zoomTo(3);
nav.previousTrigger();
}
});



Hope this will help others.


Regards,
Hua Jie


On Tue, Mar 12, 2013 at 3:47 PM, 杨华杰 <yhjhoo at gmail.com> wrote:

> It's a solution but not perfect, user still able to draw outside of the
> range.
>
>
> On Tue, Mar 12, 2013 at 8:14 AM, Sergeant_york <electronicpanda at gmail.com>wrote:
>
>> If your problem is not being able to restrict people to draw outside of
>> defined borders, there is a much more easier solution by the way (inside
>> of
>> drawing borders =) )
>>
>> You can restrict OpenLayers.Map object's extent:
>>
>> http://dev.openlayers.org/docs/files/OpenLayers/Map-js.html
>> restrictedExtent        {<OpenLayers.Bounds>|Array} If provided as an
>> array, the
>> array should consist of four values (left, bottom, right, top).
>>
>>
>> Code can be like that:
>>
>> map.setOptions({restrictedExtent: map.getMaxExtent()});
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://osgeo-org.1560.n6.nabble.com/display-a-border-at-the-end-of-the-world-tp5039296p5039794.html
>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>> _______________________________________________
>> Users mailing list
>> Users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130319/2c91cdf0/attachment.html>


More information about the Users mailing list