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: [email protected] [mailto:[email protected]] On Behalf Of cgp Sent: Thursday, December 03, 2009 10:36 AM To: [email protected] 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 [email protected] http://openlayers.org/mailman/listinfo/users _______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users
