Select to view content in your preferred language

Changing Map Service Dynamically

899
4
08-31-2010 05:10 AM
FlexDeveloper
Deactivated User
Dear All,
What I have is a combo-box that I have populated with names of different maps that I have and added the tiled map service-urls to the data field. At the combo-box close event, I am trying to load the selected map. In essence, this is to change the map service dynamically at run time because I think that loading all my maps initially and hiding/showing them would be wasteful.

The problem is that, while my map loads the first map that I select, it fails to load the subsequent maps. As far as I understand it, it is just the problem of changing the extent and LODs of the map. But, despite all my efforts, I am not being able to obtain the extent of the map whose url I obtain from the combo box. I have seen trails of people looking for a solution to similar problems on the net, but could not find any crisp solutions. I can't believe something this basic can be impossible for an API this robust.

Can anyone please bail me out. A little pointer in the right direction too would be highly appreciated.

Best regards,
Gaurav
Tags (2)
0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Gaurav,

   Why not predefine the extent of the map service in the combobox data?

//Populate your combobox with an array like this.
private var ABC:ArrayCollection = new ArrayCollection([{label:"Subway", msurl:"the map service url",extent:"-78.75651009240596,39.6278291354036,-78.74282009759395,39.634491742596595"},
    {label:"CiCi's Pizza", msurl:"the map service url", extent:"-78.84485849540602,39.6282293839035,-78.831168500594,39.634891991096495"},
    {label:"Auntie Anne's", msurl:"the map service url", extent:"-78.84208596390596,39.623430996403556,-78.82839596909395,39.63009360359655"},
    {label:"Orange Julius", msurl:"the map service url", extent:"-78.841786340406,39.6244109709035,-78.82809634559399,39.63107357809649"}]);

//Then you get access to the extent using some code like this:

var ext:String = yourComboboxId.dataProvider[yourComboboxId.selectedIndex].extent;

0 Kudos
FlexDeveloper
Deactivated User
Dear Robert,
Thanks a heap. But this is leading me into further troubles. Actually I have one service published for each state of the country. And since states vary greatly in size, I had to set different LODs for each map. And if I go by your example, I shall have to load the LODs from the combo-box data too.

Right now, the way I am doing it is to initialize each map service with a unique id in the beginning, but this has started to play havoc on our server.

As I mentioned before, one thing that I noticed is that if I load just one blank map in the beginning and provide the service URL later on through the combo-box, the map automatically extracts its full extents and shows it properly. My question is, why can we not do it for the URLs that we pass later on? Is there not a way to reset or re-initialize the map before the next URL is passed. I tried the myMap.initialize() function, but it does not seem to have the desired effect. Or maybe destroy the myMap altogether and recreate one at each combo-box change event.

Another way of asking the above question is that if I can get hold of a map-service URL, say, as a user input, how do I go about displaying it in my application without having to hard-code each of the parameters like fullExtent and LODs.

I shall be very thankful for any help.

Best regards,
Gaurav
0 Kudos
FlexDeveloper
Deactivated User
Thanks to Robert again, I atleast found the answer to the question:

Dear Robert,
Another way of asking the above question is that if I can get hold of a map-service URL, say, as a user input, how do I go about displaying it in my application without having to hard-code each of the parameters like fullExtent and LODs.


Robert has very beautifully illustrated the solution in a separate thread at:

http://forums.esri.com/thread.asp?c=158&f=2421&t=293581

However, trying this code too, my problem persists. The map loads the first URL that is provided but refuses to load the other URLs because they come from different extents (though they have the same projection). I tried to set the map extent using the myMap.extent= typeXML.initialExtent; and the LODs using map.lods = typeXML.tileInfo.lods; but still am not able to get the new map to display. I wonder where I am getting wrong. I even tried to destroy the map and re-create a new one, but got mixed up in that.

Robert, please be my savior.:)

Best regards,
Gaurav
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Gaurav,

   Try this map.removeAllLayers and then map.lods=[]; and then add the new layers.
0 Kudos