forked from turban/Leaflet.Photo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeaflet.Photo.js
83 lines (70 loc) · 1.89 KB
/
Leaflet.Photo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
L.Photo = L.FeatureGroup.extend({
options: {
icon: {
iconSize: [40, 40]
}
},
initialize: function (photos, options) {
L.setOptions(this, options);
L.FeatureGroup.prototype.initialize.call(this, photos);
},
addLayers: function (photos) {
if (photos) {
for (var i = 0, len = photos.length; i < len; i++) {
this.addLayer(photos[i]);
}
}
return this;
},
addLayer: function (photo) {
L.FeatureGroup.prototype.addLayer.call(this, this.createMarker(photo));
},
createMarker: function (photo) {
var marker = L.marker(photo, {
icon: L.divIcon(L.extend({
html: '<div style="background-image: url(' + photo.thumbnail + ');"></div>',
className: 'leaflet-marker-photo'
}, photo, this.options.icon)),
title: photo.caption || ''
});
marker.photo = photo;
return marker;
}
});
L.photo = function (photos, options) {
return new L.Photo(photos, options);
};
if (L.MarkerClusterGroup) {
L.Photo.Cluster = L.MarkerClusterGroup.extend({
options: {
featureGroup: L.photo,
maxClusterRadius: 100,
showCoverageOnHover: false,
iconCreateFunction: function(cluster) {
return new L.DivIcon(L.extend({
className: 'leaflet-marker-photo',
html: '<div style="background-image: url(' + cluster.getAllChildMarkers()[0].photo.thumbnail + ');"></div><b>' + cluster.getChildCount() + '</b>'
}, this.icon));
},
icon: {
iconSize: [40, 40]
}
},
initialize: function (options) {
options = L.Util.setOptions(this, options);
L.MarkerClusterGroup.prototype.initialize.call(this);
this._photos = options.featureGroup(null, options);
},
add: function (photos) {
this.addLayer(this._photos.addLayers(photos));
return this;
},
clear: function () {
this._photos.clearLayers();
this.clearLayers();
}
});
L.photo.cluster = function (options) {
return new L.Photo.Cluster(options);
};
}