[OpenLayers-Users] Is there a way to get the absolute bounding box of a feature in a layer?

Brad Spencer brad at cubewerx.com.au
Wed Dec 2 18:59:30 EST 2009


I do this in two ways so if there is a better way then I'd like to know.
1) When I load all my data into my repository I pre-process the data and
build a BBox attribute or every polygon in the load set (layer). Then I just
do either a getFeature or a getfeatureinfo to pick off the BBox attribute.
2) If the layer was created before I started adding BBoxes for each feature
- I can determine this from a return of a getFeature request - I then parse
the GML geometry to generate a BBox.

These can be done either at the client or on the server (I use PHP).

Cheers, Brad... 

-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] On
Behalf Of cgp
Sent: Thursday, December 03, 2009 10:36 AM
To: users at openlayers.org
Subject: [OpenLayers-Users] Is there a way to get the absolute bounding box
of a feature in a layer?


Please see image attached.  http://n2.nabble.com/file/n4103130/feature.png 

My goal is to zoom in to a feature when I click on a button. 

My code would be essentially like this (assuming all required declarations
are made):

$("#zoomToFeatureButton").click(function(){
     var feature_id = $("#input_feat_id").val();
     var bounds =  getFeatureBounds(feature_id );       //get bounds of
feature
     zoomToFeature(bounds );
}

	function zoomToFeature(data) {
		var bounds = data.split("^"); //bounds passed in 
		
		var min_x = bounds[0];
		var min_y = bounds[1];
		var max_x = bounds[2];
		var max_y = bounds[3];
		
		var feature_bounds = new OpenLayers.Bounds(min_x, min_y,
max_x, max_y);
		
		map.zoomToExtent(feature_bounds,true);
	}



My problem is within getFeatureBounds(feature_id ). I can't seem to find
anything that would allow me to get the bounding box of a feature. If I can
get the min x, min y, max x and max y of a feature, will that let me create
a Bounds object and use that for zooming? 

Thanks.

-- 
View this message in context:
http://n2.nabble.com/Is-there-a-way-to-get-the-absolute-bounding-box-of-a-fe
ature-in-a-layer-tp4103130p4103130.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list