I have an x, y, spatialReference and zoom value that I need the map to go to. My map uses a custom basemap (same as the given spatial reference) and the view uses an extent value like so:
var view = new MapView({
container: "viewDiv",
map: map,
extent:new Extent ({"xmin": 554418, "ymin": 166279, "xmax": 584505, "ymax": 144457, "spatialReference":{"wkid": 27700}})
});
I can't get view.goTo to work no matter what I do.
Shakil,
Can you provide a sample?
var ex = new Extent({
center:{
x:564460.8649987298,
y:139625.260181187
}
});
view.goTo(ex);
Managed to get it working:
var geo = view.center;
geo.x = x;
geo.y = y;
view.goTo({
geometry:geo,
zoom:zoom
});
Worked for me as well. I have run into this a couple of times now. I think the documentation or api needs to be fixed. Documentation reads like the original should of worked and then {target: someGeometry} should work. Maybe I'm reading it wrong but I don't see any mention of using the geometry attribute for target. Am I reading this wrong Esri?
Travis,
No you are not reading anything wrong. When an Object is passed to the goTo method then the Object should have a property of target that points to a Number[]|Geometry|Geometry[]|Graphic|Graphic[]|Viewpoint. If you are not wanting to Also pass a zoom, scale, or center property with the target then you should just pass the Number[]|Geometry|Geometry[]|Graphic|Graphic[]|Viewpoint directly to the goTo method.
Is zoom required if you're requesting the map to be at full extent?
Gregory,
According to the API docs view.goTo(featureLayer.fullExtent); should work.
my working code:
if you want to zoom to feature layer extend, use below function
if you want to zoom to lat, long, use below function
works with v4.12 and v4.16