Hello, I'm using WAB 2.2 and the Jewelry Box Theme.
I'm trying to select a feature on the map and zoom to it. I would think there would be examples of this but they sure are hard to find.
queryTask = new QueryTask(MyFeatureLayer);
query = new Query();
query.where = myWhereClause;
query.returnGeometry = true;
query.outSpatialReference = this.map.spatialReference;
queryTask.execute(query, function (results) {
var geo = results.features[0].geometry;
this.map.setExtent(geo.getExtent(),true);
});
I'm attempting to select a single point in a point feature layer and zoom to that feature.
TypeError: Cannot read property 'toJson' of null
at Object.setExtent (init.js:593)
You can't zoom to a single point using "getExtent" since, unlike a group of points or a line or a feature, it doesn't have an extent. You would have to use centerAndZoom
Ken,
Thank you for the response. Boy what a pain that option is. I'm having issues setting the levelOrFactor value. I tried 1 (one) and it zooms out to the entire background layer. I finally tried 20 (twenty) and it is at an acceptable level. Is there a "pan" option? Something that might keep the scale at the same scale the user is currently at and just move to the selected feature?
You can use centerAt if you want to keep the same zoom scale that is currently set.