How do I increase the maximum number of Markers in Vaadin Maps?

99 views Asked by At

In Vaadin Maps (Vaadin 23) I'm finding that only a certain number of markers are displayed on the map. How do I for example show up to say 500 markers (as in 500 locations in the code below)?

locations.stream().forEach(location -> {
        Coordinate coordinate = Coordinate.fromLonLat(Double.parseDouble(location.getLon()), Double.parseDouble(location.getLat()));
        MarkerFeature customerMarker = new MarkerFeature(coordinate);
        map.getFeatureLayer().addFeature(customerMarker);
    });
1

There are 1 answers

1
Sascha Ißbrücker On

thanks for checking out the new Map component.

There shouldn't be any limit to the number of markers that you can add, neither from the Vaadin component, nor the underlying OpenLayers library.

Here is an example that displays 500 markers:

int numMarkers = 500;
double x = 0;
double y = 0;

for (int i = 0; i < numMarkers; i++) {
    // Display ten rows of fifty markers
    if (i % 50 == 0) {
        y += 1000;
        x = 0;
    } else {
        x += 1000;
    }

    Coordinate coordinate = new Coordinate(x, y);
    MarkerFeature marker = new MarkerFeature(coordinate);

    map.getFeatureLayer().addFeature(marker);
}

enter image description here

One thing you could check is whether all locations actually have unique coordinates, maybe there are some overlaps. For example the Coordinate.fromLonLat method you use trims values if longitude/latitude are out of bounds, which would put multiple markers in the same location in that case.

Apart from that you can always open an issue with a reproduction, and we'll take a look.