Select to view content in your preferred language

LayerInfo MinScale, MaxScale not being read correctly

775
4
05-11-2011 12:14 PM
CameronBlandy
Regular Contributor
hello,

I am using the following function to read all layers in a Dynamic map service and grab the MinScale and MaxScale properties. The function is very straightforward but doesn't give the desired result. All values for the MinScale and MaxScale are zero.

This is a read only property which is fine as I only want to get the values, not set them.

Does anybody know why this doesn't work.

        private void DynamicLayer_Initialized(object sender, EventArgs e)
        {
            ArcGISDynamicMapServiceLayer mapLayer = sender as ArcGISDynamicMapServiceLayer;
            foreach (LayerInfo li in mapLayer.Layers)
            {
                MessageBox.Show((li.Name + " :" + li.MinScale + " " + li.MaxScale).ToString());
             }
        }

Regards,
Cameron
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
MinScale and maxScale are only provided by the map service REST end point since ArcGIS server version 10 SP1 (i.e. 10.01).

You can check the version (and the min scale and max scale infos) with a request like : http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Average_Household_Size/MapSer...
0 Kudos
CameronBlandy
Regular Contributor
Thanks for the quick explanation. In the API documentation it doesn't say that those properties are only for 10.1 map services. It would have saved me a lot time if I had know this. 😞
0 Kudos
CameronBlandy
Regular Contributor
So I created a function to get the MinScale and MaxScale using json (as found in a previous post).

        private void DynamicLayer_Initialized(object sender, EventArgs e)
        {
            ArcGISDynamicMapServiceLayer mapLayer = sender as ArcGISDynamicMapServiceLayer;

            foreach (LayerInfo li in mapLayer.Layers)
            {
                if (li.SubLayerIds == null)
                {
                    Uri layerUri = new Uri(mapLayer.Url + "/" + li.ID + "?f=json", UriKind.RelativeOrAbsolute);
                    
                    WebClient webClient = new WebClient();
                    webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
                }  
            }
        }


        public void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {

            string[] properties = e.Result.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string minScale = properties.FirstOrDefault(p => p.Contains("minScale"));
            string maxScale = properties.FirstOrDefault(p => p.Contains("maxScale"));

            if (minScale != null)
                minScale = minScale.Substring(minScale.IndexOf(':') + 1, minScale.Length - (minScale.IndexOf(':') + 1));
            if (maxScale != null)
                maxScale = maxScale.Substring(maxScale.IndexOf(':') + 1, maxScale.Length - (maxScale.IndexOf(':') + 1));

        }


The problem I now have is that while it is doing all of the Async calls the Initialized property of the MapService is true which triggers a Map.Layers.LayersInitialized call. I do not want to trigger this event until all of the Aysnc calls have been completed. Is there a way to achieve this?

Regards,
Cameron
0 Kudos
DominiqueBroux
Esri Frequent Contributor
which triggers a Map.Layers.LayersInitialized call. I do not want to trigger this event until all of the Aysnc calls have been completed. Is there a way to achieve this?

You can't change the LayersInitialized event.
You have to manage it by yourself. The function that needs the min/max scales should be executed only when the layers are initialized AND when you got the min/max scales for ALL sublayers.

Sidenote : which ArcGIS Server version are you using? If it's the version 10, you can use the layers REST end point (example) which will give you the min/max scales of all the sublayers with only one request. Could be more performant and easier for managing the events.
0 Kudos