0

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.

3

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.