I was wondering if it is possible to retrieve the extent of a layer from an ArcGIS map server? I have already tried using the following code:
var url = 'https://fragis.fra.dot.gov/fragis/rest/services/Blocks/MapServer';
var newLayer = new ArcGISDynamicMapServer(url);
newLayer.setVisibleLayers([3]);
newLayer.id = 'a name';
map.setExtent(newLayer.initialExtent);
map.addLayer(newLayer);
But it only returns the absolute max and min values for the extent.
{xmin: -180, ymin: -90, xmax: 180, ymax: 90, spatialReference: {wkid: 4326}}
I've tried using FullExtent and that returns null. I've tried using a FeatureLayer instead of a ArcGISDynamicMapServer with no luck.
1 Answer 1
Managed to figure it out. I made the mistake of thinking that when you create the dynamic layer, it would automatically load all of the information in right then and there. But after modifying the code to run when the layer has fully loaded, it worked.
var url = 'https://fragis.fra.dot.gov/fragis/rest/services/Blocks/MapServer';
var newLayer = new ArcGISDynamicMapServer(url);
newLayer.setVisibleLayers([3]);
newLayer.id = 'a name';
newLayer.on('load', function () {
map.setExtent(newLayer.initialExtent);
});
map.addLayer(newLayer);