|
| 1 | +package software.xdev.vaadin.maps.leaflet.flow.demo.plugins; |
| 2 | + |
| 3 | +import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
| 4 | +import com.vaadin.flow.router.Route; |
| 5 | + |
| 6 | +import software.xdev.vaadin.maps.leaflet.MapContainer; |
| 7 | +import software.xdev.vaadin.maps.leaflet.basictypes.LLatLng; |
| 8 | +import software.xdev.vaadin.maps.leaflet.layer.other.LMarkerClusterGroup; |
| 9 | +import software.xdev.vaadin.maps.leaflet.layer.raster.LTileLayer; |
| 10 | +import software.xdev.vaadin.maps.leaflet.layer.ui.LMarker; |
| 11 | +import software.xdev.vaadin.maps.leaflet.map.LMap; |
| 12 | +import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry; |
| 13 | +import software.xdev.vaadin.maps.leaflet.registry.LDefaultComponentManagementRegistry; |
| 14 | + |
| 15 | + |
| 16 | +@Route(LeafletMarkerClusterDemo.NAV) |
| 17 | +@SuppressWarnings("checkstyle:MagicNumber") |
| 18 | +public class LeafletMarkerClusterDemo extends VerticalLayout |
| 19 | +{ |
| 20 | + public static final String NAV = "/leaflet-markercluster"; |
| 21 | + |
| 22 | + public LeafletMarkerClusterDemo() |
| 23 | + { |
| 24 | + // Let the view use 100% of the site |
| 25 | + this.setSizeFull(); |
| 26 | + |
| 27 | + // Create the registry which is needed so that components can be reused and their methods invoked |
| 28 | + // Note: You normally don't need to invoke any methods of the registry and just hand it over to the components |
| 29 | + final LComponentManagementRegistry reg = new LDefaultComponentManagementRegistry(this); |
| 30 | + |
| 31 | + // Create and add the MapContainer (which contains the map) to the UI |
| 32 | + final MapContainer mapContainer = new MapContainer(reg); |
| 33 | + mapContainer.setSizeFull(); |
| 34 | + this.add(mapContainer); |
| 35 | + |
| 36 | + final LMap map = mapContainer.getlMap(); |
| 37 | + |
| 38 | + // Add a (default) TileLayer so that we can see something on the map |
| 39 | + map.addLayer(LTileLayer.createDefaultForOpenStreetMapTileServer(reg)); |
| 40 | + |
| 41 | + // Set what part of the world should be shown |
| 42 | + map.setView(new LLatLng(reg, 49.1, 12), 8); |
| 43 | + |
| 44 | + final LMarkerClusterGroup markerClusterGroup = new LMarkerClusterGroup(reg); |
| 45 | + markerClusterGroup.addLayer(new LMarker(reg, new LLatLng(reg, 49.6756, 12.1610)) |
| 46 | + .bindPopup("XDEV Software")); |
| 47 | + markerClusterGroup.addLayer(new LMarker(reg, new LLatLng(reg, 49.673800, 12.160113)) |
| 48 | + .bindPopup("Schnitzel")); |
| 49 | + |
| 50 | + markerClusterGroup.addLayer(new LMarker(reg, new LLatLng(reg, 49.67, 12.16)) |
| 51 | + .bindPopup("Weiden i.d.OPf.")); |
| 52 | + markerClusterGroup.addLayer(new LMarker(reg, new LLatLng(reg, 49.44, 11.86)) |
| 53 | + .bindPopup("Amberg")); |
| 54 | + markerClusterGroup.addLayer(new LMarker(reg, new LLatLng(reg, 49.33, 12.11)) |
| 55 | + .bindPopup("Schwandorf")); |
| 56 | + markerClusterGroup.addLayer(new LMarker(reg, new LLatLng(reg, 49.45, 11.08)) |
| 57 | + .bindPopup("Nürnberg")); |
| 58 | + markerClusterGroup.addLayer(new LMarker(reg, new LLatLng(reg, 49.02, 12.1)) |
| 59 | + .bindPopup("Regensburg")); |
| 60 | + markerClusterGroup.addLayer(new LMarker(reg, new LLatLng(reg, 48.14, 11.57)) |
| 61 | + .bindPopup("München")); |
| 62 | + |
| 63 | + map.addLayer(markerClusterGroup); |
| 64 | + } |
| 65 | +} |
0 commit comments