[OpenLayers-Users] Is there an easy way to center and zoom the map automatically based on the placemarks that are on it?

Aaron E-J azintirea at gmail.com
Wed Jul 4 06:55:34 PDT 2012


Great thanks, I'll try it out tomorrow (work related and I'm off today)

Aaron E-J
http://www.otherrealm.org
http://www.prospectdesigns.com
Vision without action is a daydream,
Action without vision is a nightmare,
One needs both to succeed.

On 7/4/2012 3:17 AM, Tobias Reinicke wrote:
> The same function is also available for vector layers;
> http://dev.openlayers.org/docs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.getDataExtent 
>
>
> I presume you will have set your kml layer up somewhere along the 
> lines of;
>
> var myKMLLayer = new OpenLayers.Layer.Vector("KML", {
>
>             strategies: [new OpenLayers.Strategy.Fixed()],
>             protocol: new OpenLayers.Protocol.HTTP({
>                 url: "whatever",
>                 format: new OpenLayers.Format.KML({
>                     extractStyles: true,
>                     extractAttributes: true,
>                     maxDepth: 2
>                 })
>             })
>         };
> Then all you do is call
> map.zoomToExtent(myKMLLayer.getDataExtent());
>
> That work for you?
>
> Toby
>
>
>
>
> On 4 July 2012 01:21, Aaron E-J <azintirea at gmail.com 
> <mailto:azintirea at gmail.com>> wrote:
>
>     Do you have, or know where I could find, an example of this being
>     implemented on KML layer?
>
>     Aaron E-J
>     http://www.otherrealm.org
>     http://www.prospectdesigns.com
>     Vision without action is a daydream, Action without vision is a
>     nightmare, One needs both to succeed.
>
>     On 7/3/2012 5:52 PM, Greg Allensworth wrote:
>>     On 7/3/2012 2:11 PM, Aaron E-J wrote:
>>>     Is there an easy way to center and zoom the map automatically
>>>     based on
>>>     the placemarks that are on it?I have it so that one can filter
>>>     placemarks based on user input but I'm not sure how to dynamically
>>>     update the map to fit the newly filtered content.Thanks for any
>>>     insight
>>>     that can be given regarding this matter.
>>
>>     An OpenLayers.Layer.Markers instance, has a method called
>>     getDataExtent() This should do most of what you want.
>>
>>     It's not automatic, though. You'd still need to call
>>     map.zoomToExtent() after the markers have been added to the layer.
>>
>>     http://dev.openlayers.org/docs/files/OpenLayers/Layer/Markers-js.html
>>
>>
>
>
>
>     _______________________________________________
>     Users mailing list
>     Users at lists.osgeo.org <mailto: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/20120704/a7926c70/attachment.html>


More information about the Users mailing list