[OpenLayers-Users] steps to zoom and center on the selected polygon

Mr. Puneet Kishor punk.kish at gmail.com
Fri Jan 13 23:12:45 EST 2012


On Jan 13, 2012, at 4:48 PM, Arnd Wippermann wrote:

> Hi,
> 
> register "featureadded" for the layer and create a zoom function
> 
> function zoomToLeftHalf(evt)
> {
>    var arrB = evt.feature.geometry.getBounds().toArray();
>    var dx = arrB[2]-arrB[0];
>    var bounds = new OpenLayers.Bounds(arrB[0], arrB[1], arrB[2]+dx,
> arrB[3]);
>    map.zoomToExtent(bounds);
> }
> map.layers[2].events.register("featureadded", map.layers[2],
> zoomToLeftHalf);
> 



Thanks Arnd. This works brilliantly.


> 
> Regards,
> Arnd 
> 
> -----Ursprüngliche Nachricht-----
> Von: openlayers-users-bounces at lists.osgeo.org
> [mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Puneet
> Kishor
> Gesendet: Freitag, 13. Januar 2012 21:03
> An: openlayers-users at lists.osgeo.org
> Betreff: [OpenLayers-Users] steps to zoom and center on the selected polygon
> 
> I am trying to accomplish the following, and would appreciate advice on how
> to go about doing it --
> 
> 1. the user click,click,click... double-clicks to create a polygon;
> 
> 2. the map zooms to the polygon so that the polygon occupies the left half
> of the browser window.
> 
> Here is my attempt to draw the interface --
> 
> 
> +----------------------------------+
> |                 .                |
> |                 .                |
> |                 .                |
> |                 .                |
> |                 .                |
> |     A           .        B       |
> |                 .                |
> |                 .                |
> |                 .                |
> |                 .                |
> +----------------------------------+
> 
> so, once a polygon is drawn, the map zooms so the drawn polygon is centered
> to its full extent within A above.
> 
> Suggestions welcome. Many thanks,
> 
> --
> Puneet Kishor_______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
> 



More information about the Users mailing list