Reputation: 1117
I am using ArcGIS
maps by Esri
for Android SDK
link to ArcGIS to display some points on the map. So far I have removed points with same coordinates via removeDupes
and just drawn the coordinates that are not duplicated. Then between the points are lines that are connecting them.
OnClick I can see the information about 1 point.
Now instead of removing duplicates I need to display the same points in a cluster. Basically a bigger circle that would display how many points are on the same coordinates and then when the cluster is clicked on it would show all of the points that are actually in there.
Here is the code on how to add the points to the map:
private void plotRoute(List<DeliveryPoint> deliveryPoints) {
Logger.d("Plotting " + deliveryPoints.size() + " coordinates.");
pointsOfInterest = removeDupes(deliveryPoints);
SpatialReference SPATIAL_REFERENCE = SpatialReferences.getWgs84();
// create a red (0xFFFF0000) circle simple marker symbol
SimpleMarkerSymbol redCircleSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0xFFFF0000, 10);
SimpleMarkerSymbol bigOrange = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0xFFFF8000, 20);
SimpleMarkerSymbol bigBlue = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0xFF0000FF, 20);
ArrayList<Graphic> poiMarkers = new ArrayList<>();
ArrayList<Graphic> labels = new ArrayList<>();
// create a new point collection for polyline
PointCollection points = new PointCollection(SPATIAL_REFERENCE);
graphicDeliveryPointCoordinatesHashMap.clear();
int ordinal = 0;
int length = pointsOfInterest.size();
for (DeliveryPoint poi: deliveryPoints) {
Point point = new Point(poi.longitude, poi.latitude, SPATIAL_REFERENCE);
points.add(point);
TextSymbol label = new TextSymbol(12, "" + ++ordinal, 0xFFFF0000, TextSymbol.HorizontalAlignment.CENTER, TextSymbol.VerticalAlignment.MIDDLE);
Graphic labelGraphic= new Graphic(point, label);
label.setOffsetY(10);
label.setOffsetX(10);
Graphic graphic = new Graphic(point, redCircleSymbol);
if(ordinal == 1) {
graphic = new Graphic(point, bigOrange);
} else if (ordinal == length) {
graphic = new Graphic(point, bigBlue);
}
poiMarkers.add(graphic);
labels.add(labelGraphic);
graphicDeliveryPointCoordinatesHashMap.put(graphic, poi);
}
textOverlay.getGraphics().addAll(labels);
poiOverlay.getGraphics().addAll(poiMarkers);
// create a polyline from the point collection
Polyline polyline = new Polyline(points);
//define a line symbol
SimpleLineSymbol lineSymbol =
new SimpleLineSymbol(
SimpleLineSymbol.Style.SOLID,
Color.argb(255, 255, 128, 0), 1.0f);
// create the graphic with polyline and symbol
Graphic lines = new Graphic(polyline, lineSymbol);
// add graphic to the graphics overlay
poiOverlay.getGraphics().add(lines);
mapView.setOnTouchListener(new PoiTouchListener(this, mapView, poiOverlay));
}
I have found documentation on how to do that in JavaScript
Link to JS clustering but that did not help me as there seems to be no official support for Android
Clustering.
Is there a way for a workaround to approach this problem?
Upvotes: 1
Views: 550
Reputation: 96
Even after the 100.x releases, the SDKs don't have the same capabilities. There is no out of the box Cluster Layer within mobile SDKs.
However, there are a few custom implementations that do what you're looking for. This one seems to be matching your use case: https://github.com/AshinJiang/ArcGIS-Android-Cluster
Upvotes: 1