Select to view content in your preferred language

Change map scale based on the layer

986
3
Jump to solution
05-07-2013 09:51 PM
VinayBansal
Frequent Contributor
Hi All,
(Javascript API 3.4 and ArcGIS 10.1)

I have a scenario where I have Bing Base map and DynamicMapService Layer. There is a drop down to select the scale and user has the ability to enter scale. Now the problem is that when Bing map is On, and user selects the scale from dropdown say 20000, map zooms to scale (18666) which is obvious since Bing base map is there and it is following the scale range of Bing. Now when I remove the Bing base map from my map control , now I want to set the scale 20000, and since only dynamicmapservice is there on the map, then it should follow the scale ranges of dynamic map services, but it still zooms to 18666.
Means, when base map is on it should follows the basemap scale, and if basemap is removed, it should follows the scale range of dynamicmapservice layer., i.e. I need to switch dynamically between (Basemap + DynamicMapServicelayer) scenario  to DynamicMapService layer on map.

So please let me know if this is possible.

Thanks to all.
0 Kudos
1 Solution

Accepted Solutions
VinayBansal
Frequent Contributor
I got the solution for this.....
Clearing these variables when bsaemap is off,
map.__tileInfo = null; map.__LOD = null; veTileLayer = null; map._params.maxScale = 0; map._params.minScale = 0; map._params.minZoom = -1; map._params.maxZoom = -1; map._params.tileInfo = null; map._params.lods = null;


And setting back these variables when basemap is on
map.__LOD = tileLod; map.__tileInfo = veTileLayer.tileInfo; map._params.minScale = tileLods[0].scale; map._params.maxScale = tileLods[tileLods.length - 1].scale; map._params.minZoom = 0; map._params.maxZoom = tileLods.length - 1; map._params.tileInfo = tileLayer.tileInfo; map._params.lods = tileLods;

View solution in original post

0 Kudos
3 Replies
ShaunWeston
Frequent Contributor
Ok so a dynamic map service doesn't have any scales, only the tiled map service does. You would have to set the scales in the map.lods property. Have a look at this sample - http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/map_switch_layer_on_zoom.html

S
o you could set the scales there to use.
0 Kudos
VinayBansal
Frequent Contributor
Ok so a dynamic map service doesn't have any scales, only the tiled map service does. You would have to set the scales in the map.lods property. Have a look at this sample - http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/map_switch_layer_on_zoom.html

S
o you could set the scales there to use.


Hi Weston,

Thanks for your reply. But my requirement is to switch between (Tiled + Dynamic Layer) and Dynamic layer.
Here is my steps for application.
1. load application with no basemap.
2. Select scale from dropdown in map say 20000.
3. Map should zoom to 20000.
4. Then add basemap from basemap dropdown on map.
5. User selects scale 20000 from dropdown. Map should zoom to basemap nearest scale, which is 18055.
6. And then if user again removes the base map then step 2 and 3 should follow.

But if map is loaded without base map, and then I add the basemap. It is added on the map, but is not visible.
And if I add the basemap and dynamic layer, and then remove the base map, then map still zooms to the base map scale.

I tried with adding and removing the layers. But it didn't solved the purpose.

The solution for this that I currently found is that recreate the map object. Since after destroying the map object we can use its div to create the new map. But doing this we can loose any graphics or selection created on the  map. 

Thanks,
Vinay Bansal
0 Kudos
VinayBansal
Frequent Contributor
I got the solution for this.....
Clearing these variables when bsaemap is off,
map.__tileInfo = null; map.__LOD = null; veTileLayer = null; map._params.maxScale = 0; map._params.minScale = 0; map._params.minZoom = -1; map._params.maxZoom = -1; map._params.tileInfo = null; map._params.lods = null;


And setting back these variables when basemap is on
map.__LOD = tileLod; map.__tileInfo = veTileLayer.tileInfo; map._params.minScale = tileLods[0].scale; map._params.maxScale = tileLods[tileLods.length - 1].scale; map._params.minZoom = 0; map._params.maxZoom = tileLods.length - 1; map._params.tileInfo = tileLayer.tileInfo; map._params.lods = tileLods;
0 Kudos