require(["esri/map", "dojo/domReady!", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/SpatialReference",], function(Map) { var layer1 = new esri.layers.ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/carte1/MapServer"); map = new Map("maptest1"); map.addLayers([layer1]); map.on("layers-add-result", function(){ var extent = layer1.fullExtent; map.setExtent(extent); alert(extent.xmax); }); });
Try this instead require(["esri/map", "dojo/domReady!", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/SpatialReference",], function(Map) { var layer1 = new esri.layers.ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/carte1/MapServer"); map = new Map("maptest1"); map.addLayers([layer1]); map.on("layers-add-result", function(){ var extent = layer1.fullExtent; map.setExtent(extent); alert(extent.xmax); }); });
map.addLayer(dynamicMapServiceLayer); console.log(dynamicMapServiceLayer.fullExtent); //this will be null dynamicMapServiceLayer.on("load", function(evt) { console.log(evt.layer.fullExtent); //this will be populated });
welcome to the forums burton!if you have a reference to an extent object, you could find its center using the method extent.getCenter() afterward, you could pass the point which is returned to map.centerAt()
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.