-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeocens-map.js
More file actions
63 lines (48 loc) · 1.53 KB
/
geocens-map.js
File metadata and controls
63 lines (48 loc) · 1.53 KB
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
// geocens-map.js 1.2.5
// (c) 2013, James Badger, Geo Sensor Web Lab.
// All Rights Reserved.
// http://www.geocens.ca/
(function($, L) {
L.Geocens = L.FeatureGroup.extend({
options: {
popupContent: function(datasource, event, marker) {
return datasource.name();
}
},
initialize: function(data, options) {
var self = this;
L.Util.setOptions(this, options);
this._datasource = data;
var layers = this._layers = {};
var markerOptions = this.options.marker;
var popup = L.popup(this.options.popup);
// Create markers from datasource(s)
if (data instanceof Array) {
$.each(data, function(index) {
var marker = L.marker(this.location(), markerOptions);
marker.datasource = this;
marker.on("click", function(e) {
if (popup._map !== undefined && popup._map !== null) {
popup._map.closePopup(popup);
}
popup.setLatLng(e.latlng)
.setContent(self.options.popupContent(marker.datasource), e, marker);
marker.bindPopup(popup);
});
var id = L.stamp(marker);
layers[id] = marker;
});
} else {
var marker = L.marker(data.location(), markerOptions);
var id = L.stamp(marker);
layers[id] = marker;
}
},
datasource: function () {
return this._datasource;
}
});
L.geocens = function (data, options) {
return new L.Geocens(data, options);
};
})(jQuery, L);