I send GetFeatureInfo request to server with ajax and get the featureset data. I want to zoom a selected feature.

Object {type: "Feature", id: "mydata.39025", geometry: Object, geometry_name: "geom", properties: Object…}

Selected feature can be a point, multilinestring, polygon. So I can not cast it as an OpenLayers.Geometry.Point, or OpenLayers.Geometry.Polyline.

How can I zooom it?


A late answer :-)

Every feature has an ol.geometry object, and an ol.geometry has an ol.Extent object, which is an array of numbers representing an extent: [minx, miny, maxx, maxy].

You can use this extent to calculate the center coordinate and to set the map->view center to this position. Afterwards you can calculate a resolution and set this to the view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.