-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathleaflet.geojsoncss.js
51 lines (43 loc) · 1.09 KB
/
leaflet.geojsoncss.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
/**
* Leaflet.geojsonCSS
* @author Alexander Burtsev, http://burtsev.me, 2014
* @license MIT
*/
(function (window, document, undefined) {
if ( !window.L || !L.GeoJSON ) {
return;
}
L.GeoJSON.CSS = L.GeoJSON.extend({
initialize: function (geojson, options) {
var styledOptions = L.extend({}, options, {
onEachFeature: function(geojson, layer) {
if ( options && options.onEachFeature ) {
options.onEachFeature(geojson, layer);
}
var style = geojson.style,
template = geojson.popupTemplate;
if ( style ) {
if ( layer instanceof L.Marker ) {
if ( style.icon ) {
layer.setIcon(L.icon(style.icon));
}
} else {
layer.setStyle(style);
}
}
if ( template && geojson.properties ) {
layer.bindPopup(L.Util.template(template, geojson.properties));
}
}
});
L.setOptions(this, styledOptions);
this._layers = {};
if (geojson) {
this.addData(geojson);
}
}
});
L.geoJson.css = function (geojson, options) {
return new L.GeoJSON.CSS(geojson, options);
};
})(window, document);