From 33d9bc0cff6ee4eb7938f8cc54f635c9ab3f1c93 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Wed, 18 Jul 2012 13:55:49 +0300 Subject: [PATCH] move L.Icon.Default to separate file, fix popup anchor --- build/deps.js | 2 +- debug/leaflet-include.js | 1 + src/layer/marker/Icon.Default.js | 43 +++++++++++++++++++++++++++++ src/layer/marker/Icon.js | 47 +------------------------------- src/layer/marker/Marker.Popup.js | 2 ++ 5 files changed, 48 insertions(+), 47 deletions(-) create mode 100644 src/layer/marker/Icon.Default.js diff --git a/build/deps.js b/build/deps.js index f89d2766..c7e0844b 100644 --- a/build/deps.js +++ b/build/deps.js @@ -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.' }, diff --git a/debug/leaflet-include.js b/debug/leaflet-include.js index d83fd923..bd8d38ef 100644 --- a/debug/leaflet-include.js +++ b/debug/leaflet-include.js @@ -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', diff --git a/src/layer/marker/Icon.Default.js b/src/layer/marker/Icon.Default.js new file mode 100644 index 00000000..b0726866 --- /dev/null +++ b/src/layer/marker/Icon.Default.js @@ -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'; + } + } +}()); diff --git a/src/layer/marker/Icon.js b/src/layer/marker/Icon.js index 1dca8f08..4453dcbd 100644 --- a/src/layer/marker/Icon.js +++ b/src/layer/marker/Icon.js @@ -32,7 +32,7 @@ L.Icon = L.Class.extend({ } return null; } - + var img = this._createImg(src); this._setIconStyles(img, name); @@ -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'; - } - } -}()); \ No newline at end of file diff --git a/src/layer/marker/Marker.Popup.js b/src/layer/marker/Marker.Popup.js index 85c236e4..8c8094ca 100644 --- a/src/layer/marker/Marker.Popup.js +++ b/src/layer/marker/Marker.Popup.js @@ -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); }