Map service ToMapPoints method

Converts points from screen coordinates to map coordinates.

ToMapPoints(MapDescription, ImageDisplay, int[ ] ScreenXValues, int[ ] ScreenYValues)

Parameter

Description

MapDescription

Used to define map extent in map units.

ImageDisplay

Used to define the map image extent in pixels.

ScreenXValues

An integer array containing the X values for coordinates to convert from screen (pixel) to map units.

ScreenYValues

An integer array containing the Y values for coordinates to convert from screen (pixel) to map units.

Return Value

A Multipoint object containing one or more coordinates in map units. Each coordinate is stored as a Point object. Note that both Multipoint and Point are abstract definitions, thus you will need to cast to MultipointN and PointN, respectively.

Remarks

This method is often used to convert user interaction on a map in a client application to map coordinates for use in other methods. For example, drawing graphics on the map and querying feature layers via user defined geometry.

To convert between map and pixel units, the origin for both must be determined. The origin for coordinates in map units is located in the lower left corner of the map image. The map origin is the minimum X and Y value of the current map extent. The origin for coordinates in pixel units is located in the upper left corner of the map image. The pixel origin is always 0,0.

Note that the map service will maintain aspect ratio, so the map extent provided as part of the MapDescription may be different than the map extent used to generate the map coordinates. To get the map extent used in the calculation, call ExportMapImage with the same MapDescription and ImageDisplay (as part of ImageDescription). A MapImage is returned where the Extent property references the map extent used by this method.

Examples

C#

MouseEventArgs mea = (MouseEventArgs)e;

int[] screenx = new int[1];

int[] screeny = new int[1];

 

screenx[0] = mea.X;

screeny[0] = mea.Y;

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

ImageDisplay imgdisp = new ImageDisplay();

imgdisp.ImageHeight = 500; //pixels

imgdisp.ImageWidth = 500; //pixels

imgdisp.ImageDPI = 96;

 

MultipointN multipoint = (MultipointN)mapservice.ToMapPoints(mapdesc, imgdisp, screenx, screeny);

VB.NET

Dim mea As MouseEventArgs = CType(e, MouseEventArgs)

 

Dim screenx(0) As Integer

Dim screeny(0) As Integer

screenx(0) = mea.X

screeny(0) = mea.Y

 

Dim mapservice As MapService_MapServer = New MapService_MapServer()

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer"

 

Dim mapinfo As MapServerInfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName())

Dim mapdesc As MapDescription = mapinfo.DefaultMapDescription

 

Dim imgdisp As ImageDisplay = New ImageDisplay()

imgdisp.ImageHeight = 500 'pixels

imgdisp.ImageWidth = 500 'pixels

imgdisp.ImageDPI = 96

 

Dim multipoint As MultipointN = CType(mapservice.ToMapPoints(mapdesc, imgdisp, screenx, screeny), MultipointN)

Java

String serviceURL = "http://localhost:6080/arcgis/services/MapService/MapServer";

MapServerBindingStub mapService = new MapServerBindingStub(serviceURL);

 

String mapName = mapService.getDefaultMapName();

MapServerInfo mapInfo = mapService.getServerInfo(mapName);

MapDescription mapDesc = mapInfo.getDefaultMapDescription();

 

ImageDisplay imgDisp = new ImageDisplay();

imgDisp.setImageHeight(500); //Height of the image in pixels

imgDisp.setImageWidth(500); //Width of the image in pixels

imgDisp.setImageDPI(96);

 

int[] screenX = new int[1];

int[] screenY = new int[1];

 

screenX[0] = 261;

screenY[0] = 292;

 

MultipointN multiPoint = (MultipointN)mapService.toMapPoints(mapDesc, imgDisp, screenX, screenY); 

 

Point[] points = multiPoint.getPointArray();

 

for (Point point : points) {

      PointN pointN = (PointN) point;

      System.out.println("X: " + pointN.getX());

      System.out.println("Y: " + pointN.getY());

}

2/28/2020