import L, { Layer, Map, Marker, Polyline, Polygon } from 'leaflet';
import 'leaflet.fullscreen/Control.FullScreen.js';
import 'leaflet.fullscreen';
import 'leaflet.markercluster';
import { WPGPXMAPS } from '../Utils/Utils';
import 'leaflet.markercluster/dist/MarkerCluster.css';
import 'leaflet/dist/leaflet.css';
import 'leaflet.fullscreen/Control.FullScreen.css';
class ClusterPhotos {
map: Map | null = null;
shownLayer: Layer | null = null;
polygon: Polygon | null = null;
markers: any | null = null;
options: {
icon: {
iconSize: [40, 40],
},
};
constructor(map: Map) {
this.map = map;
//Custom radius and icon create function
this.markers = (L as any).markerClusterGroup({
maxClusterRadius: 120,
iconCreateFunction: function (cluster) {
return new L.DivIcon(
L.extend(
{
className: "leaflet-marker-photo",
html:
'
' +
cluster.getChildCount() +
"",
},
this.icon
)
);
},
//Disable all of the defaults:
spiderfyOnMaxZoom: false, showCoverageOnHover: false, zoomToBoundsOnClick: false
});
this.markers.on('click', function (evt: any) {
var photo = evt.layer.photo;
var template = '
{name}
';
evt.layer.bindPopup(L.Util.template(template, photo), {
minWidth: 'auto'
}).openPopup();
});
this.markers.on('clustermouseover', function (a) {
this.removePolygon();
a.layer.setOpacity(0.2);
this.shownLayer = a.layer;
this.polygon = L.polygon(a.layer.getConvexHull());
this.map.addLayer(this.polygon);
});
this.markers.on('clustermouseout', this.removePolygon);
this.map.on('zoomend', this.removePolygon);
this.map.addLayer(this.markers);
}
populate(images: any[]) {
for (const photo of images) {
var m = L.marker(L.latLng(photo.lat, photo.lng), {
icon: L.divIcon(
L.extend(
{
html:
'',
className: "leaflet-marker-photo",
},
photo,
{
iconSize: [40, 40],
}
)
),
title: photo.caption || "",
});
this.markers.addLayer(m);
}
return false;
}
private removePolygon() {
if (this.shownLayer) {
(this.shownLayer as any).setOpacity(1);
this.shownLayer = null;
}
if (this.polygon) {
this.map.removeLayer(this.polygon);
this.polygon = null;
}
};
}
export class LeafletMapEngine implements MapEngine