Select to view content in your preferred language

Setting an initial extent based on a spatial ref potentially different from the map

3079
7
05-04-2011 11:13 PM
ChristopherMugdan
Regular Contributor
We have an application where we use template substitution to publish our version of the ArcGIS Flex Viewer based on extents in WGS84. We put them into config.xml "initial extent" setting before launching the Flex Viewer instance. How can I ensure that this extent is transformed into the map's spatial reference so that the map goes to the correct extent? Is this the right place for setting the extent?

I am using ArcGIS Flex Viewer 2.3.1

Cheers,
Chris Mugdan
Tags (2)
0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
Chris,

   What is you maps spatial reference? Why don't you just put the inital extent in the config.xml using the same coordinates as the basemap is in? It is not had to determine the extent of your data if you look at the map service's rest service directory page.
0 Kudos
ChristopherMugdan
Regular Contributor
Hi Robert,

The initial extent coordinates that we put into the config.xml are determined in our product in WGS84 and they do not know what coordinate system the underlying ArcGIS Server layers are. I was hoping at least to be able to find out what coordinate system the base layers were in so I could transform the extent coordinates to the base layer (map) coordinates from our WGS84 coordinates. I take it that setting the extent coordinate system to WGS84 with the coordinates from our application and then passing that to the map will not work? I tried that and it did not seem to work, but maybe I did not do it correctly. Here is what I did:

...

iextent = new Extent(Number(iextArray[0]), Number(iextArray[1]), Number(iextArray[2]), 
                            Number(iextArray[3]));

...

iextent.spatialReference = new SpatialReference(4326);

...

map.extent = iextent;

Cheers,
Chris
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Chris,

   Let me see if I can help you understand what happens in the Viewer/API. Basically you have basemap layers and operational layers the major difference between the two are that basemap layers are one or more layers that you want on all the time, operational layers are overlays to the basemap. Bare with me here as I think a need to go over this to give you the full picture. Basemaps are commonly tiled/cached layers and thus do not get re-projected by ArcGIS Server to match the spatial reference of the map. The map either gets it's spatial reference from the first layer that is loaded or the extent that is provided by the inital extent at initialization. It does not matter what spatial reference your data is in (WGS84 or what ever). What does matter is if you are going to be using esri's ArcGIS Online basemaps than they are in web mercator aux (102100 or 3857). Those layer are cached so they can not be re-projected. Your data with will usually be added as operational layers and can be added as dynamic which will allow ArcGIS Server to re-project them to match the cached basemaps. So what it comes down to is, that is the spatial reference of the map service(s) that you are going to be using as your basemap, that is the spatial reference that you need to use when defining the initial extent. All layers that are added to the map that are not cached will get re-projected by the server automatically. Hope this helps.
0 Kudos
ChristopherMugdan
Regular Contributor
Hi Robert,

Thanks for the detailed response. My problem is that, if someone who uses our modified Flex Viewer is using maps with a different coordinate system that we do not know about in advance then from what you are saying, inside the Flex Viewer we cannot automatically transform the extent coordinates that we compute in our application (which are WEGS84) and pass in via substitution to the map's coordinate system. If I could interrogate the map's coordinate system then I presume I could use the geometry operations to transform the points, but I cannot see how to get at the map's coordinate system. It seems to be null (uin the Flash debugger), even after the base layers are added. I guess it is too late then anyway.

If none of the above is possible then I suppose I am restricted to the Web projection by modifying the setting of iextent in the MapManager as follows:

      var wmextent:WebMercatorExtent = new WebMercatorExtent(Number(iextArray[0]), Number(iextArray[1]), Number(iextArray[2]), Number(iextArray[3]));
      iextent = wmextent.extent;

This is what I have been doing as a workaround initially, but what I need is a more robust solution.

Cheers,
Chris
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Chris,

  OK you really have me scratching my head here... Are you saying that you are customizing the Flex Viewer that will then be further configured by some one else and you will not have control over what map services they add?...
0 Kudos
ChristopherMugdan
Regular Contributor
Yes, that's it. We have our own widgets that invoke functions on our product that adds its layers over the top of the underlying ArcGIS Server base layers. The viewer combines the output of our product (as an overlay) with the customer's map layers in this way, and those layers may not be in Web Mercator projection. I have added a couple of classes in the main code base to talk to our WMS server and I have slightly modified the MapManager to handle our type of optional layer.

Maybe we are asking too much of the product in what we are trying to do?

Cheers,
Chris
0 Kudos
ChristopherMugdan
Regular Contributor
For everyone's interest, I solved this semi-automatically;) by adding the wkid of our map to the map attributes and then invoking the ArcGIS Server geometry service to project the extent corner points to the map's spatial reference. This seems to work satisfactorily.

Thanks to those who took the trouble to respond!

Cheers,
Chris Mugdan
0 Kudos