I can easily zoom to a selection of points in my FeatureLayer with this handy one-liner:
map.setExtent(graphicsUtils.graphicsExtent(myFeatureLayer.getSelectedFeatures()), true);
In this case, it's assigned to a button.
How do I utilize the map.centerAndZoom when just a single point of my Feature Layer is selected?
Just want to assign to a different button. I can't seem to find the exact syntax but I know I need to grab the geometry of the single selected point to then use in map.centerAndZoom.
Thnks so much. Any help is greatly appreciated.
David
Solved! Go to Solution.
David,
So it would look more like this then:
var gExt = graphicsUtils.graphicsExtent(myFeatureLayher.getSelectedFeatures()); if (gExt) { map.setExtent(gExt.expand(1.5), true); } else { var mp2 = myFeatureLayher.getSelectedFeatures()[0].geometry; map.centerAndZoom(mp2, 17); }
David,
Here is some code I use:
if (gExt) { map.setExtent(gExt.expand(1.5), true); } else { var mp2 = currentLayerAdded.graphics[0].geometry; map.centerAndZoom(mp2, 12); }
Finally figured out how to insert code nicely to my replies. Here is my quick and dirty zoom and center fix for a single selected feature:
on(dom.byId("zoomToSelectedPoint"), "click", function () { centermap(); setTimeout(function () { zoomin17(); }, 500); }); function centermap() { map.setExtent(graphicsUtils.graphicsExtent(activitiesDay1.getSelectedFeatures()), true); } function zoomin17() { map.setZoom(17); }
David,
So it would look more like this then:
var gExt = graphicsUtils.graphicsExtent(myFeatureLayher.getSelectedFeatures()); if (gExt) { map.setExtent(gExt.expand(1.5), true); } else { var mp2 = myFeatureLayher.getSelectedFeatures()[0].geometry; map.centerAndZoom(mp2, 17); }
Here is my code I came up with for a zoom button that works nicely. Works if multiple points or a single point is selected.
on(dom.byId("zoomToSelectedD1Activities"), "click", function () { var countp = activitiesDay1.getSelectedFeatures().length; if (countp > 1) { map.setExtent(graphicsUtils.graphicsExtent(activitiesDay1.getSelectedFeatures()), true); } else { var mp1A = activitiesDay1.getSelectedFeatures()[0].geometry; map.centerAndZoom(mp1A, 18); } });
Aha! That's it. Thanks so much, Robert. I was trying this last night but had forgotten the "()" between "getSelectedFeatures" and "[0]." Silly me. That's what happens when you stay up 'til 3:00 AM coding.