-
Notifications
You must be signed in to change notification settings - Fork 0
/
Leaflet-custom-markers.js
118 lines (95 loc) · 2.52 KB
/
Leaflet-custom-markers.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
Leaflet Custom Marker, a JavaScript library for using svg path has marker in Leaflet maps
(c) 2015 D.Daron
Version 0.0.1
*/
(function() {
L.CustomMarker = L.Path.extend({
options: {
fill: true,
anchor: [-10,-36],
points:[
[10 ,0],
["C",4 ,0],
[0 ,4],
[0 ,10],
["C",0 ,16],
[10 ,36],
[10 ,36],
["C",10 ,36],
[20 ,16],
[20 ,10],
["C",20 ,4],
[16,0],
[10 ,0],
["L",10 ,0],
["Z M",6,6],
["",6,16],
["",14,16],
["",14,6]
],
radius: 10
},
initialize: function (latlng, options) {
this._latlng = L.latLng(latlng);
this.setOptions(options);
},
setLatLng: function (latlng) {
this._latlng = L.latLng(latlng);
this.redraw();
return this.fire('move', {latlng: this._latlng});
},
getLatLng: function () {
return this._latlng;
},
setOptions: function (options) {
L.setOptions(this, options);
this._updateOptions();
return this.redraw();
},
_updateOptions: function () {
this._points = this.options.points;
this._anchor = this.options.anchor;
},
setStyle : function (options) {
L.Path.prototype.setStyle.call(this, options);
return this;
},
_project: function () {
this._point = this._map.latLngToLayerPoint(this._latlng);
this._updateBounds();
},
_updateBounds: function () {
var w = this._clickTolerance(),
p = [w,w];
this._pxBounds = new L.Bounds(this._point.subtract(p), this._point.add(p));
},
_update: function () {
if (this._map) {
this._updatePath();
}
},
_updatePath: function () {
var p = this._point,
sX = this._anchor[0],
sY = this._anchor[1];
// For each point: ["type of curve","x","y"]
var relCoords = this._points;
var d = 'M ';
for (var i = 0, len = relCoords.length; i < len; i++) {
if (relCoords[i].length == 2)
d += (p.x+sX+relCoords[i][0]) + ',' + (p.y+sY+relCoords[i][1]) + ' '
else if (relCoords[i].length == 3)
d += relCoords[i][0] + (p.x+sX+relCoords[i][1]) + ',' + (p.y+sY+relCoords[i][2]) + ' '
}
d += 'Z';
this._renderer._setPath(this, d);
},
_empty: function () {
return this._radius && !this._renderer._bounds.intersects(this._pxBounds);
}
});
L.customMarker = function (latlng, options) {
return new L.CustomMarker(latlng, options);
};
}());