[OpenLayers-Users] building the right type of object
Eric Lemoine
eric.lemoine at camptocamp.com
Tue Mar 8 06:35:40 EST 2011
On Tue, Mar 8, 2011 at 12:07 PM, Leigh Holcombe
<lholcombe at triple-bypass.net> wrote:
> On Mar 7, 2011, at 7:39 PM, Eric Lemoine wrote:
>
>> On Monday, March 7, 2011, Leigh Holcombe <lholcombe at triple-bypass.net> wrote:
>>> Greetings,
>>>
>>> I have a layer constructed from a GeoJSON file, using the following code:
>>> var trail1 = new OpenLayers.Layer.Vector("Kaau Crater", {strategies: [new OpenLayers.Strategy.Fixed()], protocol: new OpenLayers.Protocol.HTTP({url: "kaaucrater-rb.json", format: new OpenLayers.Format.GeoJSON()}), styleMap: styles, projection: utm4n});
>>>
>>> What I'd like to do is get the bounds or centerpoint of the GeoJSON file automatically, perhaps by using something like getBounds or getCenterLonLat, but my newb mind is discovering that I can't perform these operations on the layer object I have created. I suspect I need to also create a geometry layer from the GeoJSON file, but I am not sure how to do that. Can anyone provide any direction?
>>
>> Hi. The Vector layer has a getDataExtent method, that you can call
>> when the features have been added to the layer:
>>
>> trail1.events.on({"loadend": function() {
>> var bounds = trail1.getDataExtent();
>> }});
>>
>> --
>> Eric Lemoine
>>
>
> Thank you, that works very well. However, it's a little too late in the process. My plan is to use the bounds/extent to calculate the center of the overlay, and then pass that to map.setCenter. Is there a way to make this happen before the loadend?
What about
trail1.events.on({"loadend": function() {
map.zoomToExtent(trail1.getDataExtent());
}});
?
>
> Additionally, where can I find a complete list of the standard events, such as loadstart and loadend?
For example, layer events are documented here:
<http://dev.openlayers.org/releases/OpenLayers-2.10/doc/apidocs/files/OpenLayers/Layer-js.html#OpenLayers.Layer.EVENT_TYPES>
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
More information about the Users
mailing list