HOW TO
Many user-interactive MapObjects Java applications need to get the location of mouse-click in the map. The location of a mouse-click can be returned from the MouseEvent object in terms of the Map object's pixel coordinate value. To perform various spatial functions, we need to convert this pixel coordinate into a map coordinate. This article outlines the steps to convert a pixel coordinate into a map coordinate.
Code:
int x1=e.getX();
int y1=e.getY();
Code:
double doubleX1=new Integer(x1).doubleValue();
double doubleY1=new Integer(y1).doubleValue();
Code:
com.esri.mo.cs.geom.Point pixelPoint= new com.esri.mo.cs.geom.Point(doubleX1,doubleY1);
Code:
com.esri.mo.cs.geom.Transform trans = map1.getPixelToWorldTransform();
com.esri.mo.cs.geom.Point mapPoint= trans.transform(pixelPoint, null);
Code:
double mapX=mapPoint.x;
double mapY=mapPoint.Y
Note:
Call getWorldToPixelTransform function on map object to transform Map Coordinate to Pixel Coordinate.
Article ID:000005390
Get help from ArcGIS experts
Download the Esri Support App