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.

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Apr 15, 2019 at 17:18

1 Answer 1

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);
answered Apr 15, 2019 at 17:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.