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,43 @@
|
|
1
|
+
L.Util.extend(L.DomEvent, {
|
2
|
+
// inspired by Zepto touch code by Thomas Fuchs
|
3
|
+
addDoubleTapListener: function (obj, handler, id) {
|
4
|
+
var last,
|
5
|
+
doubleTap = false,
|
6
|
+
delay = 250,
|
7
|
+
touch,
|
8
|
+
pre = '_leaflet_',
|
9
|
+
touchstart = 'touchstart',
|
10
|
+
touchend = 'touchend';
|
11
|
+
|
12
|
+
function onTouchStart(e) {
|
13
|
+
if (e.touches.length !== 1) {
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
|
17
|
+
var now = Date.now(),
|
18
|
+
delta = now - (last || now);
|
19
|
+
|
20
|
+
touch = e.touches[0];
|
21
|
+
doubleTap = (delta > 0 && delta <= delay);
|
22
|
+
last = now;
|
23
|
+
}
|
24
|
+
function onTouchEnd(e) {
|
25
|
+
if (doubleTap) {
|
26
|
+
touch.type = 'dblclick';
|
27
|
+
handler(touch);
|
28
|
+
last = null;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
obj[pre + touchstart + id] = onTouchStart;
|
32
|
+
obj[pre + touchend + id] = onTouchEnd;
|
33
|
+
|
34
|
+
obj.addEventListener(touchstart, onTouchStart, false);
|
35
|
+
obj.addEventListener(touchend, onTouchEnd, false);
|
36
|
+
},
|
37
|
+
|
38
|
+
removeDoubleTapListener: function (obj, id) {
|
39
|
+
var pre = '_leaflet_';
|
40
|
+
obj.removeEventListener(obj, obj[pre + 'touchstart' + id], false);
|
41
|
+
obj.removeEventListener(obj, obj[pre + 'touchend' + id], false);
|
42
|
+
}
|
43
|
+
});
|
@@ -0,0 +1,154 @@
|
|
1
|
+
/*
|
2
|
+
* L.DomEvent contains functions for working with DOM events.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.DomEvent = {
|
6
|
+
/* inpired by John Resig, Dean Edwards and YUI addEvent implementations */
|
7
|
+
addListener: function (/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn, /*Object*/ context) {
|
8
|
+
var id = L.Util.stamp(fn),
|
9
|
+
key = '_leaflet_' + type + id;
|
10
|
+
|
11
|
+
if (obj[key]) {
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
|
15
|
+
var handler = function (e) {
|
16
|
+
return fn.call(context || obj, e || L.DomEvent._getEvent());
|
17
|
+
};
|
18
|
+
|
19
|
+
if (L.Browser.touch && (type === 'dblclick') && this.addDoubleTapListener) {
|
20
|
+
this.addDoubleTapListener(obj, handler, id);
|
21
|
+
} else if ('addEventListener' in obj) {
|
22
|
+
if (type === 'mousewheel') {
|
23
|
+
obj.addEventListener('DOMMouseScroll', handler, false);
|
24
|
+
obj.addEventListener(type, handler, false);
|
25
|
+
} else if ((type === 'mouseenter') || (type === 'mouseleave')) {
|
26
|
+
var originalHandler = handler,
|
27
|
+
newType = (type === 'mouseenter' ? 'mouseover' : 'mouseout');
|
28
|
+
handler = function (e) {
|
29
|
+
if (!L.DomEvent._checkMouse(obj, e)) {
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
return originalHandler(e);
|
33
|
+
};
|
34
|
+
obj.addEventListener(newType, handler, false);
|
35
|
+
} else {
|
36
|
+
obj.addEventListener(type, handler, false);
|
37
|
+
}
|
38
|
+
} else if ('attachEvent' in obj) {
|
39
|
+
obj.attachEvent("on" + type, handler);
|
40
|
+
}
|
41
|
+
|
42
|
+
obj[key] = handler;
|
43
|
+
},
|
44
|
+
|
45
|
+
removeListener: function (/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn) {
|
46
|
+
var id = L.Util.stamp(fn),
|
47
|
+
key = '_leaflet_' + type + id,
|
48
|
+
handler = obj[key];
|
49
|
+
|
50
|
+
if (!handler) {
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
|
54
|
+
if (L.Browser.touch && (type === 'dblclick') && this.removeDoubleTapListener) {
|
55
|
+
this.removeDoubleTapListener(obj, id);
|
56
|
+
} else if ('removeEventListener' in obj) {
|
57
|
+
if (type === 'mousewheel') {
|
58
|
+
obj.removeEventListener('DOMMouseScroll', handler, false);
|
59
|
+
obj.removeEventListener(type, handler, false);
|
60
|
+
} else if ((type === 'mouseenter') || (type === 'mouseleave')) {
|
61
|
+
obj.removeEventListener((type === 'mouseenter' ? 'mouseover' : 'mouseout'), handler, false);
|
62
|
+
} else {
|
63
|
+
obj.removeEventListener(type, handler, false);
|
64
|
+
}
|
65
|
+
} else if ('detachEvent' in obj) {
|
66
|
+
obj.detachEvent("on" + type, handler);
|
67
|
+
}
|
68
|
+
obj[key] = null;
|
69
|
+
},
|
70
|
+
|
71
|
+
_checkMouse: function (el, e) {
|
72
|
+
var related = e.relatedTarget;
|
73
|
+
|
74
|
+
if (!related) {
|
75
|
+
return true;
|
76
|
+
}
|
77
|
+
|
78
|
+
try {
|
79
|
+
while (related && (related !== el)) {
|
80
|
+
related = related.parentNode;
|
81
|
+
}
|
82
|
+
} catch (err) {
|
83
|
+
return false;
|
84
|
+
}
|
85
|
+
|
86
|
+
return (related !== el);
|
87
|
+
},
|
88
|
+
|
89
|
+
/*jshint noarg:false */ // evil magic for IE
|
90
|
+
_getEvent: function () {
|
91
|
+
var e = window.event;
|
92
|
+
if (!e) {
|
93
|
+
var caller = arguments.callee.caller;
|
94
|
+
while (caller) {
|
95
|
+
e = caller['arguments'][0];
|
96
|
+
if (e && window.Event === e.constructor) {
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
caller = caller.caller;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
return e;
|
103
|
+
},
|
104
|
+
/*jshint noarg:false */
|
105
|
+
|
106
|
+
stopPropagation: function (/*Event*/ e) {
|
107
|
+
if (e.stopPropagation) {
|
108
|
+
e.stopPropagation();
|
109
|
+
} else {
|
110
|
+
e.cancelBubble = true;
|
111
|
+
}
|
112
|
+
},
|
113
|
+
|
114
|
+
disableClickPropagation: function (/*HTMLElement*/ el) {
|
115
|
+
L.DomEvent.addListener(el, 'mousedown', L.DomEvent.stopPropagation);
|
116
|
+
L.DomEvent.addListener(el, 'click', L.DomEvent.stopPropagation);
|
117
|
+
L.DomEvent.addListener(el, 'dblclick', L.DomEvent.stopPropagation);
|
118
|
+
},
|
119
|
+
|
120
|
+
preventDefault: function (/*Event*/ e) {
|
121
|
+
if (e.preventDefault) {
|
122
|
+
e.preventDefault();
|
123
|
+
} else {
|
124
|
+
e.returnValue = false;
|
125
|
+
}
|
126
|
+
},
|
127
|
+
|
128
|
+
stop: function (e) {
|
129
|
+
L.DomEvent.preventDefault(e);
|
130
|
+
L.DomEvent.stopPropagation(e);
|
131
|
+
},
|
132
|
+
|
133
|
+
getMousePosition: function (e, container) {
|
134
|
+
var x = e.pageX ? e.pageX : e.clientX +
|
135
|
+
document.body.scrollLeft + document.documentElement.scrollLeft,
|
136
|
+
y = e.pageY ? e.pageY : e.clientY +
|
137
|
+
document.body.scrollTop + document.documentElement.scrollTop,
|
138
|
+
pos = new L.Point(x, y);
|
139
|
+
return (container ?
|
140
|
+
pos.subtract(L.DomUtil.getViewportOffset(container)) : pos);
|
141
|
+
},
|
142
|
+
|
143
|
+
getWheelDelta: function (e) {
|
144
|
+
var delta = 0;
|
145
|
+
if (e.wheelDelta) {
|
146
|
+
delta = e.wheelDelta / 120;
|
147
|
+
}
|
148
|
+
if (e.detail) {
|
149
|
+
delta = -e.detail / 3;
|
150
|
+
}
|
151
|
+
return delta;
|
152
|
+
}
|
153
|
+
};
|
154
|
+
|
@@ -0,0 +1,155 @@
|
|
1
|
+
/*
|
2
|
+
* L.DomUtil contains various utility functions for working with DOM
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.DomUtil = {
|
6
|
+
get: function (id) {
|
7
|
+
return (typeof id === 'string' ? document.getElementById(id) : id);
|
8
|
+
},
|
9
|
+
|
10
|
+
getStyle: function (el, style) {
|
11
|
+
var value = el.style[style];
|
12
|
+
if (!value && el.currentStyle) {
|
13
|
+
value = el.currentStyle[style];
|
14
|
+
}
|
15
|
+
if (!value || value === 'auto') {
|
16
|
+
var css = document.defaultView.getComputedStyle(el, null);
|
17
|
+
value = css ? css[style] : null;
|
18
|
+
}
|
19
|
+
return (value === 'auto' ? null : value);
|
20
|
+
},
|
21
|
+
|
22
|
+
getViewportOffset: function (element) {
|
23
|
+
var top = 0,
|
24
|
+
left = 0,
|
25
|
+
el = element,
|
26
|
+
docBody = document.body;
|
27
|
+
|
28
|
+
do {
|
29
|
+
top += el.offsetTop || 0;
|
30
|
+
left += el.offsetLeft || 0;
|
31
|
+
|
32
|
+
if (el.offsetParent === docBody &&
|
33
|
+
L.DomUtil.getStyle(el, 'position') === 'absolute') {
|
34
|
+
break;
|
35
|
+
}
|
36
|
+
el = el.offsetParent;
|
37
|
+
} while (el);
|
38
|
+
|
39
|
+
el = element;
|
40
|
+
|
41
|
+
do {
|
42
|
+
if (el === docBody) {
|
43
|
+
break;
|
44
|
+
}
|
45
|
+
|
46
|
+
top -= el.scrollTop || 0;
|
47
|
+
left -= el.scrollLeft || 0;
|
48
|
+
|
49
|
+
el = el.parentNode;
|
50
|
+
} while (el);
|
51
|
+
|
52
|
+
return new L.Point(left, top);
|
53
|
+
},
|
54
|
+
|
55
|
+
create: function (tagName, className, container) {
|
56
|
+
var el = document.createElement(tagName);
|
57
|
+
el.className = className;
|
58
|
+
if (container) {
|
59
|
+
container.appendChild(el);
|
60
|
+
}
|
61
|
+
return el;
|
62
|
+
},
|
63
|
+
|
64
|
+
disableTextSelection: function () {
|
65
|
+
if (document.selection && document.selection.empty) {
|
66
|
+
document.selection.empty();
|
67
|
+
}
|
68
|
+
if (!this._onselectstart) {
|
69
|
+
this._onselectstart = document.onselectstart;
|
70
|
+
document.onselectstart = L.Util.falseFn;
|
71
|
+
}
|
72
|
+
},
|
73
|
+
|
74
|
+
enableTextSelection: function () {
|
75
|
+
document.onselectstart = this._onselectstart;
|
76
|
+
this._onselectstart = null;
|
77
|
+
},
|
78
|
+
|
79
|
+
hasClass: function (el, name) {
|
80
|
+
return (el.className.length > 0) &&
|
81
|
+
new RegExp("(^|\\s)" + name + "(\\s|$)").test(el.className);
|
82
|
+
},
|
83
|
+
|
84
|
+
addClass: function (el, name) {
|
85
|
+
if (!L.DomUtil.hasClass(el, name)) {
|
86
|
+
el.className += (el.className ? ' ' : '') + name;
|
87
|
+
}
|
88
|
+
},
|
89
|
+
|
90
|
+
removeClass: function (el, name) {
|
91
|
+
el.className = el.className.replace(/(\S+)\s*/g, function (w, match) {
|
92
|
+
if (match === name) {
|
93
|
+
return '';
|
94
|
+
}
|
95
|
+
return w;
|
96
|
+
}).replace(/^\s+/, '');
|
97
|
+
},
|
98
|
+
|
99
|
+
setOpacity: function (el, value) {
|
100
|
+
if (L.Browser.ie) {
|
101
|
+
el.style.filter = 'alpha(opacity=' + Math.round(value * 100) + ')';
|
102
|
+
} else {
|
103
|
+
el.style.opacity = value;
|
104
|
+
}
|
105
|
+
},
|
106
|
+
|
107
|
+
//TODO refactor away this ugly translate/position mess
|
108
|
+
|
109
|
+
testProp: function (props) {
|
110
|
+
var style = document.documentElement.style;
|
111
|
+
|
112
|
+
for (var i = 0; i < props.length; i++) {
|
113
|
+
if (props[i] in style) {
|
114
|
+
return props[i];
|
115
|
+
}
|
116
|
+
}
|
117
|
+
return false;
|
118
|
+
},
|
119
|
+
|
120
|
+
getTranslateString: function (point) {
|
121
|
+
return L.DomUtil.TRANSLATE_OPEN +
|
122
|
+
point.x + 'px,' + point.y + 'px' +
|
123
|
+
L.DomUtil.TRANSLATE_CLOSE;
|
124
|
+
},
|
125
|
+
|
126
|
+
getScaleString: function (scale, origin) {
|
127
|
+
var preTranslateStr = L.DomUtil.getTranslateString(origin),
|
128
|
+
scaleStr = ' scale(' + scale + ') ',
|
129
|
+
postTranslateStr = L.DomUtil.getTranslateString(origin.multiplyBy(-1));
|
130
|
+
|
131
|
+
return preTranslateStr + scaleStr + postTranslateStr;
|
132
|
+
},
|
133
|
+
|
134
|
+
setPosition: function (el, point) {
|
135
|
+
el._leaflet_pos = point;
|
136
|
+
if (L.Browser.webkit) {
|
137
|
+
el.style[L.DomUtil.TRANSFORM] = L.DomUtil.getTranslateString(point);
|
138
|
+
} else {
|
139
|
+
el.style.left = point.x + 'px';
|
140
|
+
el.style.top = point.y + 'px';
|
141
|
+
}
|
142
|
+
},
|
143
|
+
|
144
|
+
getPosition: function (el) {
|
145
|
+
return el._leaflet_pos;
|
146
|
+
}
|
147
|
+
};
|
148
|
+
|
149
|
+
L.Util.extend(L.DomUtil, {
|
150
|
+
TRANSITION: L.DomUtil.testProp(['transition', 'webkitTransition', 'OTransition', 'MozTransition', 'msTransition']),
|
151
|
+
TRANSFORM: L.DomUtil.testProp(['transformProperty', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']),
|
152
|
+
|
153
|
+
TRANSLATE_OPEN: 'translate' + (L.Browser.webkit3d ? '3d(' : '('),
|
154
|
+
TRANSLATE_CLOSE: L.Browser.webkit3d ? ',0)' : ')'
|
155
|
+
});
|
@@ -0,0 +1,147 @@
|
|
1
|
+
/*
|
2
|
+
* L.Draggable allows you to add dragging capabilities to any element. Supports mobile devices too.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Draggable = L.Class.extend({
|
6
|
+
includes: L.Mixin.Events,
|
7
|
+
|
8
|
+
statics: {
|
9
|
+
START: L.Browser.touch ? 'touchstart' : 'mousedown',
|
10
|
+
END: L.Browser.touch ? 'touchend' : 'mouseup',
|
11
|
+
MOVE: L.Browser.touch ? 'touchmove' : 'mousemove',
|
12
|
+
TAP_TOLERANCE: 15
|
13
|
+
},
|
14
|
+
|
15
|
+
initialize: function (element, dragStartTarget) {
|
16
|
+
this._element = element;
|
17
|
+
this._dragStartTarget = dragStartTarget || element;
|
18
|
+
},
|
19
|
+
|
20
|
+
enable: function () {
|
21
|
+
if (this._enabled) {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
L.DomEvent.addListener(this._dragStartTarget, L.Draggable.START, this._onDown, this);
|
25
|
+
this._enabled = true;
|
26
|
+
},
|
27
|
+
|
28
|
+
disable: function () {
|
29
|
+
if (!this._enabled) {
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
L.DomEvent.removeListener(this._dragStartTarget, L.Draggable.START, this._onDown);
|
33
|
+
this._enabled = false;
|
34
|
+
},
|
35
|
+
|
36
|
+
_onDown: function (e) {
|
37
|
+
if ((!L.Browser.touch && e.shiftKey) || ((e.which !== 1) && (e.button !== 1) && !e.touches)) {
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
if (e.touches && e.touches.length > 1) {
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
|
45
|
+
var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e),
|
46
|
+
el = first.target;
|
47
|
+
|
48
|
+
L.DomEvent.preventDefault(e);
|
49
|
+
|
50
|
+
if (L.Browser.touch && el.tagName.toLowerCase() === 'a') {
|
51
|
+
el.className += ' leaflet-active';
|
52
|
+
}
|
53
|
+
|
54
|
+
this._moved = false;
|
55
|
+
if (this._moving) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
|
59
|
+
if (!L.Browser.touch) {
|
60
|
+
L.DomUtil.disableTextSelection();
|
61
|
+
this._setMovingCursor();
|
62
|
+
}
|
63
|
+
|
64
|
+
this._startPos = this._newPos = L.DomUtil.getPosition(this._element);
|
65
|
+
this._startPoint = new L.Point(first.clientX, first.clientY);
|
66
|
+
|
67
|
+
L.DomEvent.addListener(document, L.Draggable.MOVE, this._onMove, this);
|
68
|
+
L.DomEvent.addListener(document, L.Draggable.END, this._onUp, this);
|
69
|
+
},
|
70
|
+
|
71
|
+
_onMove: function (e) {
|
72
|
+
if (e.touches && e.touches.length > 1) {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
|
76
|
+
L.DomEvent.preventDefault(e);
|
77
|
+
|
78
|
+
var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e);
|
79
|
+
|
80
|
+
if (!this._moved) {
|
81
|
+
this.fire('dragstart');
|
82
|
+
this._moved = true;
|
83
|
+
}
|
84
|
+
this._moving = true;
|
85
|
+
|
86
|
+
var newPoint = new L.Point(first.clientX, first.clientY);
|
87
|
+
this._newPos = this._startPos.add(newPoint).subtract(this._startPoint);
|
88
|
+
|
89
|
+
L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget);
|
90
|
+
},
|
91
|
+
|
92
|
+
_updatePosition: function () {
|
93
|
+
this.fire('predrag');
|
94
|
+
L.DomUtil.setPosition(this._element, this._newPos);
|
95
|
+
this.fire('drag');
|
96
|
+
},
|
97
|
+
|
98
|
+
_onUp: function (e) {
|
99
|
+
if (e.changedTouches) {
|
100
|
+
var first = e.changedTouches[0],
|
101
|
+
el = first.target,
|
102
|
+
dist = (this._newPos && this._newPos.distanceTo(this._startPos)) || 0;
|
103
|
+
|
104
|
+
if (el.tagName.toLowerCase() === 'a') {
|
105
|
+
el.className = el.className.replace(' leaflet-active', '');
|
106
|
+
}
|
107
|
+
|
108
|
+
if (dist < L.Draggable.TAP_TOLERANCE) {
|
109
|
+
this._simulateEvent('click', first);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
if (!L.Browser.touch) {
|
114
|
+
L.DomUtil.enableTextSelection();
|
115
|
+
this._restoreCursor();
|
116
|
+
}
|
117
|
+
|
118
|
+
L.DomEvent.removeListener(document, L.Draggable.MOVE, this._onMove);
|
119
|
+
L.DomEvent.removeListener(document, L.Draggable.END, this._onUp);
|
120
|
+
|
121
|
+
if (this._moved) {
|
122
|
+
this.fire('dragend');
|
123
|
+
}
|
124
|
+
this._moving = false;
|
125
|
+
},
|
126
|
+
|
127
|
+
_setMovingCursor: function () {
|
128
|
+
this._bodyCursor = document.body.style.cursor;
|
129
|
+
document.body.style.cursor = 'move';
|
130
|
+
},
|
131
|
+
|
132
|
+
_restoreCursor: function () {
|
133
|
+
document.body.style.cursor = this._bodyCursor;
|
134
|
+
},
|
135
|
+
|
136
|
+
_simulateEvent: function (type, e) {
|
137
|
+
var simulatedEvent = document.createEvent('MouseEvents');
|
138
|
+
|
139
|
+
simulatedEvent.initMouseEvent(
|
140
|
+
type, true, true, window, 1,
|
141
|
+
e.screenX, e.screenY,
|
142
|
+
e.clientX, e.clientY,
|
143
|
+
false, false, false, false, 0, null);
|
144
|
+
|
145
|
+
e.target.dispatchEvent(simulatedEvent);
|
146
|
+
}
|
147
|
+
});
|