katit katit - 14 days ago 7
C# Question

ESRI Map control PanTo

I'm trying to make map center on certain Latitude/Longitude but Esri map control uses it's own X/Y coordinate system.

control.MapControl.PanTo(new MapPoint(control.MapCenter.Latitude, control.MapCenter.Longitude));


This code does not work. Is there any "conversion" routine to get MapPoint out of Lat/Lon or what should I do?

Answer

The method I use for conversion from lat/long(spatial reference 4326) to Esri coordinates (spatial reference 102100) is as follows:

// Create mappoint with lat/long coordinates
var mapPoint = new MapPoint(long, lat);

// Need to convert from Lat/Long to Esri
var webMercator = new WebMercator();
var converted = (MapPoint) webMercator.FromGeographic(mapPoint);

Before doing the conversion step, you can also check the spatial reference of mapPoint to see if it needs to be converted.