diff --git a/layer/Icon.Canvas.js b/layer/Icon.Canvas.js
index 0029700..faa861c 100644
--- a/layer/Icon.Canvas.js
+++ b/layer/Icon.Canvas.js
@@ -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));
\ No newline at end of file
diff --git a/layer/Layer.Deferred.js b/layer/Layer.Deferred.js
index f29f864..5f5a009 100644
--- a/layer/Layer.Deferred.js
+++ b/layer/Layer.Deferred.js
@@ -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));
\ No newline at end of file
diff --git a/layer/Marker.Rotate.js b/layer/Marker.Rotate.js
index 740fc52..affc6d8 100644
--- a/layer/Marker.Rotate.js
+++ b/layer/Marker.Rotate.js
@@ -1,10 +1,21 @@
-/*
- * Based on comments by @runanet and @coomsie
- * https://github.com/CloudMade/Leaflet/issues/386
- *
- * Wrapping function is needed to preserve L.Marker.update function
- */
-(function () {
+(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) {
+ /*
+ * Based on comments by @runanet and @coomsie
+ * https://github.com/CloudMade/Leaflet/issues/386
+ *
+ */
var _old__setPos = L.Marker.prototype._setPos;
L.Marker.include({
_updateImg: function (i, a, s) {
@@ -59,4 +70,4 @@
}
}
});
-}());
+}, window));
\ No newline at end of file
diff --git a/layer/Marker.Text.js b/layer/Marker.Text.js
index 112be26..f8e4197 100644
--- a/layer/Marker.Text.js
+++ b/layer/Marker.Text.js
@@ -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));
\ No newline at end of file
diff --git a/layer/vector/GPX.js b/layer/vector/GPX.js
index f582d5a..16a0e7f 100644
--- a/layer/vector/GPX.js
+++ b/layer/vector/GPX.js
@@ -1,152 +1,166 @@
-L.GPX = L.FeatureGroup.extend({
- initialize: function (gpx, options) {
- L.Util.setOptions(this, options);
- this._gpx = gpx;
- this._layers = {};
+(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.GPX = L.FeatureGroup.extend({
+ initialize: function (gpx, options) {
+ L.Util.setOptions(this, options);
+ this._gpx = gpx;
+ this._layers = {};
+
+ if (gpx) {
+ this.addGPX(gpx, options, this.options.async);
+ }
+ },
- if (gpx) {
- this.addGPX(gpx, options, this.options.async);
- }
- },
-
- loadXML: function (url, cb, options, async) {
- if (async === undefined) async = this.options.async;
- if (options === undefined) options = this.options;
+ loadXML: function (url, cb, options, async) {
+ if (async === undefined) async = this.options.async;
+ if (options === undefined) options = this.options;
- var req = new window.XMLHttpRequest();
- req.open('GET', url, async);
- try {
- req.overrideMimeType('text/xml'); // unsupported by IE
- } catch (e) {}
- req.onreadystatechange = function () {
- if (req.readyState !== 4) return;
- if (req.status === 200) cb(req.responseXML, options);
- };
- req.send(null);
- },
+ var req = new window.XMLHttpRequest();
+ req.open('GET', url, async);
+ try {
+ req.overrideMimeType('text/xml'); // unsupported by IE
+ } catch (e) {}
+ req.onreadystatechange = function () {
+ if (req.readyState !== 4) return;
+ if (req.status === 200) cb(req.responseXML, options);
+ };
+ req.send(null);
+ },
- _humanLen: function (l) {
- if (l < 2000)
- return l.toFixed(0) + ' m';
- else
- return (l/1000).toFixed(1) + ' km';
- },
-
- _polylineLen: function (line)//line is a L.Polyline()
- {
- var ll = line._latlngs;
- var d = 0, p = null;
- for (var i = 0; i < ll.length; i++)
+ _humanLen: function (l) {
+ if (l < 2000)
+ return l.toFixed(0) + ' m';
+ else
+ return (l/1000).toFixed(1) + ' km';
+ },
+
+ _polylineLen: function (line)//line is a L.Polyline()
{
- if (i && p)
- d += p.distanceTo(ll[i]);
- p = ll[i];
- }
- return d;
- },
+ var ll = line._latlngs;
+ var d = 0, p = null;
+ for (var i = 0; i < ll.length; i++)
+ {
+ if (i && p)
+ d += p.distanceTo(ll[i]);
+ p = ll[i];
+ }
+ return d;
+ },
- addGPX: function (url, options, async) {
- var _this = this;
- var cb = function (gpx, options) { _this._addGPX(gpx, options); };
- this.loadXML(url, cb, options, async);
- },
+ addGPX: function (url, options, async) {
+ var _this = this;
+ var cb = function (gpx, options) { _this._addGPX(gpx, options); };
+ this.loadXML(url, cb, options, async);
+ },
- _addGPX: function (gpx, options) {
- var layers = this.parseGPX(gpx, options);
- if (!layers) return;
- this.addLayer(layers);
- this.fire('loaded');
- },
+ _addGPX: function (gpx, options) {
+ var layers = this.parseGPX(gpx, options);
+ if (!layers) return;
+ this.addLayer(layers);
+ this.fire('loaded');
+ },
- parseGPX: function (xml, options) {
- var j, i, el, layers = [];
- var named = false, tags = [['rte','rtept'], ['trkseg','trkpt']];
+ parseGPX: function (xml, options) {
+ var j, i, el, layers = [];
+ var named = false, tags = [['rte','rtept'], ['trkseg','trkpt']];
- for (j = 0; j < tags.length; j++) {
- el = xml.getElementsByTagName(tags[j][0]);
- for (i = 0; i < el.length; i++) {
- var l = this.parse_trkseg(el[i], xml, options, tags[j][1]);
- for (var k = 0; k < l.length; k++) {
- if (this.parse_name(el[i], l[k])) named = true;
- layers.push(l[k]);
+ for (j = 0; j < tags.length; j++) {
+ el = xml.getElementsByTagName(tags[j][0]);
+ for (i = 0; i < el.length; i++) {
+ var l = this.parse_trkseg(el[i], xml, options, tags[j][1]);
+ for (var k = 0; k < l.length; k++) {
+ if (this.parse_name(el[i], l[k])) named = true;
+ layers.push(l[k]);
+ }
}
}
- }
- el = xml.getElementsByTagName('wpt');
- if (options.display_wpt !== false) {
- for (i = 0; i < el.length; i++) {
- var marker = this.parse_wpt(el[i], xml, options);
- if (!marker) continue;
- if (this.parse_name(el[i], marker)) named = true;
- layers.push(marker);
+ el = xml.getElementsByTagName('wpt');
+ if (options.display_wpt !== false) {
+ for (i = 0; i < el.length; i++) {
+ var marker = this.parse_wpt(el[i], xml, options);
+ if (!marker) continue;
+ if (this.parse_name(el[i], marker)) named = true;
+ layers.push(marker);
+ }
}
- }
- if (!layers.length) return;
- var layer = layers[0];
- if (layers.length > 1)
- layer = new L.FeatureGroup(layers);
- if (!named) this.parse_name(xml, layer);
- return layer;
- },
+ if (!layers.length) return;
+ var layer = layers[0];
+ if (layers.length > 1)
+ layer = new L.FeatureGroup(layers);
+ if (!named) this.parse_name(xml, layer);
+ return layer;
+ },
- parse_name: function (xml, layer) {
- var i, el, txt='', name, descr='', link, len=0;
- el = xml.getElementsByTagName('name');
- if (el.length)
- name = el[0].childNodes[0].nodeValue;
- el = xml.getElementsByTagName('desc');
- for (i = 0; i < el.length; i++) {
- for (var j = 0; j < el[i].childNodes.length; j++)
- descr = descr + el[i].childNodes[j].nodeValue;
- }
- el = xml.getElementsByTagName('link');
- if (el.length)
- link = el[0].getAttribute('href');
+ parse_name: function (xml, layer) {
+ var i, el, txt='', name, descr='', link, len=0;
+ el = xml.getElementsByTagName('name');
+ if (el.length)
+ name = el[0].childNodes[0].nodeValue;
+ el = xml.getElementsByTagName('desc');
+ for (i = 0; i < el.length; i++) {
+ for (var j = 0; j < el[i].childNodes.length; j++)
+ descr = descr + el[i].childNodes[j].nodeValue;
+ }
+ el = xml.getElementsByTagName('link');
+ if (el.length)
+ link = el[0].getAttribute('href');
- if (layer instanceof L.Path)
- len = this._polylineLen(layer);
+ if (layer instanceof L.Path)
+ len = this._polylineLen(layer);
- if (name) txt += '
' + name + '
' + descr;
- if (len) txt += '' + this._humanLen(len) + '
';
- if (link) txt += '[...]
';
+ if (name) txt += '' + name + '
' + descr;
+ if (len) txt += '' + this._humanLen(len) + '
';
+ if (link) txt += '[...]
';
- if (layer && layer._popup === undefined) layer.bindPopup(txt);
- return txt;
- },
+ if (layer && layer._popup === undefined) layer.bindPopup(txt);
+ return txt;
+ },
- parse_trkseg: function (line, xml, options, tag) {
- var el = line.getElementsByTagName(tag);
- if (!el.length) return [];
- var coords = [];
- for (var i = 0; i < el.length; i++) {
- var ll = new L.LatLng(el[i].getAttribute('lat'),
- el[i].getAttribute('lon'));
- ll.meta = {};
- for (var j in el[i].childNodes) {
- var e = el[i].childNodes[j];
- if (!e.tagName) continue;
- ll.meta[e.tagName] = e.textContent;
+ parse_trkseg: function (line, xml, options, tag) {
+ var el = line.getElementsByTagName(tag);
+ if (!el.length) return [];
+ var coords = [];
+ for (var i = 0; i < el.length; i++) {
+ var ll = new L.LatLng(el[i].getAttribute('lat'),
+ el[i].getAttribute('lon'));
+ ll.meta = {};
+ for (var j in el[i].childNodes) {
+ var e = el[i].childNodes[j];
+ if (!e.tagName) continue;
+ ll.meta[e.tagName] = e.textContent;
+ }
+ coords.push(ll);
}
- coords.push(ll);
- }
- var l = [new L.Polyline(coords, options)];
- this.fire('addline', {line:l});
- return l;
- },
+ var l = [new L.Polyline(coords, options)];
+ this.fire('addline', {line:l});
+ return l;
+ },
- parse_wpt: function (e, xml, options) {
- var m = new L.Marker(new L.LatLng(e.getAttribute('lat'),
- e.getAttribute('lon')), options);
- var attributes = {};
- for (var i = 0; i < e.childNodes.length; i++) {
- var ch = e.childNodes[i];
- if (ch.nodeName !== '#text') {
- attributes[ch.nodeName] = ch.textContent;
+ parse_wpt: function (e, xml, options) {
+ var m = new L.Marker(new L.LatLng(e.getAttribute('lat'),
+ e.getAttribute('lon')), options);
+ var attributes = {};
+ for (var i = 0; i < e.childNodes.length; i++) {
+ var ch = e.childNodes[i];
+ if (ch.nodeName !== '#text') {
+ attributes[ch.nodeName] = ch.textContent;
+ }
}
+ this.fire('addpoint', {point:m, attributes:attributes});
+ return m;
}
- this.fire('addpoint', {point:m, attributes:attributes});
- return m;
- }
-});
+ });
+}, window));
\ No newline at end of file
diff --git a/layer/vector/KML.js b/layer/vector/KML.js
index 096c1c3..b3568cb 100644
--- a/layer/vector/KML.js
+++ b/layer/vector/KML.js
@@ -1,486 +1,499 @@
-L.KML = L.FeatureGroup.extend({
- options: {
- async: true
- },
-
- initialize: function (kml, options) {
- L.Util.setOptions(this, options);
- this._kml = kml;
- this._layers = {};
-
- if (kml) {
- this.addKML(kml, options, this.options.async);
- }
- },
-
- loadXML: function (url, cb, options, async) {
- if (async === undefined) async = this.options.async;
- if (options === undefined) options = this.options;
-
- var req = new window.XMLHttpRequest();
-
- // Check for IE8 and IE9 Fix Cors for those browsers
- if (req.withCredentials === undefined && typeof window.XDomainRequest !== 'undefined') {
- var xdr = new window.XDomainRequest();
- xdr.open('GET', url, async);
- xdr.onprogress = function () { };
- xdr.ontimeout = function () { };
- xdr.onerror = function () { };
- xdr.onload = function () {
- if (xdr.responseText) {
- var xml = new window.ActiveXObject('Microsoft.XMLDOM');
- xml.loadXML(xdr.responseText);
- cb(xml, options);
- }
- };
- setTimeout(function () { xdr.send(); }, 0);
- } else {
- req.open('GET', url, async);
- req.setRequestHeader('Accept', 'application/vnd.google-earth.kml+xml');
- try {
- req.overrideMimeType('text/xml'); // unsupported by IE
- } catch (e) { }
- req.onreadystatechange = function () {
- if (req.readyState !== 4) return;
- if (req.status === 200) cb(req.responseXML, options);
- };
- req.send(null);
- }
- },
-
- addKML: function (url, options, async) {
- var _this = this;
- var cb = function (kml) { _this._addKML(kml); };
- this.loadXML(url, cb, options, async);
- },
-
- _addKML: function (xml) {
- var layers = L.KML.parseKML(xml);
- if (!layers || !layers.length) return;
- for (var i = 0; i < layers.length; i++) {
- this.fire('addlayer', {
- layer: layers[i]
- });
- this.addLayer(layers[i]);
- }
- this.latLngs = L.KML.getLatLngs(xml);
- this.fire('loaded');
- },
-
- latLngs: []
-});
-
-L.Util.extend(L.KML, {
-
- parseKML: function (xml) {
- var style = this.parseStyles(xml);
- this.parseStyleMap(xml, style);
- var el = xml.getElementsByTagName('Folder');
- var layers = [], l;
- for (var i = 0; i < el.length; i++) {
- if (!this._check_folder(el[i])) { continue; }
- l = this.parseFolder(el[i], style);
- if (l) { layers.push(l); }
- }
- el = xml.getElementsByTagName('Placemark');
- for (var j = 0; j < el.length; j++) {
- if (!this._check_folder(el[j])) { continue; }
- l = this.parsePlacemark(el[j], xml, style);
- if (l) { layers.push(l); }
- }
- el = xml.getElementsByTagName('GroundOverlay');
- for (var k = 0; k < el.length; k++) {
- l = this.parseGroundOverlay(el[k]);
- if (l) { layers.push(l); }
- }
- return layers;
- },
-
- // Return false if e's first parent Folder is not [folder]
- // - returns true if no parent Folders
- _check_folder: function (e, folder) {
- e = e.parentNode;
- while (e && e.tagName !== 'Folder')
- {
- e = e.parentNode;
- }
- return !e || e === folder;
- },
-
- parseStyles: function (xml) {
- var styles = {};
- var sl = xml.getElementsByTagName('Style');
- for (var i=0, len=sl.length; i 1) {
+ layer = new L.FeatureGroup(layers);
}
- }
-
- var layers = [];
- var parse = ['LineString', 'Polygon', 'Point', 'Track', 'gx:Track'];
- for (j in parse) {
- var tag = parse[j];
- el = place.getElementsByTagName(tag);
+ var name, descr = '';
+ el = place.getElementsByTagName('name');
+ if (el.length && el[0].childNodes.length) {
+ name = el[0].childNodes[0].nodeValue;
+ }
+ el = place.getElementsByTagName('description');
for (i = 0; i < el.length; i++) {
- var l = this['parse' + tag.replace(/gx:/, '')](el[i], xml, opts);
- if (l) { layers.push(l); }
+ for (j = 0; j < el[i].childNodes.length; j++) {
+ descr = descr + el[i].childNodes[j].nodeValue;
+ }
}
- }
-
- if (!layers.length) {
- return;
- }
- var layer = layers[0];
- if (layers.length > 1) {
- layer = new L.FeatureGroup(layers);
- }
- var name, descr = '';
- el = place.getElementsByTagName('name');
- if (el.length && el[0].childNodes.length) {
- name = el[0].childNodes[0].nodeValue;
- }
- el = place.getElementsByTagName('description');
- for (i = 0; i < el.length; i++) {
- for (j = 0; j < el[i].childNodes.length; j++) {
- descr = descr + el[i].childNodes[j].nodeValue;
+ if (name) {
+ layer.on('add', function () {
+ layer.bindPopup('' + name + '
' + descr);
+ });
}
- }
-
- if (name) {
- layer.on('add', function () {
- layer.bindPopup('' + name + '
' + descr);
- });
- }
- return layer;
- },
-
- parseCoords: function (xml) {
- var el = xml.getElementsByTagName('coordinates');
- return this._read_coords(el[0]);
- },
-
- parseLineString: function (line, xml, options) {
- var coords = this.parseCoords(line);
- if (!coords.length) { return; }
- return new L.Polyline(coords, options);
- },
-
- parseTrack: function (line, xml, options) {
- var el = xml.getElementsByTagName('gx:coord');
- if (el.length === 0) { el = xml.getElementsByTagName('coord'); }
- var coords = [];
- for (var j = 0; j < el.length; j++) {
- coords = coords.concat(this._read_gxcoords(el[j]));
- }
- if (!coords.length) { return; }
- return new L.Polyline(coords, options);
- },
+ return layer;
+ },
+
+ parseCoords: function (xml) {
+ var el = xml.getElementsByTagName('coordinates');
+ return this._read_coords(el[0]);
+ },
+
+ parseLineString: function (line, xml, options) {
+ var coords = this.parseCoords(line);
+ if (!coords.length) { return; }
+ return new L.Polyline(coords, options);
+ },
+
+ parseTrack: function (line, xml, options) {
+ var el = xml.getElementsByTagName('gx:coord');
+ if (el.length === 0) { el = xml.getElementsByTagName('coord'); }
+ var coords = [];
+ for (var j = 0; j < el.length; j++) {
+ coords = coords.concat(this._read_gxcoords(el[j]));
+ }
+ if (!coords.length) { return; }
+ return new L.Polyline(coords, options);
+ },
+
+ parsePoint: function (line, xml, options) {
+ var el = line.getElementsByTagName('coordinates');
+ if (!el.length) {
+ return;
+ }
+ var ll = el[0].childNodes[0].nodeValue.split(',');
+ return new L.KMLMarker(new L.LatLng(ll[1], ll[0]), options);
+ },
- parsePoint: function (line, xml, options) {
- var el = line.getElementsByTagName('coordinates');
- if (!el.length) {
- return;
- }
- var ll = el[0].childNodes[0].nodeValue.split(',');
- return new L.KMLMarker(new L.LatLng(ll[1], ll[0]), options);
- },
-
- parsePolygon: function (line, xml, options) {
- var el, polys = [], inner = [], i, coords;
- el = line.getElementsByTagName('outerBoundaryIs');
- for (i = 0; i < el.length; i++) {
- coords = this.parseCoords(el[i]);
- if (coords) {
- polys.push(coords);
+ parsePolygon: function (line, xml, options) {
+ var el, polys = [], inner = [], i, coords;
+ el = line.getElementsByTagName('outerBoundaryIs');
+ for (i = 0; i < el.length; i++) {
+ coords = this.parseCoords(el[i]);
+ if (coords) {
+ polys.push(coords);
+ }
}
- }
- el = line.getElementsByTagName('innerBoundaryIs');
- for (i = 0; i < el.length; i++) {
- coords = this.parseCoords(el[i]);
- if (coords) {
- inner.push(coords);
+ el = line.getElementsByTagName('innerBoundaryIs');
+ for (i = 0; i < el.length; i++) {
+ coords = this.parseCoords(el[i]);
+ if (coords) {
+ inner.push(coords);
+ }
}
- }
- if (!polys.length) {
- return;
- }
- if (options.fillColor) {
- options.fill = true;
- }
- if (polys.length === 1) {
- return new L.Polygon(polys.concat(inner), options);
- }
- return new L.MultiPolygon(polys, options);
- },
-
- getLatLngs: function (xml) {
- var el = xml.getElementsByTagName('coordinates');
- var coords = [];
- for (var j = 0; j < el.length; j++) {
- // text might span many childNodes
- coords = coords.concat(this._read_coords(el[j]));
- }
- return coords;
- },
+ if (!polys.length) {
+ return;
+ }
+ if (options.fillColor) {
+ options.fill = true;
+ }
+ if (polys.length === 1) {
+ return new L.Polygon(polys.concat(inner), options);
+ }
+ return new L.MultiPolygon(polys, options);
+ },
+
+ getLatLngs: function (xml) {
+ var el = xml.getElementsByTagName('coordinates');
+ var coords = [];
+ for (var j = 0; j < el.length; j++) {
+ // text might span many childNodes
+ coords = coords.concat(this._read_coords(el[j]));
+ }
+ return coords;
+ },
- _read_coords: function (el) {
- var text = '', coords = [], i;
- for (i = 0; i < el.childNodes.length; i++) {
- text = text + el.childNodes[i].nodeValue;
- }
- text = text.split(/[\s\n]+/);
- for (i = 0; i < text.length; i++) {
- var ll = text[i].split(',');
- if (ll.length < 2) {
- continue;
+ _read_coords: function (el) {
+ var text = '', coords = [], i;
+ for (i = 0; i < el.childNodes.length; i++) {
+ text = text + el.childNodes[i].nodeValue;
}
- coords.push(new L.LatLng(ll[1], ll[0]));
- }
- return coords;
- },
-
- _read_gxcoords: function (el) {
- var text = '', coords = [];
- text = el.firstChild.nodeValue.split(' ');
- coords.push(new L.LatLng(text[1], text[0]));
- return coords;
- },
-
- parseGroundOverlay: function (xml) {
- var latlonbox = xml.getElementsByTagName('LatLonBox')[0];
- var bounds = new L.LatLngBounds(
- [
- latlonbox.getElementsByTagName('south')[0].childNodes[0].nodeValue,
- latlonbox.getElementsByTagName('west')[0].childNodes[0].nodeValue
- ],
- [
- latlonbox.getElementsByTagName('north')[0].childNodes[0].nodeValue,
- latlonbox.getElementsByTagName('east')[0].childNodes[0].nodeValue
- ]
- );
- var attributes = {Icon: true, href: true, color: true};
- function _parse (xml) {
- var options = {}, ioptions = {};
- for (var i = 0; i < xml.childNodes.length; i++) {
- var e = xml.childNodes[i];
- var key = e.tagName;
- if (!attributes[key]) { continue; }
- var value = e.childNodes[0].nodeValue;
- if (key === 'Icon') {
- ioptions = _parse(e);
- if (ioptions.href) { options.href = ioptions.href; }
- } else if (key === 'href') {
- options.href = value;
- } else if (key === 'color') {
- options.opacity = parseInt(value.substring(0, 2), 16) / 255.0;
- options.color = '#' + value.substring(6, 8) + value.substring(4, 6) + value.substring(2, 4);
+ text = text.split(/[\s\n]+/);
+ for (i = 0; i < text.length; i++) {
+ var ll = text[i].split(',');
+ if (ll.length < 2) {
+ continue;
}
+ coords.push(new L.LatLng(ll[1], ll[0]));
}
- return options;
- }
- var options = {};
- options = _parse(xml);
- if (latlonbox.getElementsByTagName('rotation')[0] !== undefined) {
- var rotation = latlonbox.getElementsByTagName('rotation')[0].childNodes[0].nodeValue;
- options.rotation = parseFloat(rotation);
+ return coords;
+ },
+
+ _read_gxcoords: function (el) {
+ var text = '', coords = [];
+ text = el.firstChild.nodeValue.split(' ');
+ coords.push(new L.LatLng(text[1], text[0]));
+ return coords;
+ },
+
+ parseGroundOverlay: function (xml) {
+ var latlonbox = xml.getElementsByTagName('LatLonBox')[0];
+ var bounds = new L.LatLngBounds(
+ [
+ latlonbox.getElementsByTagName('south')[0].childNodes[0].nodeValue,
+ latlonbox.getElementsByTagName('west')[0].childNodes[0].nodeValue
+ ],
+ [
+ latlonbox.getElementsByTagName('north')[0].childNodes[0].nodeValue,
+ latlonbox.getElementsByTagName('east')[0].childNodes[0].nodeValue
+ ]
+ );
+ var attributes = {Icon: true, href: true, color: true};
+ function _parse (xml) {
+ var options = {}, ioptions = {};
+ for (var i = 0; i < xml.childNodes.length; i++) {
+ var e = xml.childNodes[i];
+ var key = e.tagName;
+ if (!attributes[key]) { continue; }
+ var value = e.childNodes[0].nodeValue;
+ if (key === 'Icon') {
+ ioptions = _parse(e);
+ if (ioptions.href) { options.href = ioptions.href; }
+ } else if (key === 'href') {
+ options.href = value;
+ } else if (key === 'color') {
+ options.opacity = parseInt(value.substring(0, 2), 16) / 255.0;
+ options.color = '#' + value.substring(6, 8) + value.substring(4, 6) + value.substring(2, 4);
+ }
+ }
+ return options;
+ }
+ var options = {};
+ options = _parse(xml);
+ if (latlonbox.getElementsByTagName('rotation')[0] !== undefined) {
+ var rotation = latlonbox.getElementsByTagName('rotation')[0].childNodes[0].nodeValue;
+ options.rotation = parseFloat(rotation);
+ }
+ return new L.RotatedImageOverlay(options.href, bounds, {opacity: options.opacity, angle: options.rotation});
+ }
+
+ });
+
+ L.KMLIcon = L.Icon.extend({
+ _setIconStyles: function (img, name) {
+ L.Icon.prototype._setIconStyles.apply(this, [img, name]);
+ var options = this.options;
+ this.options.popupAnchor = [0,(-0.83*img.height)];
+ if (options.anchorType.x === 'fraction')
+ img.style.marginLeft = (-options.anchorRef.x * img.width) + 'px';
+ if (options.anchorType.y === 'fraction')
+ img.style.marginTop = ((-(1 - options.anchorRef.y) * img.height) + 1) + 'px';
+ if (options.anchorType.x === 'pixels')
+ img.style.marginLeft = (-options.anchorRef.x) + 'px';
+ if (options.anchorType.y === 'pixels')
+ img.style.marginTop = (options.anchorRef.y - img.height + 1) + 'px';
+ }
+ });
+
+
+ L.KMLMarker = L.Marker.extend({
+ options: {
+ icon: new L.KMLIcon.Default()
+ }
+ });
+
+ // Inspired by https://github.com/bbecquet/Leaflet.PolylineDecorator/tree/master/src
+ L.RotatedImageOverlay = L.ImageOverlay.extend({
+ options: {
+ angle: 0
+ },
+ _reset: function () {
+ L.ImageOverlay.prototype._reset.call(this);
+ this._rotate();
+ },
+ _animateZoom: function (e) {
+ L.ImageOverlay.prototype._animateZoom.call(this, e);
+ this._rotate();
+ },
+ _rotate: function () {
+ if (L.DomUtil.TRANSFORM) {
+ // use the CSS transform rule if available
+ this._image.style[L.DomUtil.TRANSFORM] += ' rotate(' + this.options.angle + 'deg)';
+ } else if (L.Browser.ie) {
+ // fallback for IE6, IE7, IE8
+ var rad = this.options.angle * (Math.PI / 180),
+ costheta = Math.cos(rad),
+ sintheta = Math.sin(rad);
+ this._image.style.filter += ' progid:DXImageTransform.Microsoft.Matrix(sizingMethod=\'auto expand\', M11=' +
+ costheta + ', M12=' + (-sintheta) + ', M21=' + sintheta + ', M22=' + costheta + ')';
+ }
+ },
+ getBounds: function () {
+ return this._bounds;
}
- return new L.RotatedImageOverlay(options.href, bounds, {opacity: options.opacity, angle: options.rotation});
- }
-
-});
-
-L.KMLIcon = L.Icon.extend({
- _setIconStyles: function (img, name) {
- L.Icon.prototype._setIconStyles.apply(this, [img, name]);
- var options = this.options;
- this.options.popupAnchor = [0,(-0.83*img.height)];
- if (options.anchorType.x === 'fraction')
- img.style.marginLeft = (-options.anchorRef.x * img.width) + 'px';
- if (options.anchorType.y === 'fraction')
- img.style.marginTop = ((-(1 - options.anchorRef.y) * img.height) + 1) + 'px';
- if (options.anchorType.x === 'pixels')
- img.style.marginLeft = (-options.anchorRef.x) + 'px';
- if (options.anchorType.y === 'pixels')
- img.style.marginTop = (options.anchorRef.y - img.height + 1) + 'px';
- }
-});
-
-
-L.KMLMarker = L.Marker.extend({
- options: {
- icon: new L.KMLIcon.Default()
- }
-});
-
-// Inspired by https://github.com/bbecquet/Leaflet.PolylineDecorator/tree/master/src
-L.RotatedImageOverlay = L.ImageOverlay.extend({
- options: {
- angle: 0
- },
- _reset: function () {
- L.ImageOverlay.prototype._reset.call(this);
- this._rotate();
- },
- _animateZoom: function (e) {
- L.ImageOverlay.prototype._animateZoom.call(this, e);
- this._rotate();
- },
- _rotate: function () {
- if (L.DomUtil.TRANSFORM) {
- // use the CSS transform rule if available
- this._image.style[L.DomUtil.TRANSFORM] += ' rotate(' + this.options.angle + 'deg)';
- } else if (L.Browser.ie) {
- // fallback for IE6, IE7, IE8
- var rad = this.options.angle * (Math.PI / 180),
- costheta = Math.cos(rad),
- sintheta = Math.sin(rad);
- this._image.style.filter += ' progid:DXImageTransform.Microsoft.Matrix(sizingMethod=\'auto expand\', M11=' +
- costheta + ', M12=' + (-sintheta) + ', M21=' + sintheta + ', M22=' + costheta + ')';
- }
- },
- getBounds: function () {
- return this._bounds;
- }
-});
-
+ });
+}, window));
\ No newline at end of file
diff --git a/layer/vector/OSM.js b/layer/vector/OSM.js
index 5ee9fc7..c99fdb2 100644
--- a/layer/vector/OSM.js
+++ b/layer/vector/OSM.js
@@ -1,167 +1,181 @@
-L.OSM = L.FeatureGroup.extend({
- options: {
- async: true,
- forceAll: false
- },
-
- initialize: function (url, options) {
- L.Util.setOptions(this, options);
- this._url = url;
- this._layers = {};
+(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.OSM = L.FeatureGroup.extend({
+ options: {
+ async: true,
+ forceAll: false
+ },
+
+ initialize: function (url, options) {
+ L.Util.setOptions(this, options);
+ this._url = url;
+ this._layers = {};
+
+ if (url) {
+ this.addXML(url, options, this.options.async);
+ }
+ },
- if (url) {
- this.addXML(url, options, this.options.async);
+ loadXML: function (url, cb, options, async) {
+ if (async === undefined) async = this.options.async;
+ if (options === undefined) options = this.options;
+
+ var req = new window.XMLHttpRequest();
+ req.open('GET', url, async);
+ req.overrideMimeType('text/xml');
+ req.onreadystatechange = function () {
+ if (req.readyState !== 4) return;
+ if (req.status === 200) cb(req.responseXML, options);
+ };
+ req.send(null);
+ },
+
+ addXML: function (url, options, async) {
+ var _this = this;
+ var cb = function (xml, options) { _this._addXML(xml, options); };
+ this.loadXML(url, cb, options, async);
+ },
+
+ _addXML: function (xml, options) {
+ var layers = this.parseOSM(xml, options);
+ if (!layers) return;
+ this.addLayer(layers);
+ this.fire('loaded');
+ },
+
+ parseOSM: function (xml, options) {
+ var i, el, ll, layers = [];
+ var nodes = {};
+ var ways = {};
+ var named = false;
+
+ el = xml.getElementsByTagName('node');
+ for (i = 0; i < el.length; i++) {
+ var l = this.parse_node(el[i], xml, options);
+ if (l === undefined) continue;
+ nodes[l.osmid] = l;
+ if (!this.options.forceAll && !l.tags.length) continue;
+ var m = this.named_node(l, options);
+ if (!ll) ll = m.getLatLng();
+ if (this.parse_name(m, l, 'Node')) named = true;
+ layers.push(m);
+ }
+
+ el = xml.getElementsByTagName('way');
+ for (i = 0; i < el.length; i++) {
+ if (i > 10) break;
+ var way = this.parse_way(el[i], nodes, options);
+ if (!way) continue;
+ if (!ll) ll = way.getLatLngs()[0];
+ if (this.parse_name(way, way, 'Way')) named = true;
+ layers.push(way);
+ ways[way.osmid] = way;
+ }
+
+ el = xml.getElementsByTagName('relation');
+ for (i = 0; i < el.length; i++) {
+ if (i > 10) break;
+ var relation = this.parse_relation(el[i], ways, options);
+ if (!relation) continue;
+ if (!ll) ll = relation.getLatLngs()[0];
+ if (this.parse_name(relation, relation, 'Relation')) named = true;
+ layers.push(relation);
+ }
+
+ if (!layers.length) return;
+ var layer = layers[0];
+ if (layers.length > 1)
+ layer = new L.FeatureGroup(layers);
+ if (!named) this.parse_name(xml, layer);
+ layer.focusPoint = ll;
+ return layer;
+ },
+
+ parse_name: function (layer, obj, obj_name) {
+ if (!this.options.forceAll)
+ if (!obj.tags || !obj.tags.length) return;
+ var i, txt = '';
+ for (i = 0; i < obj.tags.length; i++) {
+ var t = obj.tags[i];
+ txt += '' + t.k + ' | = | ' + t.v + ' |
';
+ }
+ txt += '
';
+ txt = '' + obj_name + ' ' + obj.osmid + '
' + txt;
+ if (layer) layer.bindPopup(txt);
+ return txt;
+ },
+
+ parse_tags: function (line) {
+ var tags = [], el = line.getElementsByTagName('tag');
+ for (var i = 0; i < el.length; i++)
+ tags.push({k: el[i].getAttribute('k'), v: el[i].getAttribute('v')});
+ return tags;
+ },
+
+ parse_node: function (e) {
+ var n = {osmid: e.getAttribute('id'),
+ lat:e.getAttribute('lat'),
+ lon:e.getAttribute('lon')
+ };
+ n.ll = new L.LatLng(n.lat, n.lon);
+ n.tags = this.parse_tags(e);
+ return n;
+ },
+
+ parse_way: function (line, nodes, options) {
+ var el = line.getElementsByTagName('nd');
+ if (!el.length) return;
+ var coords = [];
+ for (var i = 0; i < el.length; i++) {
+ var ref = el[i].getAttribute('ref'), n = nodes[ref];
+ if (!n) return;
+ coords.push(n.ll);
+ }
+ var layer = new L.Polyline(coords, options);
+ layer.tags = this.parse_tags(line);
+ layer.osmid = line.getAttribute('id');
+ return layer;
+ },
+
+ parse_relation: function (line, ways, options) {
+ var el = line.getElementsByTagName('member');
+ if (!el.length) return;
+ var rt, coords = [], tags = this.parse_tags(line);
+ var i;
+ for (i = 0; i < tags.length; i++)
+ if (tags[i].k === 'type') rt = tags[i].v;
+
+ if (rt !== 'multipolygon' && rt !== 'boundary' && rt !== 'waterway')
+ return;
+
+ for (i = 0; i < el.length; i++) {
+ var mt = el[i].getAttribute('type'), ref = el[i].getAttribute('ref');
+ if (mt !== 'way') continue;
+ var w = ways[ref];
+ if (!w) return;
+ coords.push(w);
+ }
+ if (!coords.length) return;
+ var layer = new L.MultiPolyline(coords, options);
+ layer.tags = this.parse_tags(line);
+ layer.osmid = line.getAttribute('id');
+ return layer;
+ },
+
+ named_node: function (node, options) {
+ var marker = new L.Marker(new L.LatLng(node.lat, node.lon), options);
+ return marker;
}
- },
-
- loadXML: function (url, cb, options, async) {
- if (async === undefined) async = this.options.async;
- if (options === undefined) options = this.options;
-
- var req = new window.XMLHttpRequest();
- req.open('GET', url, async);
- req.overrideMimeType('text/xml');
- req.onreadystatechange = function () {
- if (req.readyState !== 4) return;
- if (req.status === 200) cb(req.responseXML, options);
- };
- req.send(null);
- },
-
- addXML: function (url, options, async) {
- var _this = this;
- var cb = function (xml, options) { _this._addXML(xml, options); };
- this.loadXML(url, cb, options, async);
- },
-
- _addXML: function (xml, options) {
- var layers = this.parseOSM(xml, options);
- if (!layers) return;
- this.addLayer(layers);
- this.fire('loaded');
- },
-
- parseOSM: function (xml, options) {
- var i, el, ll, layers = [];
- var nodes = {};
- var ways = {};
- var named = false;
-
- el = xml.getElementsByTagName('node');
- for (i = 0; i < el.length; i++) {
- var l = this.parse_node(el[i], xml, options);
- if (l === undefined) continue;
- nodes[l.osmid] = l;
- if (!this.options.forceAll && !l.tags.length) continue;
- var m = this.named_node(l, options);
- if (!ll) ll = m.getLatLng();
- if (this.parse_name(m, l, 'Node')) named = true;
- layers.push(m);
- }
-
- el = xml.getElementsByTagName('way');
- for (i = 0; i < el.length; i++) {
- if (i > 10) break;
- var way = this.parse_way(el[i], nodes, options);
- if (!way) continue;
- if (!ll) ll = way.getLatLngs()[0];
- if (this.parse_name(way, way, 'Way')) named = true;
- layers.push(way);
- ways[way.osmid] = way;
- }
-
- el = xml.getElementsByTagName('relation');
- for (i = 0; i < el.length; i++) {
- if (i > 10) break;
- var relation = this.parse_relation(el[i], ways, options);
- if (!relation) continue;
- if (!ll) ll = relation.getLatLngs()[0];
- if (this.parse_name(relation, relation, 'Relation')) named = true;
- layers.push(relation);
- }
-
- if (!layers.length) return;
- var layer = layers[0];
- if (layers.length > 1)
- layer = new L.FeatureGroup(layers);
- if (!named) this.parse_name(xml, layer);
- layer.focusPoint = ll;
- return layer;
- },
-
- parse_name: function (layer, obj, obj_name) {
- if (!this.options.forceAll)
- if (!obj.tags || !obj.tags.length) return;
- var i, txt = '';
- for (i = 0; i < obj.tags.length; i++) {
- var t = obj.tags[i];
- txt += '' + t.k + ' | = | ' + t.v + ' |
';
- }
- txt += '
';
- txt = '' + obj_name + ' ' + obj.osmid + '
' + txt;
- if (layer) layer.bindPopup(txt);
- return txt;
- },
-
- parse_tags: function (line) {
- var tags = [], el = line.getElementsByTagName('tag');
- for (var i = 0; i < el.length; i++)
- tags.push({k: el[i].getAttribute('k'), v: el[i].getAttribute('v')});
- return tags;
- },
-
- parse_node: function (e) {
- var n = {osmid: e.getAttribute('id'),
- lat:e.getAttribute('lat'),
- lon:e.getAttribute('lon')
- };
- n.ll = new L.LatLng(n.lat, n.lon);
- n.tags = this.parse_tags(e);
- return n;
- },
-
- parse_way: function (line, nodes, options) {
- var el = line.getElementsByTagName('nd');
- if (!el.length) return;
- var coords = [];
- for (var i = 0; i < el.length; i++) {
- var ref = el[i].getAttribute('ref'), n = nodes[ref];
- if (!n) return;
- coords.push(n.ll);
- }
- var layer = new L.Polyline(coords, options);
- layer.tags = this.parse_tags(line);
- layer.osmid = line.getAttribute('id');
- return layer;
- },
-
- parse_relation: function (line, ways, options) {
- var el = line.getElementsByTagName('member');
- if (!el.length) return;
- var rt, coords = [], tags = this.parse_tags(line);
- var i;
- for (i = 0; i < tags.length; i++)
- if (tags[i].k === 'type') rt = tags[i].v;
-
- if (rt !== 'multipolygon' && rt !== 'boundary' && rt !== 'waterway')
- return;
-
- for (i = 0; i < el.length; i++) {
- var mt = el[i].getAttribute('type'), ref = el[i].getAttribute('ref');
- if (mt !== 'way') continue;
- var w = ways[ref];
- if (!w) return;
- coords.push(w);
- }
- if (!coords.length) return;
- var layer = new L.MultiPolyline(coords, options);
- layer.tags = this.parse_tags(line);
- layer.osmid = line.getAttribute('id');
- return layer;
- },
-
- named_node: function (node, options) {
- var marker = new L.Marker(new L.LatLng(node.lat, node.lon), options);
- return marker;
- }
-});
+ });
+}, window));
\ No newline at end of file
diff --git a/layer/vector/TOPOJSON.js b/layer/vector/TOPOJSON.js
index 45cc17f..eb75851 100644
--- a/layer/vector/TOPOJSON.js
+++ b/layer/vector/TOPOJSON.js
@@ -1,640 +1,654 @@
-/* eslint-disable */
-
--/**
-- * Embed of the topojson library from Mike Bostock v1.6.26
-- * https://github.com/mbostock/topojson
-- *
-- */
-
-(function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
- (factory((global.topojson = global.topojson || {})));
-}(this, function (exports) { 'use strict';
-
- function noop() {}
-
- function transformAbsolute(transform) {
- if (!transform) return noop;
- var x0,
- y0,
- kx = transform.scale[0],
- ky = transform.scale[1],
- dx = transform.translate[0],
- dy = transform.translate[1];
- return function(point, i) {
- if (!i) x0 = y0 = 0;
- point[0] = (x0 += point[0]) * kx + dx;
- point[1] = (y0 += point[1]) * ky + dy;
- };
- }
-
- function transformRelative(transform) {
- if (!transform) return noop;
- var x0,
- y0,
- kx = transform.scale[0],
- ky = transform.scale[1],
- dx = transform.translate[0],
- dy = transform.translate[1];
- return function(point, i) {
- if (!i) x0 = y0 = 0;
- var x1 = Math.round((point[0] - dx) / kx),
- y1 = Math.round((point[1] - dy) / ky);
- point[0] = x1 - x0;
- point[1] = y1 - y0;
- x0 = x1;
- y0 = y1;
- };
- }
-
- function reverse(array, n) {
- var t, j = array.length, i = j - n;
- while (i < --j) t = array[i], array[i++] = array[j], array[j] = t;
- }
-
- function bisect(a, x) {
- var lo = 0, hi = a.length;
- while (lo < hi) {
- var mid = lo + hi >>> 1;
- if (a[mid] < x) lo = mid + 1;
- else hi = mid;
+(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'));
}
- return lo;
- }
-
- function feature(topology, o) {
- return o.type === "GeometryCollection" ? {
- type: "FeatureCollection",
- features: o.geometries.map(function(o) { return feature$1(topology, o); })
- } : feature$1(topology, o);
- }
-
- function feature$1(topology, o) {
- var f = {
- type: "Feature",
- id: o.id,
- properties: o.properties || {},
- geometry: object(topology, o)
- };
- if (o.id == null) delete f.id;
- return f;
- }
-
- function object(topology, o) {
- var absolute = transformAbsolute(topology.transform),
- arcs = topology.arcs;
-
- function arc(i, points) {
- if (points.length) points.pop();
- for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length, p; k < n; ++k) {
- points.push(p = a[k].slice());
- absolute(p, k);
- }
- if (i < 0) reverse(points, n);
- }
-
- function point(p) {
- p = p.slice();
- absolute(p, 0);
- return p;
- }
-
- function line(arcs) {
- var points = [];
- for (var i = 0, n = arcs.length; i < n; ++i) arc(arcs[i], points);
- if (points.length < 2) points.push(points[0].slice());
- return points;
+ // attach your plugin to the global 'L' variable
+ if (typeof window !== 'undefined' && window.L) {
+ window.L.YourPlugin = factory(L);
}
+}(function (L) {
+ /* eslint-disable */
+
+ -/**
+ - * Embed of the topojson library from Mike Bostock v1.6.26
+ - * https://github.com/mbostock/topojson
+ - *
+ - */
+
+ (function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
+ (factory((global.topojson = global.topojson || {})));
+ }(this, function (exports) { 'use strict';
+
+ function noop() {}
+
+ function transformAbsolute(transform) {
+ if (!transform) return noop;
+ var x0,
+ y0,
+ kx = transform.scale[0],
+ ky = transform.scale[1],
+ dx = transform.translate[0],
+ dy = transform.translate[1];
+ return function(point, i) {
+ if (!i) x0 = y0 = 0;
+ point[0] = (x0 += point[0]) * kx + dx;
+ point[1] = (y0 += point[1]) * ky + dy;
+ };
+ }
+
+ function transformRelative(transform) {
+ if (!transform) return noop;
+ var x0,
+ y0,
+ kx = transform.scale[0],
+ ky = transform.scale[1],
+ dx = transform.translate[0],
+ dy = transform.translate[1];
+ return function(point, i) {
+ if (!i) x0 = y0 = 0;
+ var x1 = Math.round((point[0] - dx) / kx),
+ y1 = Math.round((point[1] - dy) / ky);
+ point[0] = x1 - x0;
+ point[1] = y1 - y0;
+ x0 = x1;
+ y0 = y1;
+ };
+ }
+
+ function reverse(array, n) {
+ var t, j = array.length, i = j - n;
+ while (i < --j) t = array[i], array[i++] = array[j], array[j] = t;
+ }
+
+ function bisect(a, x) {
+ var lo = 0, hi = a.length;
+ while (lo < hi) {
+ var mid = lo + hi >>> 1;
+ if (a[mid] < x) lo = mid + 1;
+ else hi = mid;
+ }
+ return lo;
+ }
+
+ function feature(topology, o) {
+ return o.type === "GeometryCollection" ? {
+ type: "FeatureCollection",
+ features: o.geometries.map(function(o) { return feature$1(topology, o); })
+ } : feature$1(topology, o);
+ }
+
+ function feature$1(topology, o) {
+ var f = {
+ type: "Feature",
+ id: o.id,
+ properties: o.properties || {},
+ geometry: object(topology, o)
+ };
+ if (o.id == null) delete f.id;
+ return f;
+ }
+
+ function object(topology, o) {
+ var absolute = transformAbsolute(topology.transform),
+ arcs = topology.arcs;
+
+ function arc(i, points) {
+ if (points.length) points.pop();
+ for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length, p; k < n; ++k) {
+ points.push(p = a[k].slice());
+ absolute(p, k);
+ }
+ if (i < 0) reverse(points, n);
+ }
- function ring(arcs) {
- var points = line(arcs);
- while (points.length < 4) points.push(points[0].slice());
- return points;
- }
+ function point(p) {
+ p = p.slice();
+ absolute(p, 0);
+ return p;
+ }
- function polygon(arcs) {
- return arcs.map(ring);
- }
+ function line(arcs) {
+ var points = [];
+ for (var i = 0, n = arcs.length; i < n; ++i) arc(arcs[i], points);
+ if (points.length < 2) points.push(points[0].slice());
+ return points;
+ }
- function geometry(o) {
- var t = o.type;
- return t === "GeometryCollection" ? {type: t, geometries: o.geometries.map(geometry)}
- : t in geometryType ? {type: t, coordinates: geometryType[t](o)}
- : null;
- }
+ function ring(arcs) {
+ var points = line(arcs);
+ while (points.length < 4) points.push(points[0].slice());
+ return points;
+ }
- var geometryType = {
- Point: function(o) { return point(o.coordinates); },
- MultiPoint: function(o) { return o.coordinates.map(point); },
- LineString: function(o) { return line(o.arcs); },
- MultiLineString: function(o) { return o.arcs.map(line); },
- Polygon: function(o) { return polygon(o.arcs); },
- MultiPolygon: function(o) { return o.arcs.map(polygon); }
- };
-
- return geometry(o);
- }
-
- function stitchArcs(topology, arcs) {
- var stitchedArcs = {},
- fragmentByStart = {},
- fragmentByEnd = {},
- fragments = [],
- emptyIndex = -1;
-
- // Stitch empty arcs first, since they may be subsumed by other arcs.
- arcs.forEach(function(i, j) {
- var arc = topology.arcs[i < 0 ? ~i : i], t;
- if (arc.length < 3 && !arc[1][0] && !arc[1][1]) {
- t = arcs[++emptyIndex], arcs[emptyIndex] = i, arcs[j] = t;
- }
- });
-
- arcs.forEach(function(i) {
- var e = ends(i),
- start = e[0],
- end = e[1],
- f, g;
-
- if (f = fragmentByEnd[start]) {
- delete fragmentByEnd[f.end];
- f.push(i);
- f.end = end;
- if (g = fragmentByStart[end]) {
- delete fragmentByStart[g.start];
- var fg = g === f ? f : f.concat(g);
- fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg;
- } else {
- fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
- }
- } else if (f = fragmentByStart[end]) {
- delete fragmentByStart[f.start];
- f.unshift(i);
- f.start = start;
- if (g = fragmentByEnd[start]) {
- delete fragmentByEnd[g.end];
- var gf = g === f ? f : g.concat(f);
- fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf;
- } else {
- fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
- }
- } else {
- f = [i];
- fragmentByStart[f.start = start] = fragmentByEnd[f.end = end] = f;
- }
- });
-
- function ends(i) {
- var arc = topology.arcs[i < 0 ? ~i : i], p0 = arc[0], p1;
- if (topology.transform) p1 = [0, 0], arc.forEach(function(dp) { p1[0] += dp[0], p1[1] += dp[1]; });
- else p1 = arc[arc.length - 1];
- return i < 0 ? [p1, p0] : [p0, p1];
- }
+ function polygon(arcs) {
+ return arcs.map(ring);
+ }
- function flush(fragmentByEnd, fragmentByStart) {
- for (var k in fragmentByEnd) {
- var f = fragmentByEnd[k];
- delete fragmentByStart[f.start];
- delete f.start;
- delete f.end;
- f.forEach(function(i) { stitchedArcs[i < 0 ? ~i : i] = 1; });
- fragments.push(f);
- }
- }
+ function geometry(o) {
+ var t = o.type;
+ return t === "GeometryCollection" ? {type: t, geometries: o.geometries.map(geometry)}
+ : t in geometryType ? {type: t, coordinates: geometryType[t](o)}
+ : null;
+ }
- flush(fragmentByEnd, fragmentByStart);
- flush(fragmentByStart, fragmentByEnd);
- arcs.forEach(function(i) { if (!stitchedArcs[i < 0 ? ~i : i]) fragments.push([i]); });
+ var geometryType = {
+ Point: function(o) { return point(o.coordinates); },
+ MultiPoint: function(o) { return o.coordinates.map(point); },
+ LineString: function(o) { return line(o.arcs); },
+ MultiLineString: function(o) { return o.arcs.map(line); },
+ Polygon: function(o) { return polygon(o.arcs); },
+ MultiPolygon: function(o) { return o.arcs.map(polygon); }
+ };
+
+ return geometry(o);
+ }
+
+ function stitchArcs(topology, arcs) {
+ var stitchedArcs = {},
+ fragmentByStart = {},
+ fragmentByEnd = {},
+ fragments = [],
+ emptyIndex = -1;
+
+ // Stitch empty arcs first, since they may be subsumed by other arcs.
+ arcs.forEach(function(i, j) {
+ var arc = topology.arcs[i < 0 ? ~i : i], t;
+ if (arc.length < 3 && !arc[1][0] && !arc[1][1]) {
+ t = arcs[++emptyIndex], arcs[emptyIndex] = i, arcs[j] = t;
+ }
+ });
+
+ arcs.forEach(function(i) {
+ var e = ends(i),
+ start = e[0],
+ end = e[1],
+ f, g;
+
+ if (f = fragmentByEnd[start]) {
+ delete fragmentByEnd[f.end];
+ f.push(i);
+ f.end = end;
+ if (g = fragmentByStart[end]) {
+ delete fragmentByStart[g.start];
+ var fg = g === f ? f : f.concat(g);
+ fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg;
+ } else {
+ fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
+ }
+ } else if (f = fragmentByStart[end]) {
+ delete fragmentByStart[f.start];
+ f.unshift(i);
+ f.start = start;
+ if (g = fragmentByEnd[start]) {
+ delete fragmentByEnd[g.end];
+ var gf = g === f ? f : g.concat(f);
+ fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf;
+ } else {
+ fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
+ }
+ } else {
+ f = [i];
+ fragmentByStart[f.start = start] = fragmentByEnd[f.end = end] = f;
+ }
+ });
+
+ function ends(i) {
+ var arc = topology.arcs[i < 0 ? ~i : i], p0 = arc[0], p1;
+ if (topology.transform) p1 = [0, 0], arc.forEach(function(dp) { p1[0] += dp[0], p1[1] += dp[1]; });
+ else p1 = arc[arc.length - 1];
+ return i < 0 ? [p1, p0] : [p0, p1];
+ }
- return fragments;
- }
+ function flush(fragmentByEnd, fragmentByStart) {
+ for (var k in fragmentByEnd) {
+ var f = fragmentByEnd[k];
+ delete fragmentByStart[f.start];
+ delete f.start;
+ delete f.end;
+ f.forEach(function(i) { stitchedArcs[i < 0 ? ~i : i] = 1; });
+ fragments.push(f);
+ }
+ }
- function mesh(topology) {
- return object(topology, meshArcs.apply(this, arguments));
- }
+ flush(fragmentByEnd, fragmentByStart);
+ flush(fragmentByStart, fragmentByEnd);
+ arcs.forEach(function(i) { if (!stitchedArcs[i < 0 ? ~i : i]) fragments.push([i]); });
- function meshArcs(topology, o, filter) {
- var arcs = [];
+ return fragments;
+ }
- function arc(i) {
- var j = i < 0 ? ~i : i;
- (geomsByArc[j] || (geomsByArc[j] = [])).push({i: i, g: geom});
- }
+ function mesh(topology) {
+ return object(topology, meshArcs.apply(this, arguments));
+ }
- function line(arcs) {
- arcs.forEach(arc);
- }
+ function meshArcs(topology, o, filter) {
+ var arcs = [];
- function polygon(arcs) {
- arcs.forEach(line);
- }
+ function arc(i) {
+ var j = i < 0 ? ~i : i;
+ (geomsByArc[j] || (geomsByArc[j] = [])).push({i: i, g: geom});
+ }
- function geometry(o) {
- if (o.type === "GeometryCollection") o.geometries.forEach(geometry);
- else if (o.type in geometryType) geom = o, geometryType[o.type](o.arcs);
- }
+ function line(arcs) {
+ arcs.forEach(arc);
+ }
- if (arguments.length > 1) {
- var geomsByArc = [],
- geom;
+ function polygon(arcs) {
+ arcs.forEach(line);
+ }
- var geometryType = {
- LineString: line,
- MultiLineString: polygon,
- Polygon: polygon,
- MultiPolygon: function(arcs) { arcs.forEach(polygon); }
- };
+ function geometry(o) {
+ if (o.type === "GeometryCollection") o.geometries.forEach(geometry);
+ else if (o.type in geometryType) geom = o, geometryType[o.type](o.arcs);
+ }
- geometry(o);
+ if (arguments.length > 1) {
+ var geomsByArc = [],
+ geom;
- geomsByArc.forEach(arguments.length < 3
- ? function(geoms) { arcs.push(geoms[0].i); }
- : function(geoms) { if (filter(geoms[0].g, geoms[geoms.length - 1].g)) arcs.push(geoms[0].i); });
- } else {
- for (var i = 0, n = topology.arcs.length; i < n; ++i) arcs.push(i);
- }
+ var geometryType = {
+ LineString: line,
+ MultiLineString: polygon,
+ Polygon: polygon,
+ MultiPolygon: function(arcs) { arcs.forEach(polygon); }
+ };
- return {type: "MultiLineString", arcs: stitchArcs(topology, arcs)};
- }
-
- function cartesianTriangleArea(triangle) {
- var a = triangle[0], b = triangle[1], c = triangle[2];
- return Math.abs((a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]));
- }
-
- function ring(ring) {
- var i = -1,
- n = ring.length,
- a,
- b = ring[n - 1],
- area = 0;
-
- while (++i < n) {
- a = b;
- b = ring[i];
- area += a[0] * b[1] - a[1] * b[0];
- }
+ geometry(o);
- return area / 2;
- }
-
- function merge(topology) {
- return object(topology, mergeArcs.apply(this, arguments));
- }
-
- function mergeArcs(topology, objects) {
- var polygonsByArc = {},
- polygons = [],
- components = [];
-
- objects.forEach(function(o) {
- if (o.type === "Polygon") register(o.arcs);
- else if (o.type === "MultiPolygon") o.arcs.forEach(register);
- });
-
- function register(polygon) {
- polygon.forEach(function(ring$$) {
- ring$$.forEach(function(arc) {
- (polygonsByArc[arc = arc < 0 ? ~arc : arc] || (polygonsByArc[arc] = [])).push(polygon);
- });
- });
- polygons.push(polygon);
- }
-
- function area(ring$$) {
- return Math.abs(ring(object(topology, {type: "Polygon", arcs: [ring$$]}).coordinates[0]));
- }
-
- polygons.forEach(function(polygon) {
- if (!polygon._) {
- var component = [],
- neighbors = [polygon];
- polygon._ = 1;
- components.push(component);
- while (polygon = neighbors.pop()) {
- component.push(polygon);
- polygon.forEach(function(ring$$) {
- ring$$.forEach(function(arc) {
- polygonsByArc[arc < 0 ? ~arc : arc].forEach(function(polygon) {
- if (!polygon._) {
- polygon._ = 1;
- neighbors.push(polygon);
- }
- });
- });
- });
- }
- }
- });
-
- polygons.forEach(function(polygon) {
- delete polygon._;
- });
-
- return {
- type: "MultiPolygon",
- arcs: components.map(function(polygons) {
- var arcs = [], n;
-
- // Extract the exterior (unique) arcs.
- polygons.forEach(function(polygon) {
- polygon.forEach(function(ring$$) {
- ring$$.forEach(function(arc) {
- if (polygonsByArc[arc < 0 ? ~arc : arc].length < 2) {
- arcs.push(arc);
- }
- });
- });
- });
-
- // Stitch the arcs into one or more rings.
- arcs = stitchArcs(topology, arcs);
-
- // If more than one ring is returned,
- // at most one of these rings can be the exterior;
- // choose the one with the greatest absolute area.
- if ((n = arcs.length) > 1) {
- for (var i = 1, k = area(arcs[0]), ki, t; i < n; ++i) {
- if ((ki = area(arcs[i])) > k) {
- t = arcs[0], arcs[0] = arcs[i], arcs[i] = t, k = ki;
- }
- }
- }
-
- return arcs;
- })
- };
- }
-
- function neighbors(objects) {
- var indexesByArc = {}, // arc index -> array of object indexes
- neighbors = objects.map(function() { return []; });
-
- function line(arcs, i) {
- arcs.forEach(function(a) {
- if (a < 0) a = ~a;
- var o = indexesByArc[a];
- if (o) o.push(i);
- else indexesByArc[a] = [i];
- });
- }
+ geomsByArc.forEach(arguments.length < 3
+ ? function(geoms) { arcs.push(geoms[0].i); }
+ : function(geoms) { if (filter(geoms[0].g, geoms[geoms.length - 1].g)) arcs.push(geoms[0].i); });
+ } else {
+ for (var i = 0, n = topology.arcs.length; i < n; ++i) arcs.push(i);
+ }
- function polygon(arcs, i) {
- arcs.forEach(function(arc) { line(arc, i); });
- }
+ return {type: "MultiLineString", arcs: stitchArcs(topology, arcs)};
+ }
+
+ function cartesianTriangleArea(triangle) {
+ var a = triangle[0], b = triangle[1], c = triangle[2];
+ return Math.abs((a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]));
+ }
+
+ function ring(ring) {
+ var i = -1,
+ n = ring.length,
+ a,
+ b = ring[n - 1],
+ area = 0;
+
+ while (++i < n) {
+ a = b;
+ b = ring[i];
+ area += a[0] * b[1] - a[1] * b[0];
+ }
- function geometry(o, i) {
- if (o.type === "GeometryCollection") o.geometries.forEach(function(o) { geometry(o, i); });
- else if (o.type in geometryType) geometryType[o.type](o.arcs, i);
- }
+ return area / 2;
+ }
- var geometryType = {
- LineString: line,
- MultiLineString: polygon,
- Polygon: polygon,
- MultiPolygon: function(arcs, i) { arcs.forEach(function(arc) { polygon(arc, i); }); }
- };
-
- objects.forEach(geometry);
-
- for (var i in indexesByArc) {
- for (var indexes = indexesByArc[i], m = indexes.length, j = 0; j < m; ++j) {
- for (var k = j + 1; k < m; ++k) {
- var ij = indexes[j], ik = indexes[k], n;
- if ((n = neighbors[ij])[i = bisect(n, ik)] !== ik) n.splice(i, 0, ik);
- if ((n = neighbors[ik])[i = bisect(n, ij)] !== ij) n.splice(i, 0, ij);
- }
- }
- }
+ function merge(topology) {
+ return object(topology, mergeArcs.apply(this, arguments));
+ }
- return neighbors;
- }
-
- function compareArea(a, b) {
- return a[1][2] - b[1][2];
- }
-
- function minAreaHeap() {
- var heap = {},
- array = [],
- size = 0;
-
- heap.push = function(object) {
- up(array[object._ = size] = object, size++);
- return size;
- };
-
- heap.pop = function() {
- if (size <= 0) return;
- var removed = array[0], object;
- if (--size > 0) object = array[size], down(array[object._ = 0] = object, 0);
- return removed;
- };
-
- heap.remove = function(removed) {
- var i = removed._, object;
- if (array[i] !== removed) return; // invalid request
- if (i !== --size) object = array[size], (compareArea(object, removed) < 0 ? up : down)(array[object._ = i] = object, i);
- return i;
- };
-
- function up(object, i) {
- while (i > 0) {
- var j = ((i + 1) >> 1) - 1,
- parent = array[j];
- if (compareArea(object, parent) >= 0) break;
- array[parent._ = i] = parent;
- array[object._ = i = j] = object;
- }
- }
+ function mergeArcs(topology, objects) {
+ var polygonsByArc = {},
+ polygons = [],
+ components = [];
- function down(object, i) {
- while (true) {
- var r = (i + 1) << 1,
- l = r - 1,
- j = i,
- child = array[j];
- if (l < size && compareArea(array[l], child) < 0) child = array[j = l];
- if (r < size && compareArea(array[r], child) < 0) child = array[j = r];
- if (j === i) break;
- array[child._ = i] = child;
- array[object._ = i = j] = object;
- }
- }
+ objects.forEach(function(o) {
+ if (o.type === "Polygon") register(o.arcs);
+ else if (o.type === "MultiPolygon") o.arcs.forEach(register);
+ });
- return heap;
- }
-
- function presimplify(topology, triangleArea) {
- var absolute = transformAbsolute(topology.transform),
- relative = transformRelative(topology.transform),
- heap = minAreaHeap();
-
- if (!triangleArea) triangleArea = cartesianTriangleArea;
-
- topology.arcs.forEach(function(arc) {
- var triangles = [],
- maxArea = 0,
- triangle,
- i,
- n,
- p;
-
- // To store each point’s effective area, we create a new array rather than
- // extending the passed-in point to workaround a Chrome/V8 bug (getting
- // stuck in smi mode). For midpoints, the initial effective area of
- // Infinity will be computed in the next step.
- for (i = 0, n = arc.length; i < n; ++i) {
- p = arc[i];
- absolute(arc[i] = [p[0], p[1], Infinity], i);
- }
-
- for (i = 1, n = arc.length - 1; i < n; ++i) {
- triangle = arc.slice(i - 1, i + 2);
- triangle[1][2] = triangleArea(triangle);
- triangles.push(triangle);
- heap.push(triangle);
- }
-
- for (i = 0, n = triangles.length; i < n; ++i) {
- triangle = triangles[i];
- triangle.previous = triangles[i - 1];
- triangle.next = triangles[i + 1];
- }
-
- while (triangle = heap.pop()) {
- var previous = triangle.previous,
- next = triangle.next;
-
- // If the area of the current point is less than that of the previous point
- // to be eliminated, use the latter's area instead. This ensures that the
- // current point cannot be eliminated without eliminating previously-
- // eliminated points.
- if (triangle[1][2] < maxArea) triangle[1][2] = maxArea;
- else maxArea = triangle[1][2];
-
- if (previous) {
- previous.next = next;
- previous[2] = triangle[2];
- update(previous);
- }
-
- if (next) {
- next.previous = previous;
- next[0] = triangle[0];
- update(next);
- }
- }
-
- arc.forEach(relative);
- });
-
- function update(triangle) {
- heap.remove(triangle);
- triangle[1][2] = triangleArea(triangle);
- heap.push(triangle);
- }
+ function register(polygon) {
+ polygon.forEach(function(ring$$) {
+ ring$$.forEach(function(arc) {
+ (polygonsByArc[arc = arc < 0 ? ~arc : arc] || (polygonsByArc[arc] = [])).push(polygon);
+ });
+ });
+ polygons.push(polygon);
+ }
- return topology;
- }
+ function area(ring$$) {
+ return Math.abs(ring(object(topology, {type: "Polygon", arcs: [ring$$]}).coordinates[0]));
+ }
- var version = "1.6.26";
+ polygons.forEach(function(polygon) {
+ if (!polygon._) {
+ var component = [],
+ neighbors = [polygon];
+ polygon._ = 1;
+ components.push(component);
+ while (polygon = neighbors.pop()) {
+ component.push(polygon);
+ polygon.forEach(function(ring$$) {
+ ring$$.forEach(function(arc) {
+ polygonsByArc[arc < 0 ? ~arc : arc].forEach(function(polygon) {
+ if (!polygon._) {
+ polygon._ = 1;
+ neighbors.push(polygon);
+ }
+ });
+ });
+ });
+ }
+ }
+ });
+
+ polygons.forEach(function(polygon) {
+ delete polygon._;
+ });
+
+ return {
+ type: "MultiPolygon",
+ arcs: components.map(function(polygons) {
+ var arcs = [], n;
+
+ // Extract the exterior (unique) arcs.
+ polygons.forEach(function(polygon) {
+ polygon.forEach(function(ring$$) {
+ ring$$.forEach(function(arc) {
+ if (polygonsByArc[arc < 0 ? ~arc : arc].length < 2) {
+ arcs.push(arc);
+ }
+ });
+ });
+ });
- exports.version = version;
- exports.mesh = mesh;
- exports.meshArcs = meshArcs;
- exports.merge = merge;
- exports.mergeArcs = mergeArcs;
- exports.feature = feature;
- exports.neighbors = neighbors;
- exports.presimplify = presimplify;
+ // Stitch the arcs into one or more rings.
+ arcs = stitchArcs(topology, arcs);
-}));
+ // If more than one ring is returned,
+ // at most one of these rings can be the exterior;
+ // choose the one with the greatest absolute area.
+ if ((n = arcs.length) > 1) {
+ for (var i = 1, k = area(arcs[0]), ki, t; i < n; ++i) {
+ if ((ki = area(arcs[i])) > k) {
+ t = arcs[0], arcs[0] = arcs[i], arcs[i] = t, k = ki;
+ }
+ }
+ }
+
+ return arcs;
+ })
+ };
+ }
+
+ function neighbors(objects) {
+ var indexesByArc = {}, // arc index -> array of object indexes
+ neighbors = objects.map(function() { return []; });
+
+ function line(arcs, i) {
+ arcs.forEach(function(a) {
+ if (a < 0) a = ~a;
+ var o = indexesByArc[a];
+ if (o) o.push(i);
+ else indexesByArc[a] = [i];
+ });
+ }
-/* eslint-disable */
+ function polygon(arcs, i) {
+ arcs.forEach(function(arc) { line(arc, i); });
+ }
-L.TOPOJSON = L.FeatureGroup.extend({
- options: {
- async: true
- },
+ function geometry(o, i) {
+ if (o.type === "GeometryCollection") o.geometries.forEach(function(o) { geometry(o, i); });
+ else if (o.type in geometryType) geometryType[o.type](o.arcs, i);
+ }
- initialize: function (data, options) {
- L.Util.setOptions(this, options);
- this._topojson = data;
- this._layers = {};
+ var geometryType = {
+ LineString: line,
+ MultiLineString: polygon,
+ Polygon: polygon,
+ MultiPolygon: function(arcs, i) { arcs.forEach(function(arc) { polygon(arc, i); }); }
+ };
+
+ objects.forEach(geometry);
+
+ for (var i in indexesByArc) {
+ for (var indexes = indexesByArc[i], m = indexes.length, j = 0; j < m; ++j) {
+ for (var k = j + 1; k < m; ++k) {
+ var ij = indexes[j], ik = indexes[k], n;
+ if ((n = neighbors[ij])[i = bisect(n, ik)] !== ik) n.splice(i, 0, ik);
+ if ((n = neighbors[ik])[i = bisect(n, ij)] !== ij) n.splice(i, 0, ij);
+ }
+ }
+ }
- if (data) {
- this.addTOPOJSON(data, options, this.options.async);
+ return neighbors;
+ }
+
+ function compareArea(a, b) {
+ return a[1][2] - b[1][2];
+ }
+
+ function minAreaHeap() {
+ var heap = {},
+ array = [],
+ size = 0;
+
+ heap.push = function(object) {
+ up(array[object._ = size] = object, size++);
+ return size;
+ };
+
+ heap.pop = function() {
+ if (size <= 0) return;
+ var removed = array[0], object;
+ if (--size > 0) object = array[size], down(array[object._ = 0] = object, 0);
+ return removed;
+ };
+
+ heap.remove = function(removed) {
+ var i = removed._, object;
+ if (array[i] !== removed) return; // invalid request
+ if (i !== --size) object = array[size], (compareArea(object, removed) < 0 ? up : down)(array[object._ = i] = object, i);
+ return i;
+ };
+
+ function up(object, i) {
+ while (i > 0) {
+ var j = ((i + 1) >> 1) - 1,
+ parent = array[j];
+ if (compareArea(object, parent) >= 0) break;
+ array[parent._ = i] = parent;
+ array[object._ = i = j] = object;
+ }
}
- },
-
- loadJSON: function (url, cb, options, async) {
- if (async === undefined) async = this.options.async;
- if (options === undefined) options = this.options;
-
- var req = new window.XMLHttpRequest();
-
- // Check for IE8 and IE9 Fix Cors for those browsers
- if (req.withCredentials === undefined && typeof window.XDomainRequest !== 'undefined') {
- var xdr = new window.XDomainRequest();
- xdr.open('GET', url, async);
- xdr.onprogress = function () { };
- xdr.ontimeout = function () { };
- xdr.onerror = function () { };
- xdr.onload = function () {
- if (xdr.responseText) {
- //var xml = new window.ActiveXObject('Microsoft.XMLDOM');
- //xml.loadJSON(xdr.responseText);
- cb(xdr.responseText, options);
- }
- };
- setTimeout(function () { xdr.send(); }, 0);
- } else {
- req.open('GET', url, async);
- try {
- req.overrideMimeType('application/json'); // unsupported by IE
- } catch (e) { }
- req.onreadystatechange = function () {
- if (req.readyState !== 4) return;
- if (req.status === 200) cb(req.response, options);
- };
- req.send(null);
+
+ function down(object, i) {
+ while (true) {
+ var r = (i + 1) << 1,
+ l = r - 1,
+ j = i,
+ child = array[j];
+ if (l < size && compareArea(array[l], child) < 0) child = array[j = l];
+ if (r < size && compareArea(array[r], child) < 0) child = array[j = r];
+ if (j === i) break;
+ array[child._ = i] = child;
+ array[object._ = i = j] = object;
+ }
}
- },
-
- addTOPOJSON: function (url, options, async) {
- var _this = this,
- cb = function (data) { _this._addTOPOJSON(data); };
- this.loadJSON(url, cb, options, async);
- },
-
- _addTOPOJSON: function (data) {
- var layers = this.parseTOPOJSON(data);
- if (!layers || !layers.length) return;
- for (var i = 0; i < layers.length; i++) {
- this.fire('addlayer', {
- layer: layers[i]
- });
- this.addLayer(layers[i]);
+
+ return heap;
+ }
+
+ function presimplify(topology, triangleArea) {
+ var absolute = transformAbsolute(topology.transform),
+ relative = transformRelative(topology.transform),
+ heap = minAreaHeap();
+
+ if (!triangleArea) triangleArea = cartesianTriangleArea;
+
+ topology.arcs.forEach(function(arc) {
+ var triangles = [],
+ maxArea = 0,
+ triangle,
+ i,
+ n,
+ p;
+
+ // To store each point’s effective area, we create a new array rather than
+ // extending the passed-in point to workaround a Chrome/V8 bug (getting
+ // stuck in smi mode). For midpoints, the initial effective area of
+ // Infinity will be computed in the next step.
+ for (i = 0, n = arc.length; i < n; ++i) {
+ p = arc[i];
+ absolute(arc[i] = [p[0], p[1], Infinity], i);
+ }
+
+ for (i = 1, n = arc.length - 1; i < n; ++i) {
+ triangle = arc.slice(i - 1, i + 2);
+ triangle[1][2] = triangleArea(triangle);
+ triangles.push(triangle);
+ heap.push(triangle);
+ }
+
+ for (i = 0, n = triangles.length; i < n; ++i) {
+ triangle = triangles[i];
+ triangle.previous = triangles[i - 1];
+ triangle.next = triangles[i + 1];
+ }
+
+ while (triangle = heap.pop()) {
+ var previous = triangle.previous,
+ next = triangle.next;
+
+ // If the area of the current point is less than that of the previous point
+ // to be eliminated, use the latter's area instead. This ensures that the
+ // current point cannot be eliminated without eliminating previously-
+ // eliminated points.
+ if (triangle[1][2] < maxArea) triangle[1][2] = maxArea;
+ else maxArea = triangle[1][2];
+
+ if (previous) {
+ previous.next = next;
+ previous[2] = triangle[2];
+ update(previous);
+ }
+
+ if (next) {
+ next.previous = previous;
+ next[0] = triangle[0];
+ update(next);
+ }
+ }
+
+ arc.forEach(relative);
+ });
+
+ function update(triangle) {
+ heap.remove(triangle);
+ triangle[1][2] = triangleArea(triangle);
+ heap.push(triangle);
}
- this.fire('loaded');
- },
- _addData : function (l, d) {
- if ('addData' in l) l.addData(d);
- if ('setGeoJSON' in l) l.setGeoJSON(d);
- },
- parseTOPOJSON : function (data) {
- var layers = [],
- o = typeof data === 'string' ? JSON.parse(data) : data;
- for (var i in o.objects) {
- var layer = L.geoJson(),
- ft = topojson.feature(o, o.objects[i]);
- if (ft.features) this._addData(layer, ft.features);
- else _this._addData(layer, ft);
- layers.push(layer);
+
+ return topology;
+ }
+
+ var version = "1.6.26";
+
+ exports.version = version;
+ exports.mesh = mesh;
+ exports.meshArcs = meshArcs;
+ exports.merge = merge;
+ exports.mergeArcs = mergeArcs;
+ exports.feature = feature;
+ exports.neighbors = neighbors;
+ exports.presimplify = presimplify;
+
+ }));
+
+ /* eslint-disable */
+
+ L.TOPOJSON = L.FeatureGroup.extend({
+ options: {
+ async: true
+ },
+
+ initialize: function (data, options) {
+ L.Util.setOptions(this, options);
+ this._topojson = data;
+ this._layers = {};
+
+ if (data) {
+ this.addTOPOJSON(data, options, this.options.async);
+ }
+ },
+
+ loadJSON: function (url, cb, options, async) {
+ if (async === undefined) async = this.options.async;
+ if (options === undefined) options = this.options;
+
+ var req = new window.XMLHttpRequest();
+
+ // Check for IE8 and IE9 Fix Cors for those browsers
+ if (req.withCredentials === undefined && typeof window.XDomainRequest !== 'undefined') {
+ var xdr = new window.XDomainRequest();
+ xdr.open('GET', url, async);
+ xdr.onprogress = function () { };
+ xdr.ontimeout = function () { };
+ xdr.onerror = function () { };
+ xdr.onload = function () {
+ if (xdr.responseText) {
+ //var xml = new window.ActiveXObject('Microsoft.XMLDOM');
+ //xml.loadJSON(xdr.responseText);
+ cb(xdr.responseText, options);
+ }
+ };
+ setTimeout(function () { xdr.send(); }, 0);
+ } else {
+ req.open('GET', url, async);
+ try {
+ req.overrideMimeType('application/json'); // unsupported by IE
+ } catch (e) { }
+ req.onreadystatechange = function () {
+ if (req.readyState !== 4) return;
+ if (req.status === 200) cb(req.response, options);
+ };
+ req.send(null);
+ }
+ },
+
+ addTOPOJSON: function (url, options, async) {
+ var _this = this,
+ cb = function (data) { _this._addTOPOJSON(data); };
+ this.loadJSON(url, cb, options, async);
+ },
+
+ _addTOPOJSON: function (data) {
+ var layers = this.parseTOPOJSON(data);
+ if (!layers || !layers.length) return;
+ for (var i = 0; i < layers.length; i++) {
+ this.fire('addlayer', {
+ layer: layers[i]
+ });
+ this.addLayer(layers[i]);
+ }
+ this.fire('loaded');
+ },
+ _addData : function (l, d) {
+ if ('addData' in l) l.addData(d);
+ if ('setGeoJSON' in l) l.setGeoJSON(d);
+ },
+ parseTOPOJSON : function (data) {
+ var layers = [],
+ o = typeof data === 'string' ? JSON.parse(data) : data;
+ for (var i in o.objects) {
+ var layer = L.geoJson(),
+ ft = topojson.feature(o, o.objects[i]);
+ if (ft.features) this._addData(layer, ft.features);
+ else _this._addData(layer, ft);
+ layers.push(layer);
+ }
+
+ return layers;
}
-
- return layers;
- }
-});
\ No newline at end of file
+ });
+}, window));
\ No newline at end of file