[OpenLayers-Users] Is there an easy way to center and zoom the map automatically based on the placemarks that are on it?
Tobias Reinicke
ramotswa at gmail.com
Wed Jul 4 00:17:16 PDT 2012
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> wrote:
> Do you have, or know where I could find, an example of this being
> implemented on KML layer?
>
> Aaron E-Jhttp://www.otherrealm.orghttp://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
> 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/d0df8098/attachment.html>
More information about the Users
mailing list