Yes I meant the current map extent, like in this screenshot. The Icons are in different GraphicsLayer.
The method I tried is to iterate over all graphics layer, iterate over all graphics, check if the geometry is in the current extent and then call the JMap.toScreenPoint() method. Here is a snippet of the code:
List<Point> coords = new ArrayList<Point>();
LayerList list = map.getLayers();
for (int i = list.size() - 1; i >= 0; i--) {
if (list.get(i) instanceof GraphicsLayer) {
GraphicsLayer layer = (GraphicsLayer) list.get(i);
if (layer.getGraphicIDs() != null && layer.getGraphicIDs().length > 0) {
int[] ids = layer.getGraphicIDs();
for (int j = 0; j < ids.length; j++) {
Graphic graphic = layer.getGraphic(ids);
com.esri.core.geometry.Geometry geometry = graphic.getGeometry();
if (com.esri.core.geometry.Geometry.isPoint(geometry.getType().a())) {
Point p = (Point) geometry;
Envelope extent = map.getExtent();
if (extent.contains(p)) {
Point screenPoint = map.toScreenPoint(p);
coords.add(screenPoint);
}
}
}
}
}
This works, but i hope there is an easier and perhaps faster way. Particularly for other geometry objects like polylines and polygons.
I need to call this method after every change of the map extent or change in the data.