-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #158 for layer scripts, still have to do it for tiles scripts
- Loading branch information
Showing
8 changed files
with
1,582 additions
and
1,474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
L.Icon.Canvas = L.Icon.extend({ | ||
options: { | ||
iconSize: new L.Point(20, 20), // Have to be supplied | ||
/* | ||
iconAnchor: (Point) | ||
popupAnchor: (Point) | ||
*/ | ||
className: 'leaflet-canvas-icon' | ||
}, | ||
(function (factory, window) { | ||
// define an AMD module that relies on 'leaflet' | ||
if (typeof define === 'function' && define.amd) { | ||
define(['leaflet'], factory); | ||
// define a Common JS module that relies on 'leaflet' | ||
} else if (typeof exports === 'object') { | ||
module.exports = factory(require('leaflet')); | ||
} | ||
// attach your plugin to the global 'L' variable | ||
if (typeof window !== 'undefined' && window.L) { | ||
window.L.YourPlugin = factory(L); | ||
} | ||
}(function (L) { | ||
L.Icon.Canvas = L.Icon.extend({ | ||
options: { | ||
iconSize: new L.Point(20, 20), // Have to be supplied | ||
/* | ||
iconAnchor: (Point) | ||
popupAnchor: (Point) | ||
*/ | ||
className: 'leaflet-canvas-icon' | ||
}, | ||
|
||
createIcon: function () { | ||
var e = document.createElement('canvas'); | ||
this._setIconStyles(e, 'icon'); | ||
var s = this.options.iconSize; | ||
e.width = s.x; | ||
e.height = s.y; | ||
this.draw(e.getContext('2d'), s.x, s.y); | ||
return e; | ||
}, | ||
createIcon: function () { | ||
var e = document.createElement('canvas'); | ||
this._setIconStyles(e, 'icon'); | ||
var s = this.options.iconSize; | ||
e.width = s.x; | ||
e.height = s.y; | ||
this.draw(e.getContext('2d'), s.x, s.y); | ||
return e; | ||
}, | ||
|
||
createShadow: function () { | ||
return null; | ||
} | ||
}); | ||
createShadow: function () { | ||
return null; | ||
} | ||
}); | ||
}, window)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,66 @@ | ||
L.DeferredLayer = L.LayerGroup.extend({ | ||
options: { | ||
js: [], | ||
init: null | ||
}, | ||
(function (factory, window) { | ||
// define an AMD module that relies on 'leaflet' | ||
if (typeof define === 'function' && define.amd) { | ||
define(['leaflet'], factory); | ||
// define a Common JS module that relies on 'leaflet' | ||
} else if (typeof exports === 'object') { | ||
module.exports = factory(require('leaflet')); | ||
} | ||
// attach your plugin to the global 'L' variable | ||
if (typeof window !== 'undefined' && window.L) { | ||
window.L.YourPlugin = factory(L); | ||
} | ||
}(function (L) { | ||
L.DeferredLayer = L.LayerGroup.extend({ | ||
options: { | ||
js: [], | ||
init: null | ||
}, | ||
|
||
_script_cache: {}, | ||
_script_cache: {}, | ||
|
||
initialize: function (options) { | ||
L.Util.setOptions(this, options); | ||
L.LayerGroup.prototype.initialize.apply(this); | ||
this._loaded = false; | ||
}, | ||
initialize: function (options) { | ||
L.Util.setOptions(this, options); | ||
L.LayerGroup.prototype.initialize.apply(this); | ||
this._loaded = false; | ||
}, | ||
|
||
onAdd: function (map) { | ||
L.LayerGroup.prototype.onAdd.apply(this, [map]); | ||
if (this._loaded) return; | ||
var loaded = function () { | ||
this._loaded = true; | ||
var l = this.options.init(); | ||
if (l) | ||
this.addLayer(l); | ||
}; | ||
this._loadScripts(this.options.js.reverse(), L.Util.bind(loaded, this)); | ||
}, | ||
|
||
_loadScripts: function (scripts, cb, args) { | ||
if (!scripts || scripts.length === 0) | ||
return cb(args); | ||
var _this = this, s = scripts.pop(), c; | ||
c = this._script_cache[s]; | ||
if (c === undefined) { | ||
c = {url: s, wait: []}; | ||
var script = document.createElement('script'); | ||
script.src = s; | ||
script.type = 'text/javascript'; | ||
script.onload = function () { | ||
c.e.readyState = 'completed'; | ||
var i = 0; | ||
for (i = 0; i < c.wait.length; i++) | ||
c.wait[i](); | ||
onAdd: function (map) { | ||
L.LayerGroup.prototype.onAdd.apply(this, [map]); | ||
if (this._loaded) return; | ||
var loaded = function () { | ||
this._loaded = true; | ||
var l = this.options.init(); | ||
if (l) | ||
this.addLayer(l); | ||
}; | ||
c.e = script; | ||
document.getElementsByTagName('head')[0].appendChild(script); | ||
this._loadScripts(this.options.js.reverse(), L.Util.bind(loaded, this)); | ||
}, | ||
|
||
_loadScripts: function (scripts, cb, args) { | ||
if (!scripts || scripts.length === 0) | ||
return cb(args); | ||
var _this = this, s = scripts.pop(), c; | ||
c = this._script_cache[s]; | ||
if (c === undefined) { | ||
c = {url: s, wait: []}; | ||
var script = document.createElement('script'); | ||
script.src = s; | ||
script.type = 'text/javascript'; | ||
script.onload = function () { | ||
c.e.readyState = 'completed'; | ||
var i = 0; | ||
for (i = 0; i < c.wait.length; i++) | ||
c.wait[i](); | ||
}; | ||
c.e = script; | ||
document.getElementsByTagName('head')[0].appendChild(script); | ||
} | ||
function _cb () { _this._loadScripts(scripts, cb, args); } | ||
c.wait.push(_cb); | ||
if (c.e.readyState === 'completed') | ||
_cb(); | ||
this._script_cache[s] = c; | ||
} | ||
function _cb () { _this._loadScripts(scripts, cb, args); } | ||
c.wait.push(_cb); | ||
if (c.e.readyState === 'completed') | ||
_cb(); | ||
this._script_cache[s] = c; | ||
} | ||
}); | ||
}); | ||
}, window)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,63 @@ | ||
L.Icon.Text = L.Icon.extend({ | ||
initialize: function (text, options) { | ||
this._text = text; | ||
L.Icon.prototype.initialize.apply(this, [options]); | ||
}, | ||
|
||
createIcon: function () { | ||
var el = document.createElement('div'); | ||
el.appendChild(document.createTextNode(this._text)); | ||
this._setIconStyles(el, 'icon'); | ||
el.style.textShadow = '2px 2px 2px #fff'; | ||
return el; | ||
}, | ||
|
||
createShadow: function () { return null; } | ||
|
||
}); | ||
|
||
L.Marker.Text = L.Marker.extend({ | ||
initialize: function (latlng, text, options) { | ||
L.Marker.prototype.initialize.apply(this, [latlng, options]); | ||
this._fakeicon = new L.Icon.Text(text); | ||
}, | ||
|
||
_initIcon: function () { | ||
L.Marker.prototype._initIcon.apply(this); | ||
|
||
var i = this._icon, s = this._shadow, obj = this.options.icon; | ||
this._icon = this._shadow = null; | ||
|
||
this.options.icon = this._fakeicon; | ||
L.Marker.prototype._initIcon.apply(this); | ||
this.options.icon = obj; | ||
|
||
if (s) { | ||
s.parentNode.removeChild(s); | ||
this._icon.appendChild(s); | ||
(function (factory, window) { | ||
// define an AMD module that relies on 'leaflet' | ||
if (typeof define === 'function' && define.amd) { | ||
define(['leaflet'], factory); | ||
// define a Common JS module that relies on 'leaflet' | ||
} else if (typeof exports === 'object') { | ||
module.exports = factory(require('leaflet')); | ||
} | ||
// attach your plugin to the global 'L' variable | ||
if (typeof window !== 'undefined' && window.L) { | ||
window.L.YourPlugin = factory(L); | ||
} | ||
}(function (L) { | ||
L.Icon.Text = L.Icon.extend({ | ||
initialize: function (text, options) { | ||
this._text = text; | ||
L.Icon.prototype.initialize.apply(this, [options]); | ||
}, | ||
|
||
createIcon: function () { | ||
var el = document.createElement('div'); | ||
el.appendChild(document.createTextNode(this._text)); | ||
this._setIconStyles(el, 'icon'); | ||
el.style.textShadow = '2px 2px 2px #fff'; | ||
return el; | ||
}, | ||
|
||
createShadow: function () { return null; } | ||
|
||
}); | ||
|
||
L.Marker.Text = L.Marker.extend({ | ||
initialize: function (latlng, text, options) { | ||
L.Marker.prototype.initialize.apply(this, [latlng, options]); | ||
this._fakeicon = new L.Icon.Text(text); | ||
}, | ||
|
||
_initIcon: function () { | ||
L.Marker.prototype._initIcon.apply(this); | ||
|
||
var i = this._icon, s = this._shadow, obj = this.options.icon; | ||
this._icon = this._shadow = null; | ||
|
||
this.options.icon = this._fakeicon; | ||
L.Marker.prototype._initIcon.apply(this); | ||
this.options.icon = obj; | ||
|
||
if (s) { | ||
s.parentNode.removeChild(s); | ||
this._icon.appendChild(s); | ||
} | ||
|
||
i.parentNode.removeChild(i); | ||
this._icon.appendChild(i); | ||
|
||
var w = this._icon.clientWidth, h = this._icon.clientHeight; | ||
this._icon.style.marginLeft = -w / 2 + 'px'; | ||
var off = new L.Point(w/2, 0); | ||
L.DomUtil.setPosition(i, off); | ||
if (s) L.DomUtil.setPosition(s, off); | ||
} | ||
|
||
i.parentNode.removeChild(i); | ||
this._icon.appendChild(i); | ||
|
||
var w = this._icon.clientWidth, h = this._icon.clientHeight; | ||
this._icon.style.marginLeft = -w / 2 + 'px'; | ||
var off = new L.Point(w/2, 0); | ||
L.DomUtil.setPosition(i, off); | ||
if (s) L.DomUtil.setPosition(s, off); | ||
} | ||
}); | ||
}); | ||
}, window)); |
Oops, something went wrong.