Limiting LODs displayed on map

3679
3
02-12-2011 07:24 AM
JeffOzvold
New Contributor
I am using an ArcGISTiledMapServiceLayer. I know that I only want LODs 4 through 14. I don't want to hardcode the resolution/scale of these LODs.

However, I have a catch-22 problem. I can only limit the LODs displayed on construction of the map; it doesn't appear that I can set them later. But I can't figure out the LODs available without loading the layer, which means adding it to a previously-constructed map.

Does this mean I can only do this by constructing a map, adding the layer, determining the LODs, destroying the map, reconstructing it with the right LODs, and re-adding the layer? Surely it's not so inefficient.
0 Kudos
3 Replies
KeithSandell
New Contributor III
Is there a particular reason you do not want to hardcode the LOD's?

Then only reason I can see to create the LODs on the fly like this is if you intend to allow the user to modify them on the fly.

You are correct in that you "do" have to load the layer to select the LODs you want from the service in order to set them, and then of course the detroy and rebuild process.

Even if you do not hardcode the LODs upfront, you are still in essence hardcoding them, but through code.

It seems to me it would just be easier to hardcode the LODs. Just go to the service's directory and copy and paste into your code.

example:

//Custom levels of detail listing
         customLods = [   
       {"level" : 0, "resolution" : 9783.93962049996, "scale" : 36978595.474472},
       {"level" : 1, "resolution" : 4891.96981024998, "scale" : 18489297.737236},
       {"level" : 2, "resolution" : 2445.98490512499, "scale" : 9244648.868618},
       {"level" : 3, "resolution" : 1222.99245256249, "scale" : 4622324.434309},
       {"level" : 4, "resolution" : 611.49622628138, "scale" : 2311162.217155},
       {"level" : 5, "resolution" : 305.748113140558, "scale" : 1155581.108577},
       {"level" : 6, "resolution" : 152.874056570411, "scale" : 577790.554289},
       {"level" : 7, "resolution" : 76.4370282850732, "scale" : 288895.277144},
       {"level" : 8, "resolution" : 38.2185141425366, "scale" : 144447.638572},
       {"level" : 9, "resolution" : 19.1092570712683, "scale" : 72223.819286},
       {"level" : 10, "resolution" : 9.55462853563415, "scale" : 36111.909643},
       {"level" : 11, "resolution" : 4.77731426794937, "scale" : 18055.954822},
       {"level" : 12, "resolution" : 2.38865713397468, "scale" : 9027.977411},
       {"level" : 13, "resolution" : 1.19432856685505, "scale" : 4513.988705}  
      ];
  
   startExtent = new esri.geometry.Extent(-10947740.873, 2195752.071, -7202937.983, 4181891.814, new esri.SpatialReference({wkid:102100}));
   map = new esri.Map("mapDiv", {extent: startExtent, lods: customLods, logo: false});
0 Kudos
JeffOzvold
New Contributor
I don't want to hardcode because I (really) want to be able to say "Show me only LODs from 1:500 to 1:24,000". I don't control the tiled map service or its LODs, so they could potentially change without my knowledge. I'd rather code my application to respond appropriately to changes like that.

I used fiddler on a map load and I realized that I can just make a dojo xhrGet call to the MapServer URL:

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hurricanes/NOAA_Tracks_1851_2007/MapServe...

The JSON data for tiled map services has the LODs in it, so I bet I could use that.
0 Kudos
KeithSandell
New Contributor III
I hadn't heard of Fiddler before this, but I wish I had. It might have helped with one of my recent problems.

I understand now why you don't want to hardcode the LODs, but the notion of cached maps that just up in change is scary. However, the solution you mentioned appears to be sound, you'll just need to carve out the Levels...

Perhaps it is nieve, but I expect the LODs to remain the same and in reality need them to because the user experience I create in my apps is almost always tied closely to the specific scales to make sure that users have an adequate, but not excessive geographic extent visible that best satisfies the needs of the tools being used.

I guess that is a benefit of coding for internal business purposes only, much more control.
0 Kudos