Skip to content

Commit 33d9bc0

Browse files
committed
move L.Icon.Default to separate file, fix popup anchor
1 parent f446659 commit 33d9bc0

File tree

5 files changed

+48
-47
lines changed

5 files changed

+48
-47
lines changed

build/deps.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var deps = {
5353
},
5454

5555
Marker: {
56-
src: ['layer/marker/Icon.js', 'layer/marker/Marker.js'],
56+
src: ['layer/marker/Icon.js', 'layer/marker/Icon.Default.js', 'layer/marker/Marker.js'],
5757
desc: 'Markers to put on the map.'
5858
},
5959

debug/leaflet-include.js

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
'layer/Popup.js',
6363

6464
'layer/marker/Icon.js',
65+
'layer/marker/Icon.Default.js',
6566
'layer/marker/DivIcon.js',
6667
'layer/marker/Marker.js',
6768
'layer/marker/Marker.Popup.js',

src/layer/marker/Icon.Default.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
L.Icon.Default = L.Icon.extend({
3+
4+
options: {
5+
iconSize: new L.Point(25, 41),
6+
iconAnchor: new L.Point(13, 41),
7+
popupAnchor: new L.Point(1, -34),
8+
9+
shadowSize: new L.Point(41, 41)
10+
},
11+
12+
_getIconUrl: function (name) {
13+
var key = name + 'Url';
14+
15+
if (this.options[key]) {
16+
return this.options[key];
17+
}
18+
19+
var path = L.Icon.Default.imagePath;
20+
21+
if (!path) {
22+
throw new Error("Couldn't autodetect L.Icon.Default.imagePath, set it manually.");
23+
}
24+
25+
return path + '/marker-' + name + '.png';
26+
}
27+
});
28+
29+
L.Icon.Default.imagePath = (function () {
30+
var scripts = document.getElementsByTagName('script'),
31+
leafletRe = /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/;
32+
33+
var i, len, src, matches;
34+
35+
for (i = 0, len = scripts.length; i < len; i++) {
36+
src = scripts[i].src;
37+
matches = src.match(leafletRe);
38+
39+
if (matches) {
40+
return src.split(leafletRe)[0] + '/images';
41+
}
42+
}
43+
}());

src/layer/marker/Icon.js

+1-46
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ L.Icon = L.Class.extend({
3232
}
3333
return null;
3434
}
35-
35+
3636
var img = this._createImg(src);
3737
this._setIconStyles(img, name);
3838

@@ -87,48 +87,3 @@ L.Icon = L.Class.extend({
8787
L.icon = function (options) {
8888
return new L.Icon(options);
8989
};
90-
91-
92-
// TODO move to a separate file
93-
94-
L.Icon.Default = L.Icon.extend({
95-
options: {
96-
iconSize: new L.Point(25, 41),
97-
iconAnchor: new L.Point(13, 41),
98-
popupAnchor: new L.Point(0, -33),
99-
100-
shadowSize: new L.Point(41, 41)
101-
},
102-
103-
_getIconUrl: function (name) {
104-
var key = name + 'Url';
105-
106-
if (this.options[key]) {
107-
return this.options[key];
108-
}
109-
110-
var path = L.Icon.Default.imagePath;
111-
112-
if (!path) {
113-
throw new Error("Couldn't autodetect L.Icon.Default.imagePath, set it manually.");
114-
}
115-
116-
return path + '/marker-' + name + '.png';
117-
}
118-
});
119-
120-
L.Icon.Default.imagePath = (function () {
121-
var scripts = document.getElementsByTagName('script'),
122-
leafletRe = /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/;
123-
124-
var i, len, src, matches;
125-
126-
for (i = 0, len = scripts.length; i < len; i++) {
127-
src = scripts[i].src;
128-
matches = src.match(leafletRe);
129-
130-
if (matches) {
131-
return src.split(leafletRe)[0] + '/images';
132-
}
133-
}
134-
}());

src/layer/marker/Marker.Popup.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ L.Marker.include({
2222
bindPopup: function (content, options) {
2323
var anchor = L.point(this.options.icon.options.popupAnchor) || new L.Point(0, 0);
2424

25+
anchor = anchor.add(L.Popup.prototype.options.offset);
26+
2527
if (options && options.offset) {
2628
anchor = anchor.add(options.offset);
2729
}

0 commit comments

Comments
 (0)