Is Reprojection on the fly supported on the Map control?

2809
4
01-18-2012 11:16 AM
StephenQuan
Occasional Contributor
Hi, I've just been trying to get geographic coordinates to display on the Hello World Map sample with projection on the fly. I prefer to keep the data in geographic coordinates and not code reprojection if the map control can be coerce to do it for me.

<CODE>
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  // Retrieve the map and initial extent from XML layout
  map = (MapView)findViewById(R.id.map);
  map.addLayer(new ArcGISDynamicMapServiceLayer("" +
    "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));

  // Add a BLUE DIAMOND point near San Bernadino using Web Mercator coordinates - this works!
  GraphicsLayer merclayer = new GraphicsLayer();
  merclayer.addGraphic(
   new Graphic(
    new Point(-13051775.04, 4066103.08),
    new SimpleMarkerSymbol(Color.BLUE, 15, STYLE.DIAMOND))
   );
  map.addLayer(merclayer);
 
  // Add a RED DIAMOND point in Australia using WGS84 geographic coordinates - fail (point is shown at equator)
  GraphicsLayer wgslayer = new GraphicsLayer(SpatialReference.create(4326), null);
  wgslayer.addGraphic(
    new Graphic(
     new Point(144, -37),
     new SimpleMarkerSymbol(Color.RED, 15, STYLE.DIAMOND))
    );
  map.addLayer(wgslayer);

  //Retrieve the non-configuration instance data that was previously returned.
  Object init = getLastNonConfigurationInstance();
   if (init != null) {
   map.restoreState((String) init);
  }
}
</CODE>
0 Kudos
4 Replies
IvanBespalov
Occasional Contributor III
Stephen,

Spatial reference and adding layer to map

Layers in the same map view might come with different spatial references by default. It is important to render all the layers with the same spatial reference. MapView takes the first added layer's spatial reference as its spatial reference. If you configure a map layout file, the topmost layer inside the map view would be the map's spatial reference.


You need to project your geometry to your map spatial reference.

P.S. I can not imagine, really. If you have a link to a map containing two or more layers, where each layer has its own coordinate system different from the other layers, then be kind enough to let me see it.
0 Kudos
StephenQuan
Occasional Contributor
Hi Ivan, you would like an example of a map containing two or more layers, where each layer has its own coordinate system different from the other layers? That's pretty easy.

1) ArcGIS Online layer in Web Mercator (GCS_WGS_1984_Major_Auxiliary_Sphere)
2) A map of Redlands (WGS_1984_UTM_Zone_11N)
3) A GPS tracklog (GCS_WGS_1984)

There's a business requirement to manage the datasets for #2 and #3 in their respective coordinate system, and there's a business requirement to show the datasets on the same map.

BTW, Ivan, I followed your references and manipulated my code as follows:

<CODE>
  // Add a RED DIAMOND point in Australia using WGS84 geographic coordinates - Works Now
  GraphicsLayer wgslayer = new GraphicsLayer();
  wgslayer.addGraphic(
    new Graphic(
     GeometryEngine.project(new Point(144, -37), SpatialReference.create(4326), SpatialReference.create(102100)),
     new SimpleMarkerSymbol(Color.RED, 15, STYLE.DIAMOND))
    );
  map.addLayer(wgslayer);
</CODE>
0 Kudos
IvanBespalov
Occasional Contributor III
May be due to the fact that my English is weak, you do not understand the irony in the question about layers.
Behold it, I hope you understand, that you can not correctly display the data from different coordinate systems simultaneously, without using the projection. Yes, I want you to show me an example that refutes it. Working example (live).

I am glad that my answer was helpful.
0 Kudos
StephenQuan
Occasional Contributor
See the Windows Phone API supports auto reprojecting of Graphic Layers see http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2011/11/18/Version-2.3-of-the-ArcGIS-API-for-... - I'm merely requesting for this to be in the Android API too.
0 Kudos