leaflet-ruby 0.3.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/LICENSE +21 -0
- data/README.rdoc +55 -0
- data/Rakefile +15 -0
- data/leaflet-ruby.gemspec +24 -0
- data/lib/leaflet-ruby.rb +18 -0
- data/lib/leaflet/CHANGELOG.md +181 -0
- data/lib/leaflet/Jakefile.js +65 -0
- data/lib/leaflet/LICENSE +22 -0
- data/lib/leaflet/README.md +32 -0
- data/lib/leaflet/build/build.html +243 -0
- data/lib/leaflet/build/build.js +79 -0
- data/lib/leaflet/build/deps.js +231 -0
- data/lib/leaflet/build/hint.js +30 -0
- data/lib/leaflet/build/hintrc.js +44 -0
- data/lib/leaflet/debug/control/control-layers.html +47 -0
- data/lib/leaflet/debug/control/map-control.html +29 -0
- data/lib/leaflet/debug/css/mobile.css +6 -0
- data/lib/leaflet/debug/css/screen.css +5 -0
- data/lib/leaflet/debug/geojson/geojson-sample.js +53 -0
- data/lib/leaflet/debug/geojson/geojson.html +56 -0
- data/lib/leaflet/debug/leaflet-include.js +120 -0
- data/lib/leaflet/debug/map/canvas.html +46 -0
- data/lib/leaflet/debug/map/map-mobile.html +42 -0
- data/lib/leaflet/debug/map/map.html +54 -0
- data/lib/leaflet/debug/map/max-bounds.html +36 -0
- data/lib/leaflet/debug/map/scroll.html +35 -0
- data/lib/leaflet/debug/map/wms-marble.html +30 -0
- data/lib/leaflet/debug/map/wms.html +37 -0
- data/lib/leaflet/debug/vector/editable.html +43 -0
- data/lib/leaflet/debug/vector/route.js +1 -0
- data/lib/leaflet/debug/vector/vector-bounds.html +69 -0
- data/lib/leaflet/debug/vector/vector-canvas.html +92 -0
- data/lib/leaflet/debug/vector/vector-mobile.html +38 -0
- data/lib/leaflet/debug/vector/vector-simple.html +63 -0
- data/lib/leaflet/debug/vector/vector.html +38 -0
- data/lib/leaflet/dist/images/layers.png +0 -0
- data/lib/leaflet/dist/images/marker-shadow.png +0 -0
- data/lib/leaflet/dist/images/marker.png +0 -0
- data/lib/leaflet/dist/images/popup-close.png +0 -0
- data/lib/leaflet/dist/images/zoom-in.png +0 -0
- data/lib/leaflet/dist/images/zoom-out.png +0 -0
- data/lib/leaflet/dist/leaflet-src.js +5537 -0
- data/lib/leaflet/dist/leaflet.css +323 -0
- data/lib/leaflet/dist/leaflet.ie.css +48 -0
- data/lib/leaflet/dist/leaflet.js +6 -0
- data/lib/leaflet/lib/jasmine/jasmine-html.js +182 -0
- data/lib/leaflet/lib/jasmine/jasmine.css +166 -0
- data/lib/leaflet/lib/jasmine/jasmine.js +2421 -0
- data/lib/leaflet/spec/runner.html +57 -0
- data/lib/leaflet/spec/suites/LeafletSpec.js +15 -0
- data/lib/leaflet/spec/suites/SpecHelper.js +28 -0
- data/lib/leaflet/spec/suites/core/ClassSpec.js +153 -0
- data/lib/leaflet/spec/suites/core/EventsSpec.js +110 -0
- data/lib/leaflet/spec/suites/core/UtilSpec.js +63 -0
- data/lib/leaflet/spec/suites/dom/DomEventSpec.js +102 -0
- data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +59 -0
- data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +1 -0
- data/lib/leaflet/spec/suites/geo/LatLngSpec.js +76 -0
- data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +42 -0
- data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +53 -0
- data/lib/leaflet/spec/suites/geometry/PointSpec.js +45 -0
- data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +19 -0
- data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +1 -0
- data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +35 -0
- data/lib/leaflet/spec/suites/map/MapSpec.js +1 -0
- data/lib/leaflet/src/Leaflet.js +33 -0
- data/lib/leaflet/src/control/Control.Attribution.js +66 -0
- data/lib/leaflet/src/control/Control.Layers.js +167 -0
- data/lib/leaflet/src/control/Control.Zoom.js +36 -0
- data/lib/leaflet/src/control/Control.js +9 -0
- data/lib/leaflet/src/core/Browser.js +53 -0
- data/lib/leaflet/src/core/Class.js +66 -0
- data/lib/leaflet/src/core/Events.js +62 -0
- data/lib/leaflet/src/core/Handler.js +29 -0
- data/lib/leaflet/src/core/Util.js +108 -0
- data/lib/leaflet/src/dom/DomEvent.DoubleTap.js +43 -0
- data/lib/leaflet/src/dom/DomEvent.js +154 -0
- data/lib/leaflet/src/dom/DomUtil.js +155 -0
- data/lib/leaflet/src/dom/Draggable.js +147 -0
- data/lib/leaflet/src/dom/transition/Transition.Native.js +102 -0
- data/lib/leaflet/src/dom/transition/Transition.Timer.js +126 -0
- data/lib/leaflet/src/dom/transition/Transition.js +28 -0
- data/lib/leaflet/src/geo/LatLng.js +44 -0
- data/lib/leaflet/src/geo/LatLngBounds.js +86 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3395.js +13 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3857.js +17 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG4326.js +7 -0
- data/lib/leaflet/src/geo/crs/CRS.js +17 -0
- data/lib/leaflet/src/geo/projection/Projection.LonLat.js +10 -0
- data/lib/leaflet/src/geo/projection/Projection.Mercator.js +51 -0
- data/lib/leaflet/src/geo/projection/Projection.SphericalMercator.js +23 -0
- data/lib/leaflet/src/geo/projection/Projection.js +5 -0
- data/lib/leaflet/src/geometry/Bounds.js +50 -0
- data/lib/leaflet/src/geometry/LineUtil.js +194 -0
- data/lib/leaflet/src/geometry/Point.js +66 -0
- data/lib/leaflet/src/geometry/PolyUtil.js +59 -0
- data/lib/leaflet/src/geometry/Transformation.js +31 -0
- data/lib/leaflet/src/layer/FeatureGroup.js +40 -0
- data/lib/leaflet/src/layer/GeoJSON.js +104 -0
- data/lib/leaflet/src/layer/ImageOverlay.js +58 -0
- data/lib/leaflet/src/layer/LayerGroup.js +74 -0
- data/lib/leaflet/src/layer/Popup.js +179 -0
- data/lib/leaflet/src/layer/marker/Icon.js +58 -0
- data/lib/leaflet/src/layer/marker/Marker.Drag.js +57 -0
- data/lib/leaflet/src/layer/marker/Marker.Popup.js +42 -0
- data/lib/leaflet/src/layer/marker/Marker.js +142 -0
- data/lib/leaflet/src/layer/tile/TileLayer.Canvas.js +41 -0
- data/lib/leaflet/src/layer/tile/TileLayer.WMS.js +47 -0
- data/lib/leaflet/src/layer/tile/TileLayer.js +310 -0
- data/lib/leaflet/src/layer/vector/Circle.js +68 -0
- data/lib/leaflet/src/layer/vector/CircleMarker.js +25 -0
- data/lib/leaflet/src/layer/vector/MultiPoly.js +34 -0
- data/lib/leaflet/src/layer/vector/Path.Popup.js +24 -0
- data/lib/leaflet/src/layer/vector/Path.SVG.js +138 -0
- data/lib/leaflet/src/layer/vector/Path.VML.js +93 -0
- data/lib/leaflet/src/layer/vector/Path.js +88 -0
- data/lib/leaflet/src/layer/vector/Polygon.js +64 -0
- data/lib/leaflet/src/layer/vector/Polyline.js +146 -0
- data/lib/leaflet/src/layer/vector/canvas/Circle.Canvas.js +18 -0
- data/lib/leaflet/src/layer/vector/canvas/Path.Canvas.js +146 -0
- data/lib/leaflet/src/layer/vector/canvas/Polygon.Canvas.js +34 -0
- data/lib/leaflet/src/layer/vector/canvas/Polyline.Canvas.js +27 -0
- data/lib/leaflet/src/map/Map.js +613 -0
- data/lib/leaflet/src/map/anim/Map.PanAnimation.js +70 -0
- data/lib/leaflet/src/map/anim/Map.ZoomAnimation.js +133 -0
- data/lib/leaflet/src/map/ext/Map.Control.js +50 -0
- data/lib/leaflet/src/map/ext/Map.Geolocation.js +86 -0
- data/lib/leaflet/src/map/ext/Map.Popup.js +20 -0
- data/lib/leaflet/src/map/handler/Map.BoxZoom.js +73 -0
- data/lib/leaflet/src/map/handler/Map.DoubleClickZoom.js +18 -0
- data/lib/leaflet/src/map/handler/Map.Drag.js +81 -0
- data/lib/leaflet/src/map/handler/Map.ScrollWheelZoom.js +55 -0
- data/lib/leaflet/src/map/handler/Map.TouchZoom.js +93 -0
- data/lib/zerista/CRS.Cartesian.js +20 -0
- data/lib/zerista/Projection.Identity.js +11 -0
- data/lib/zerista/zerista_layer.js +97 -0
- data/vendor/assets/javascripts/leaflet.js +139 -0
- data/vendor/assets/stylesheets/leaflet.css +1 -0
- data/vendor/assets/stylesheets/leaflet.ie.css +1 -0
- metadata +185 -0
@@ -0,0 +1,167 @@
|
|
1
|
+
|
2
|
+
L.Control.Layers = L.Class.extend({
|
3
|
+
options: {
|
4
|
+
collapsed: !L.Browser.touch
|
5
|
+
},
|
6
|
+
|
7
|
+
initialize: function (baseLayers, overlays, options) {
|
8
|
+
L.Util.setOptions(this, options);
|
9
|
+
|
10
|
+
this._layers = {};
|
11
|
+
|
12
|
+
for (var i in baseLayers) {
|
13
|
+
if (baseLayers.hasOwnProperty(i)) {
|
14
|
+
this._addLayer(baseLayers[i], i);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
for (i in overlays) {
|
19
|
+
if (overlays.hasOwnProperty(i)) {
|
20
|
+
this._addLayer(overlays[i], i, true);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
},
|
24
|
+
|
25
|
+
onAdd: function (map) {
|
26
|
+
this._map = map;
|
27
|
+
|
28
|
+
this._initLayout();
|
29
|
+
this._update();
|
30
|
+
},
|
31
|
+
|
32
|
+
getContainer: function () {
|
33
|
+
return this._container;
|
34
|
+
},
|
35
|
+
|
36
|
+
getPosition: function () {
|
37
|
+
return L.Control.Position.TOP_RIGHT;
|
38
|
+
},
|
39
|
+
|
40
|
+
addBaseLayer: function (layer, name) {
|
41
|
+
this._addLayer(layer, name);
|
42
|
+
this._update();
|
43
|
+
return this;
|
44
|
+
},
|
45
|
+
|
46
|
+
addOverlay: function (layer, name) {
|
47
|
+
this._addLayer(layer, name, true);
|
48
|
+
this._update();
|
49
|
+
return this;
|
50
|
+
},
|
51
|
+
|
52
|
+
removeLayer: function (layer) {
|
53
|
+
var id = L.Util.stamp(layer);
|
54
|
+
delete this._layers[id];
|
55
|
+
this._update();
|
56
|
+
return this;
|
57
|
+
},
|
58
|
+
|
59
|
+
_initLayout: function () {
|
60
|
+
this._container = L.DomUtil.create('div', 'leaflet-control-layers');
|
61
|
+
L.DomEvent.disableClickPropagation(this._container);
|
62
|
+
|
63
|
+
this._form = L.DomUtil.create('form', 'leaflet-control-layers-list');
|
64
|
+
|
65
|
+
if (this.options.collapsed) {
|
66
|
+
L.DomEvent.addListener(this._container, 'mouseover', this._expand, this);
|
67
|
+
L.DomEvent.addListener(this._container, 'mouseout', this._collapse, this);
|
68
|
+
|
69
|
+
var link = this._layersLink = L.DomUtil.create('a', 'leaflet-control-layers-toggle');
|
70
|
+
link.href = '#';
|
71
|
+
link.title = 'Layers';
|
72
|
+
|
73
|
+
L.DomEvent.addListener(link, 'focus', this._expand, this);
|
74
|
+
L.DomEvent.addListener(this._map, L.Draggable.START, this._collapse, this);
|
75
|
+
// TODO keyboard accessibility
|
76
|
+
|
77
|
+
this._container.appendChild(link);
|
78
|
+
} else {
|
79
|
+
this._expand();
|
80
|
+
}
|
81
|
+
|
82
|
+
this._baseLayersList = L.DomUtil.create('div', 'leaflet-control-layers-base', this._form);
|
83
|
+
this._separator = L.DomUtil.create('div', 'leaflet-control-layers-separator', this._form);
|
84
|
+
this._overlaysList = L.DomUtil.create('div', 'leaflet-control-layers-overlays', this._form);
|
85
|
+
|
86
|
+
this._container.appendChild(this._form);
|
87
|
+
},
|
88
|
+
|
89
|
+
_addLayer: function (layer, name, overlay) {
|
90
|
+
var id = L.Util.stamp(layer);
|
91
|
+
this._layers[id] = {
|
92
|
+
layer: layer,
|
93
|
+
name: name,
|
94
|
+
overlay: overlay
|
95
|
+
};
|
96
|
+
},
|
97
|
+
|
98
|
+
_update: function () {
|
99
|
+
if (!this._container) {
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
|
103
|
+
this._baseLayersList.innerHTML = '';
|
104
|
+
this._overlaysList.innerHTML = '';
|
105
|
+
|
106
|
+
var baseLayersPresent = false,
|
107
|
+
overlaysPresent = false;
|
108
|
+
|
109
|
+
for (var i in this._layers) {
|
110
|
+
if (this._layers.hasOwnProperty(i)) {
|
111
|
+
var obj = this._layers[i];
|
112
|
+
this._addItem(obj);
|
113
|
+
overlaysPresent = overlaysPresent || obj.overlay;
|
114
|
+
baseLayersPresent = baseLayersPresent || !obj.overlay;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
this._separator.style.display = (overlaysPresent && baseLayersPresent ? '' : 'none');
|
119
|
+
},
|
120
|
+
|
121
|
+
_addItem: function (obj, onclick) {
|
122
|
+
var label = document.createElement('label');
|
123
|
+
|
124
|
+
var input = document.createElement('input');
|
125
|
+
if (!obj.overlay) {
|
126
|
+
input.name = 'leaflet-base-layers';
|
127
|
+
}
|
128
|
+
input.type = obj.overlay ? 'checkbox' : 'radio';
|
129
|
+
input.checked = this._map.hasLayer(obj.layer);
|
130
|
+
input.layerId = L.Util.stamp(obj.layer);
|
131
|
+
|
132
|
+
L.DomEvent.addListener(input, 'click', this._onInputClick, this);
|
133
|
+
|
134
|
+
var name = document.createTextNode(' ' + obj.name);
|
135
|
+
|
136
|
+
label.appendChild(input);
|
137
|
+
label.appendChild(name);
|
138
|
+
|
139
|
+
var container = obj.overlay ? this._overlaysList : this._baseLayersList;
|
140
|
+
container.appendChild(label);
|
141
|
+
},
|
142
|
+
|
143
|
+
_onInputClick: function () {
|
144
|
+
var i, input, obj,
|
145
|
+
inputs = this._form.getElementsByTagName('input'),
|
146
|
+
inputsLen = inputs.length;
|
147
|
+
|
148
|
+
for (i = 0; i < inputsLen; i++) {
|
149
|
+
input = inputs[i];
|
150
|
+
obj = this._layers[input.layerId];
|
151
|
+
|
152
|
+
if (input.checked) {
|
153
|
+
this._map.addLayer(obj.layer, !obj.overlay);
|
154
|
+
} else {
|
155
|
+
this._map.removeLayer(obj.layer);
|
156
|
+
}
|
157
|
+
}
|
158
|
+
},
|
159
|
+
|
160
|
+
_expand: function () {
|
161
|
+
L.DomUtil.addClass(this._container, 'leaflet-control-layers-expanded');
|
162
|
+
},
|
163
|
+
|
164
|
+
_collapse: function () {
|
165
|
+
this._container.className = this._container.className.replace(' leaflet-control-layers-expanded', '');
|
166
|
+
}
|
167
|
+
});
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
L.Control.Zoom = L.Class.extend({
|
3
|
+
onAdd: function (map) {
|
4
|
+
this._map = map;
|
5
|
+
this._container = L.DomUtil.create('div', 'leaflet-control-zoom');
|
6
|
+
|
7
|
+
this._zoomInButton = this._createButton(
|
8
|
+
'Zoom in', 'leaflet-control-zoom-in', this._map.zoomIn, this._map);
|
9
|
+
this._zoomOutButton = this._createButton(
|
10
|
+
'Zoom out', 'leaflet-control-zoom-out', this._map.zoomOut, this._map);
|
11
|
+
|
12
|
+
this._container.appendChild(this._zoomInButton);
|
13
|
+
this._container.appendChild(this._zoomOutButton);
|
14
|
+
},
|
15
|
+
|
16
|
+
getContainer: function () {
|
17
|
+
return this._container;
|
18
|
+
},
|
19
|
+
|
20
|
+
getPosition: function () {
|
21
|
+
return L.Control.Position.TOP_LEFT;
|
22
|
+
},
|
23
|
+
|
24
|
+
_createButton: function (title, className, fn, context) {
|
25
|
+
var link = document.createElement('a');
|
26
|
+
link.href = '#';
|
27
|
+
link.title = title;
|
28
|
+
link.className = className;
|
29
|
+
|
30
|
+
L.DomEvent.disableClickPropagation(link);
|
31
|
+
L.DomEvent.addListener(link, 'click', L.DomEvent.preventDefault);
|
32
|
+
L.DomEvent.addListener(link, 'click', fn, context);
|
33
|
+
|
34
|
+
return link;
|
35
|
+
}
|
36
|
+
});
|
@@ -0,0 +1,53 @@
|
|
1
|
+
(function () {
|
2
|
+
var ua = navigator.userAgent.toLowerCase(),
|
3
|
+
ie = !!window.ActiveXObject,
|
4
|
+
webkit = ua.indexOf("webkit") !== -1,
|
5
|
+
mobile = typeof orientation !== 'undefined' ? true : false,
|
6
|
+
android = ua.indexOf("android") !== -1,
|
7
|
+
opera = window.opera;
|
8
|
+
|
9
|
+
L.Browser = {
|
10
|
+
ie: ie,
|
11
|
+
ie6: ie && !window.XMLHttpRequest,
|
12
|
+
|
13
|
+
webkit: webkit,
|
14
|
+
webkit3d: webkit && ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()),
|
15
|
+
|
16
|
+
gecko: ua.indexOf("gecko") !== -1,
|
17
|
+
|
18
|
+
opera: opera,
|
19
|
+
|
20
|
+
android: android,
|
21
|
+
mobileWebkit: mobile && webkit,
|
22
|
+
mobileOpera: mobile && opera,
|
23
|
+
|
24
|
+
mobile: mobile,
|
25
|
+
touch: (function () {
|
26
|
+
var touchSupported = false,
|
27
|
+
startName = 'ontouchstart';
|
28
|
+
|
29
|
+
// WebKit, etc
|
30
|
+
if (startName in document.documentElement) {
|
31
|
+
return true;
|
32
|
+
}
|
33
|
+
|
34
|
+
// Firefox/Gecko
|
35
|
+
var e = document.createElement('div');
|
36
|
+
|
37
|
+
// If no support for basic event stuff, unlikely to have touch support
|
38
|
+
if (!e.setAttribute || !e.removeAttribute) {
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
|
42
|
+
e.setAttribute(startName, 'return;');
|
43
|
+
if (typeof e[startName] === 'function') {
|
44
|
+
touchSupported = true;
|
45
|
+
}
|
46
|
+
|
47
|
+
e.removeAttribute(startName);
|
48
|
+
e = null;
|
49
|
+
|
50
|
+
return touchSupported;
|
51
|
+
}())
|
52
|
+
};
|
53
|
+
}());
|
@@ -0,0 +1,66 @@
|
|
1
|
+
/*
|
2
|
+
* Class powers the OOP facilities of the library. Thanks to John Resig and Dean Edwards for inspiration!
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Class = function () {};
|
6
|
+
|
7
|
+
L.Class.extend = function (/*Object*/ props) /*-> Class*/ {
|
8
|
+
|
9
|
+
// extended class with the new prototype
|
10
|
+
var NewClass = function () {
|
11
|
+
if (this.initialize) {
|
12
|
+
this.initialize.apply(this, arguments);
|
13
|
+
}
|
14
|
+
};
|
15
|
+
|
16
|
+
// instantiate class without calling constructor
|
17
|
+
var F = function () {};
|
18
|
+
F.prototype = this.prototype;
|
19
|
+
var proto = new F();
|
20
|
+
|
21
|
+
proto.constructor = NewClass;
|
22
|
+
NewClass.prototype = proto;
|
23
|
+
|
24
|
+
// add superclass access
|
25
|
+
NewClass.superclass = this.prototype;
|
26
|
+
|
27
|
+
// add class name
|
28
|
+
//proto.className = props;
|
29
|
+
|
30
|
+
//inherit parent's statics
|
31
|
+
for (var i in this) {
|
32
|
+
if (this.hasOwnProperty(i) && i !== 'prototype' && i !== 'superclass') {
|
33
|
+
NewClass[i] = this[i];
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
// mix static properties into the class
|
38
|
+
if (props.statics) {
|
39
|
+
L.Util.extend(NewClass, props.statics);
|
40
|
+
delete props.statics;
|
41
|
+
}
|
42
|
+
|
43
|
+
// mix includes into the prototype
|
44
|
+
if (props.includes) {
|
45
|
+
L.Util.extend.apply(null, [proto].concat(props.includes));
|
46
|
+
delete props.includes;
|
47
|
+
}
|
48
|
+
|
49
|
+
// merge options
|
50
|
+
if (props.options && proto.options) {
|
51
|
+
props.options = L.Util.extend({}, proto.options, props.options);
|
52
|
+
}
|
53
|
+
|
54
|
+
// mix given properties into the prototype
|
55
|
+
L.Util.extend(proto, props);
|
56
|
+
|
57
|
+
// allow inheriting further
|
58
|
+
NewClass.extend = L.Class.extend;
|
59
|
+
|
60
|
+
// method for adding properties to prototype
|
61
|
+
NewClass.include = function (props) {
|
62
|
+
L.Util.extend(this.prototype, props);
|
63
|
+
};
|
64
|
+
|
65
|
+
return NewClass;
|
66
|
+
};
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/*
|
2
|
+
* L.Mixin.Events adds custom events functionality to Leaflet classes
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Mixin = {};
|
6
|
+
|
7
|
+
L.Mixin.Events = {
|
8
|
+
addEventListener: function (/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) {
|
9
|
+
var events = this._leaflet_events = this._leaflet_events || {};
|
10
|
+
events[type] = events[type] || [];
|
11
|
+
events[type].push({
|
12
|
+
action: fn,
|
13
|
+
context: context || this
|
14
|
+
});
|
15
|
+
return this;
|
16
|
+
},
|
17
|
+
|
18
|
+
hasEventListeners: function (/*String*/ type) /*-> Boolean*/ {
|
19
|
+
var k = '_leaflet_events';
|
20
|
+
return (k in this) && (type in this[k]) && (this[k][type].length > 0);
|
21
|
+
},
|
22
|
+
|
23
|
+
removeEventListener: function (/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) {
|
24
|
+
if (!this.hasEventListeners(type)) {
|
25
|
+
return this;
|
26
|
+
}
|
27
|
+
|
28
|
+
for (var i = 0, events = this._leaflet_events, len = events[type].length; i < len; i++) {
|
29
|
+
if (
|
30
|
+
(events[type][i].action === fn) &&
|
31
|
+
(!context || (events[type][i].context === context))
|
32
|
+
) {
|
33
|
+
events[type].splice(i, 1);
|
34
|
+
return this;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
return this;
|
38
|
+
},
|
39
|
+
|
40
|
+
fireEvent: function (/*String*/ type, /*(optional) Object*/ data) {
|
41
|
+
if (!this.hasEventListeners(type)) {
|
42
|
+
return this;
|
43
|
+
}
|
44
|
+
|
45
|
+
var event = L.Util.extend({
|
46
|
+
type: type,
|
47
|
+
target: this
|
48
|
+
}, data);
|
49
|
+
|
50
|
+
var listeners = this._leaflet_events[type].slice();
|
51
|
+
|
52
|
+
for (var i = 0, len = listeners.length; i < len; i++) {
|
53
|
+
listeners[i].action.call(listeners[i].context || this, event);
|
54
|
+
}
|
55
|
+
|
56
|
+
return this;
|
57
|
+
}
|
58
|
+
};
|
59
|
+
|
60
|
+
L.Mixin.Events.on = L.Mixin.Events.addEventListener;
|
61
|
+
L.Mixin.Events.off = L.Mixin.Events.removeEventListener;
|
62
|
+
L.Mixin.Events.fire = L.Mixin.Events.fireEvent;
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
* L.Handler classes are used internally to inject interaction features to classes like Map and Marker.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Handler = L.Class.extend({
|
6
|
+
initialize: function (map) {
|
7
|
+
this._map = map;
|
8
|
+
},
|
9
|
+
|
10
|
+
enable: function () {
|
11
|
+
if (this._enabled) {
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
this._enabled = true;
|
15
|
+
this.addHooks();
|
16
|
+
},
|
17
|
+
|
18
|
+
disable: function () {
|
19
|
+
if (!this._enabled) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
this._enabled = false;
|
23
|
+
this.removeHooks();
|
24
|
+
},
|
25
|
+
|
26
|
+
enabled: function () {
|
27
|
+
return !!this._enabled;
|
28
|
+
}
|
29
|
+
});
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/*
|
2
|
+
* L.Util is a namespace for various utility functions.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Util = {
|
6
|
+
extend: function (/*Object*/ dest) /*-> Object*/ { // merge src properties into dest
|
7
|
+
var sources = Array.prototype.slice.call(arguments, 1);
|
8
|
+
for (var j = 0, len = sources.length, src; j < len; j++) {
|
9
|
+
src = sources[j] || {};
|
10
|
+
for (var i in src) {
|
11
|
+
if (src.hasOwnProperty(i)) {
|
12
|
+
dest[i] = src[i];
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
return dest;
|
17
|
+
},
|
18
|
+
|
19
|
+
bind: function (/*Function*/ fn, /*Object*/ obj) /*-> Object*/ {
|
20
|
+
return function () {
|
21
|
+
return fn.apply(obj, arguments);
|
22
|
+
};
|
23
|
+
},
|
24
|
+
|
25
|
+
stamp: (function () {
|
26
|
+
var lastId = 0, key = '_leaflet_id';
|
27
|
+
return function (/*Object*/ obj) {
|
28
|
+
obj[key] = obj[key] || ++lastId;
|
29
|
+
return obj[key];
|
30
|
+
};
|
31
|
+
}()),
|
32
|
+
|
33
|
+
requestAnimFrame: (function () {
|
34
|
+
function timeoutDefer(callback) {
|
35
|
+
window.setTimeout(callback, 1000 / 60);
|
36
|
+
}
|
37
|
+
|
38
|
+
var requestFn = window.requestAnimationFrame ||
|
39
|
+
window.webkitRequestAnimationFrame ||
|
40
|
+
window.mozRequestAnimationFrame ||
|
41
|
+
window.oRequestAnimationFrame ||
|
42
|
+
window.msRequestAnimationFrame ||
|
43
|
+
timeoutDefer;
|
44
|
+
|
45
|
+
return function (callback, context, immediate, contextEl) {
|
46
|
+
callback = context ? L.Util.bind(callback, context) : callback;
|
47
|
+
if (immediate && requestFn === timeoutDefer) {
|
48
|
+
callback();
|
49
|
+
} else {
|
50
|
+
requestFn(callback, contextEl);
|
51
|
+
}
|
52
|
+
};
|
53
|
+
}()),
|
54
|
+
|
55
|
+
limitExecByInterval: function (fn, time, context) {
|
56
|
+
var lock, execOnUnlock, args;
|
57
|
+
function exec() {
|
58
|
+
lock = false;
|
59
|
+
if (execOnUnlock) {
|
60
|
+
args.callee.apply(context, args);
|
61
|
+
execOnUnlock = false;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
return function () {
|
65
|
+
args = arguments;
|
66
|
+
if (!lock) {
|
67
|
+
lock = true;
|
68
|
+
setTimeout(exec, time);
|
69
|
+
fn.apply(context, args);
|
70
|
+
} else {
|
71
|
+
execOnUnlock = true;
|
72
|
+
}
|
73
|
+
};
|
74
|
+
},
|
75
|
+
|
76
|
+
falseFn: function () {
|
77
|
+
return false;
|
78
|
+
},
|
79
|
+
|
80
|
+
formatNum: function (num, digits) {
|
81
|
+
var pow = Math.pow(10, digits || 5);
|
82
|
+
return Math.round(num * pow) / pow;
|
83
|
+
},
|
84
|
+
|
85
|
+
setOptions: function (obj, options) {
|
86
|
+
obj.options = L.Util.extend({}, obj.options, options);
|
87
|
+
},
|
88
|
+
|
89
|
+
getParamString: function (obj) {
|
90
|
+
var params = [];
|
91
|
+
for (var i in obj) {
|
92
|
+
if (obj.hasOwnProperty(i)) {
|
93
|
+
params.push(i + '=' + obj[i]);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return '?' + params.join('&');
|
97
|
+
},
|
98
|
+
|
99
|
+
template: function (str, data) {
|
100
|
+
return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) {
|
101
|
+
var value = data[key];
|
102
|
+
if (!data.hasOwnProperty(key)) {
|
103
|
+
throw new Error('No value provided for variable ' + str);
|
104
|
+
}
|
105
|
+
return value;
|
106
|
+
});
|
107
|
+
}
|
108
|
+
};
|