move L.Icon.Default to separate file, fix popup anchor

This commit is contained in:
Vladimir Agafonkin 2012-07-18 13:55:49 +03:00
parent f446659325
commit 33d9bc0cff
5 changed files with 48 additions and 47 deletions

View File

@ -53,7 +53,7 @@ var deps = {
},
Marker: {
src: ['layer/marker/Icon.js', 'layer/marker/Marker.js'],
src: ['layer/marker/Icon.js', 'layer/marker/Icon.Default.js', 'layer/marker/Marker.js'],
desc: 'Markers to put on the map.'
},

View File

@ -62,6 +62,7 @@
'layer/Popup.js',
'layer/marker/Icon.js',
'layer/marker/Icon.Default.js',
'layer/marker/DivIcon.js',
'layer/marker/Marker.js',
'layer/marker/Marker.Popup.js',

View File

@ -0,0 +1,43 @@
L.Icon.Default = L.Icon.extend({
options: {
iconSize: new L.Point(25, 41),
iconAnchor: new L.Point(13, 41),
popupAnchor: new L.Point(1, -34),
shadowSize: new L.Point(41, 41)
},
_getIconUrl: function (name) {
var key = name + 'Url';
if (this.options[key]) {
return this.options[key];
}
var path = L.Icon.Default.imagePath;
if (!path) {
throw new Error("Couldn't autodetect L.Icon.Default.imagePath, set it manually.");
}
return path + '/marker-' + name + '.png';
}
});
L.Icon.Default.imagePath = (function () {
var scripts = document.getElementsByTagName('script'),
leafletRe = /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/;
var i, len, src, matches;
for (i = 0, len = scripts.length; i < len; i++) {
src = scripts[i].src;
matches = src.match(leafletRe);
if (matches) {
return src.split(leafletRe)[0] + '/images';
}
}
}());

View File

@ -87,48 +87,3 @@ L.Icon = L.Class.extend({
L.icon = function (options) {
return new L.Icon(options);
};
// TODO move to a separate file
L.Icon.Default = L.Icon.extend({
options: {
iconSize: new L.Point(25, 41),
iconAnchor: new L.Point(13, 41),
popupAnchor: new L.Point(0, -33),
shadowSize: new L.Point(41, 41)
},
_getIconUrl: function (name) {
var key = name + 'Url';
if (this.options[key]) {
return this.options[key];
}
var path = L.Icon.Default.imagePath;
if (!path) {
throw new Error("Couldn't autodetect L.Icon.Default.imagePath, set it manually.");
}
return path + '/marker-' + name + '.png';
}
});
L.Icon.Default.imagePath = (function () {
var scripts = document.getElementsByTagName('script'),
leafletRe = /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/;
var i, len, src, matches;
for (i = 0, len = scripts.length; i < len; i++) {
src = scripts[i].src;
matches = src.match(leafletRe);
if (matches) {
return src.split(leafletRe)[0] + '/images';
}
}
}());

View File

@ -22,6 +22,8 @@ L.Marker.include({
bindPopup: function (content, options) {
var anchor = L.point(this.options.icon.options.popupAnchor) || new L.Point(0, 0);
anchor = anchor.add(L.Popup.prototype.options.offset);
if (options && options.offset) {
anchor = anchor.add(options.offset);
}