var feature_bounds= layer.getFeatureById(feature_id).geometry.getBounds(); http://dev.openlayers.org/docs/files/OpenLayers/Geometry-js.html#OpenLayers.Geometry.getBounds
map.zoomToExtent(feature_bounds,true); cheers On Thu, Dec 3, 2009 at 12:36 AM, cgp <[email protected]> wrote: > > 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-feature-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 > -- Ivan Grcic _______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users
