leaflet-js 0.6.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG.rdoc +32 -0
- data/LICENSE +21 -0
- data/README.rdoc +54 -0
- data/Rakefile +15 -0
- data/leaflet-js.gemspec +28 -0
- data/lib/leaflet-js.rb +10 -0
- data/lib/leaflet.draw/BREAKINGCHANGES.md +54 -0
- data/lib/leaflet.draw/CHANGELOG.md +73 -0
- data/lib/leaflet.draw/Jakefile.js +26 -0
- data/lib/leaflet.draw/MIT-LICENCE.txt +20 -0
- data/lib/leaflet.draw/README.md +364 -0
- data/lib/leaflet.draw/TODO.md +62 -0
- data/lib/leaflet.draw/build/build.html +243 -0
- data/lib/leaflet.draw/build/build.js +189 -0
- data/lib/leaflet.draw/build/deps.js +75 -0
- data/lib/leaflet.draw/build/hintrc.js +47 -0
- data/lib/leaflet.draw/build/leaflet.draw-include.js +42 -0
- data/lib/leaflet.draw/dist/images/spritesheet.png +0 -0
- data/lib/leaflet.draw/dist/leaflet.draw-src.js +2429 -0
- data/lib/leaflet.draw/dist/leaflet.draw.css +212 -0
- data/lib/leaflet.draw/dist/leaflet.draw.ie.css +44 -0
- data/lib/leaflet.draw/dist/leaflet.draw.js +10 -0
- data/lib/leaflet.draw/examples/basic.html +106 -0
- data/lib/leaflet.draw/examples/edithandlers.html +67 -0
- data/lib/leaflet.draw/examples/libs/images/layers.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-icon.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-icon@2x.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-shadow.png +0 -0
- data/lib/leaflet.draw/examples/libs/leaflet-src.js +8587 -0
- data/lib/leaflet.draw/examples/libs/leaflet.css +459 -0
- data/lib/leaflet.draw/examples/libs/leaflet.ie.css +51 -0
- data/lib/leaflet.draw/package.json +37 -0
- data/lib/leaflet.draw/spec/after.js +2 -0
- data/lib/leaflet.draw/spec/before.js +3 -0
- data/lib/leaflet.draw/spec/expect.js +1253 -0
- data/lib/leaflet.draw/spec/happen.js +93 -0
- data/lib/leaflet.draw/spec/index.html +36 -0
- data/lib/leaflet.draw/spec/karma.conf.js +69 -0
- data/lib/leaflet.draw/spec/sinon.js +4223 -0
- data/lib/leaflet.draw/spec/suites/DrawControlSpec.js +15 -0
- data/lib/leaflet.draw/spec/suites/SpecHelper.js +26 -0
- data/lib/leaflet.draw/src/Control.Draw.js +101 -0
- data/lib/leaflet.draw/src/Leaflet.draw.js +5 -0
- data/lib/leaflet.draw/src/Toolbar.js +187 -0
- data/lib/leaflet.draw/src/Tooltip.js +52 -0
- data/lib/leaflet.draw/src/copyright.js +8 -0
- data/lib/leaflet.draw/src/draw/DrawToolbar.js +107 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Circle.js +59 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Feature.js +74 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Marker.js +97 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Polygon.js +79 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Polyline.js +360 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Rectangle.js +41 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.SimpleShape.js +67 -0
- data/lib/leaflet.draw/src/edit/EditToolbar.js +93 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.Circle.js +63 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.Poly.js +267 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.Rectangle.js +117 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.SimpleShape.js +138 -0
- data/lib/leaflet.draw/src/edit/handler/EditToolbar.Delete.js +109 -0
- data/lib/leaflet.draw/src/edit/handler/EditToolbar.Edit.js +233 -0
- data/lib/leaflet.draw/src/ext/LatLngUtil.js +18 -0
- data/lib/leaflet.draw/src/ext/LineUtil.Intersect.js +15 -0
- data/lib/leaflet.draw/src/ext/Polygon.Intersect.js +27 -0
- data/lib/leaflet.draw/src/ext/Polyline.Intersect.js +85 -0
- data/lib/leaflet.label/CHANGELOG.md +35 -0
- data/lib/leaflet.label/Jakefile.js +21 -0
- data/lib/leaflet.label/MIT-LICENCE.txt +20 -0
- data/lib/leaflet.label/README.md +86 -0
- data/lib/leaflet.label/build/build.js +155 -0
- data/lib/leaflet.label/build/deps.js +24 -0
- data/lib/leaflet.label/build/hint.js +30 -0
- data/lib/leaflet.label/build/hintrc.js +47 -0
- data/lib/leaflet.label/dist/images/death.png +0 -0
- data/lib/leaflet.label/dist/leaflet.label-src.js +359 -0
- data/lib/leaflet.label/dist/leaflet.label.css +33 -0
- data/lib/leaflet.label/dist/leaflet.label.js +9 -0
- data/lib/leaflet.label/example/label.html +82 -0
- data/lib/leaflet.label/libs/leaflet/images/layers.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-icon.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-icon@2x.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-shadow.png +0 -0
- data/lib/leaflet.label/libs/leaflet/leaflet-src.js +8587 -0
- data/lib/leaflet.label/libs/leaflet/leaflet.css +459 -0
- data/lib/leaflet.label/libs/leaflet/leaflet.ie.css +51 -0
- data/lib/leaflet.label/libs/leaflet/leaflet.js +8 -0
- data/lib/leaflet.label/src/FeatureGroup.Label.js +20 -0
- data/lib/leaflet.label/src/Label.js +123 -0
- data/lib/leaflet.label/src/Leaflet.label.js +5 -0
- data/lib/leaflet.label/src/Map.Label.js +7 -0
- data/lib/leaflet.label/src/Marker.Label.js +160 -0
- data/lib/leaflet.label/src/Path.Label.js +55 -0
- data/lib/leaflet.label/src/copyright.js +8 -0
- data/lib/leaflet/CHANGELOG.md +637 -0
- data/lib/leaflet/CONTRIBUTING.md +155 -0
- data/lib/leaflet/Jakefile.js +26 -0
- data/lib/leaflet/LICENSE +23 -0
- data/lib/leaflet/README.md +30 -0
- data/lib/leaflet/build/build.html +243 -0
- data/lib/leaflet/build/build.js +193 -0
- data/lib/leaflet/build/deps.js +256 -0
- data/lib/leaflet/build/hintrc.js +37 -0
- data/lib/leaflet/debug/css/mobile.css +6 -0
- data/lib/leaflet/debug/css/screen.css +5 -0
- data/lib/leaflet/debug/hacks/jitter.html +43 -0
- data/lib/leaflet/debug/leaflet-include.js +59 -0
- data/lib/leaflet/debug/map/canvas.html +47 -0
- data/lib/leaflet/debug/map/controls.html +50 -0
- data/lib/leaflet/debug/map/geolocation.html +35 -0
- data/lib/leaflet/debug/map/image-overlay.html +44 -0
- data/lib/leaflet/debug/map/map-mobile.html +35 -0
- data/lib/leaflet/debug/map/map.html +60 -0
- data/lib/leaflet/debug/map/max-bounds.html +37 -0
- data/lib/leaflet/debug/map/scroll.html +36 -0
- data/lib/leaflet/debug/map/simple-proj.html +45 -0
- data/lib/leaflet/debug/map/wms-marble.html +31 -0
- data/lib/leaflet/debug/map/wms.html +41 -0
- data/lib/leaflet/debug/map/zoomlevels.html +46 -0
- data/lib/leaflet/debug/tests/add_remove_layers.html +88 -0
- data/lib/leaflet/debug/tests/bringtoback.html +38 -0
- data/lib/leaflet/debug/tests/click_on_canvas.html +59 -0
- data/lib/leaflet/debug/tests/click_on_canvas_broken.html +49 -0
- data/lib/leaflet/debug/tests/opacity.html +57 -0
- data/lib/leaflet/debug/tests/remove_while_dragging.html +29 -0
- data/lib/leaflet/debug/tests/removetilewhilepan.html +42 -0
- data/lib/leaflet/debug/tests/reuse_popups.html +41 -0
- data/lib/leaflet/debug/tests/svg_clicks.html +55 -0
- data/lib/leaflet/debug/vector/bounds-extend.html +89 -0
- data/lib/leaflet/debug/vector/feature-group-bounds.html +91 -0
- data/lib/leaflet/debug/vector/geojson-sample.js +53 -0
- data/lib/leaflet/debug/vector/geojson.html +174 -0
- data/lib/leaflet/debug/vector/rectangle.html +54 -0
- data/lib/leaflet/debug/vector/route.js +1 -0
- data/lib/leaflet/debug/vector/touchzoomemu.html +195 -0
- data/lib/leaflet/debug/vector/us-states.js +54 -0
- data/lib/leaflet/debug/vector/vector-bounds.html +70 -0
- data/lib/leaflet/debug/vector/vector-canvas.html +93 -0
- data/lib/leaflet/debug/vector/vector-mobile.html +39 -0
- data/lib/leaflet/debug/vector/vector-simple.html +49 -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-icon-2x.png +0 -0
- data/lib/leaflet/dist/images/marker-icon.png +0 -0
- data/lib/leaflet/dist/images/marker-shadow.png +0 -0
- data/lib/leaflet/dist/leaflet-src.js +8579 -0
- data/lib/leaflet/dist/leaflet.css +459 -0
- data/lib/leaflet/dist/leaflet.ie.css +51 -0
- data/lib/leaflet/dist/leaflet.js +8 -0
- data/lib/leaflet/package.json +22 -0
- data/lib/leaflet/spec/after.js +2 -0
- data/lib/leaflet/spec/before.js +3 -0
- data/lib/leaflet/spec/expect.js +1253 -0
- data/lib/leaflet/spec/happen.js +93 -0
- data/lib/leaflet/spec/index.html +78 -0
- data/lib/leaflet/spec/karma.conf.js +64 -0
- data/lib/leaflet/spec/sinon.js +4223 -0
- data/lib/leaflet/spec/suites/LeafletSpec.js +13 -0
- data/lib/leaflet/spec/suites/SpecHelper.js +26 -0
- data/lib/leaflet/spec/suites/control/Control.AttributionSpec.js +68 -0
- data/lib/leaflet/spec/suites/control/Control.LayersSpec.js +67 -0
- data/lib/leaflet/spec/suites/control/Control.ScaleSpec.js +6 -0
- data/lib/leaflet/spec/suites/core/ClassSpec.js +156 -0
- data/lib/leaflet/spec/suites/core/EventsSpec.js +336 -0
- data/lib/leaflet/spec/suites/core/UtilSpec.js +212 -0
- data/lib/leaflet/spec/suites/dom/DomEventSpec.js +102 -0
- data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +89 -0
- data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +136 -0
- data/lib/leaflet/spec/suites/geo/LatLngSpec.js +118 -0
- data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +47 -0
- data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +87 -0
- data/lib/leaflet/spec/suites/geometry/LineUtilSpec.js +75 -0
- data/lib/leaflet/spec/suites/geometry/PointSpec.js +104 -0
- data/lib/leaflet/spec/suites/geometry/PolyUtilSpec.js +27 -0
- data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +31 -0
- data/lib/leaflet/spec/suites/layer/FeatureGroupSpec.js +36 -0
- data/lib/leaflet/spec/suites/layer/GeoJSONSpec.js +86 -0
- data/lib/leaflet/spec/suites/layer/LayerGroupSpec.js +58 -0
- data/lib/leaflet/spec/suites/layer/PopupSpec.js +59 -0
- data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +87 -0
- data/lib/leaflet/spec/suites/layer/vector/CircleMarkerSpec.js +53 -0
- data/lib/leaflet/spec/suites/layer/vector/CircleSpec.js +17 -0
- data/lib/leaflet/spec/suites/layer/vector/PolygonSpec.js +55 -0
- data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +35 -0
- data/lib/leaflet/spec/suites/layer/vector/PolylineSpec.js +55 -0
- data/lib/leaflet/spec/suites/map/MapSpec.js +244 -0
- data/lib/leaflet/src/Leaflet.js +23 -0
- data/lib/leaflet/src/control/Control.Attribution.js +115 -0
- data/lib/leaflet/src/control/Control.Layers.js +243 -0
- data/lib/leaflet/src/control/Control.Scale.js +112 -0
- data/lib/leaflet/src/control/Control.Zoom.js +86 -0
- data/lib/leaflet/src/control/Control.js +107 -0
- data/lib/leaflet/src/copyright.js +4 -0
- data/lib/leaflet/src/core/Browser.js +96 -0
- data/lib/leaflet/src/core/Class.js +106 -0
- data/lib/leaflet/src/core/Events.js +174 -0
- data/lib/leaflet/src/core/Handler.js +28 -0
- data/lib/leaflet/src/core/Util.js +182 -0
- data/lib/leaflet/src/dom/DomEvent.DoubleTap.js +103 -0
- data/lib/leaflet/src/dom/DomEvent.MsTouch.js +146 -0
- data/lib/leaflet/src/dom/DomEvent.js +211 -0
- data/lib/leaflet/src/dom/DomUtil.js +239 -0
- data/lib/leaflet/src/dom/Draggable.js +198 -0
- data/lib/leaflet/src/dom/PosAnimation.Timer.js +67 -0
- data/lib/leaflet/src/dom/PosAnimation.js +83 -0
- data/lib/leaflet/src/geo/LatLng.js +88 -0
- data/lib/leaflet/src/geo/LatLngBounds.js +153 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3395.js +14 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3857.js +21 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG4326.js +10 -0
- data/lib/leaflet/src/geo/crs/CRS.Simple.js +12 -0
- data/lib/leaflet/src/geo/crs/CRS.js +27 -0
- data/lib/leaflet/src/geo/projection/Projection.LonLat.js +13 -0
- data/lib/leaflet/src/geo/projection/Projection.Mercator.js +56 -0
- data/lib/leaflet/src/geo/projection/Projection.SphericalMercator.js +27 -0
- data/lib/leaflet/src/geo/projection/Projection.js +5 -0
- data/lib/leaflet/src/geometry/Bounds.js +95 -0
- data/lib/leaflet/src/geometry/LineUtil.js +202 -0
- data/lib/leaflet/src/geometry/Point.js +119 -0
- data/lib/leaflet/src/geometry/PolyUtil.js +55 -0
- data/lib/leaflet/src/geometry/Transformation.js +31 -0
- data/lib/leaflet/src/images/marker.svg +1 -0
- data/lib/leaflet/src/layer/FeatureGroup.js +81 -0
- data/lib/leaflet/src/layer/GeoJSON.js +245 -0
- data/lib/leaflet/src/layer/ImageOverlay.js +132 -0
- data/lib/leaflet/src/layer/LayerGroup.js +110 -0
- data/lib/leaflet/src/layer/Popup.js +316 -0
- data/lib/leaflet/src/layer/marker/DivIcon.js +43 -0
- data/lib/leaflet/src/layer/marker/Icon.Default.js +51 -0
- data/lib/leaflet/src/layer/marker/Icon.js +101 -0
- data/lib/leaflet/src/layer/marker/Marker.Drag.js +66 -0
- data/lib/leaflet/src/layer/marker/Marker.Popup.js +72 -0
- data/lib/leaflet/src/layer/marker/Marker.js +275 -0
- data/lib/leaflet/src/layer/tile/TileLayer.Anim.js +117 -0
- data/lib/leaflet/src/layer/tile/TileLayer.Canvas.js +60 -0
- data/lib/leaflet/src/layer/tile/TileLayer.WMS.js +83 -0
- data/lib/leaflet/src/layer/tile/TileLayer.js +578 -0
- data/lib/leaflet/src/layer/vector/Circle.js +98 -0
- data/lib/leaflet/src/layer/vector/CircleMarker.js +33 -0
- data/lib/leaflet/src/layer/vector/MultiPoly.js +47 -0
- data/lib/leaflet/src/layer/vector/Path.Popup.js +65 -0
- data/lib/leaflet/src/layer/vector/Path.SVG.js +219 -0
- data/lib/leaflet/src/layer/vector/Path.VML.js +125 -0
- data/lib/leaflet/src/layer/vector/Path.js +115 -0
- data/lib/leaflet/src/layer/vector/Polygon.js +81 -0
- data/lib/leaflet/src/layer/vector/Polyline.js +164 -0
- data/lib/leaflet/src/layer/vector/Rectangle.js +27 -0
- data/lib/leaflet/src/layer/vector/canvas/Circle.Canvas.js +18 -0
- data/lib/leaflet/src/layer/vector/canvas/Path.Canvas.js +196 -0
- data/lib/leaflet/src/layer/vector/canvas/Polygon.Canvas.js +37 -0
- data/lib/leaflet/src/layer/vector/canvas/Polyline.Canvas.js +30 -0
- data/lib/leaflet/src/map/Map.js +743 -0
- data/lib/leaflet/src/map/anim/Map.PanAnimation.js +88 -0
- data/lib/leaflet/src/map/anim/Map.ZoomAnimation.js +90 -0
- data/lib/leaflet/src/map/ext/Map.Geolocation.js +91 -0
- data/lib/leaflet/src/map/handler/Map.BoxZoom.js +104 -0
- data/lib/leaflet/src/map/handler/Map.DoubleClickZoom.js +23 -0
- data/lib/leaflet/src/map/handler/Map.Drag.js +146 -0
- data/lib/leaflet/src/map/handler/Map.Keyboard.js +147 -0
- data/lib/leaflet/src/map/handler/Map.ScrollWheelZoom.js +56 -0
- data/lib/leaflet/src/map/handler/Map.TouchZoom.js +121 -0
- data/vendor/assets/images/layers.png +0 -0
- data/vendor/assets/images/marker-icon-2x.png +0 -0
- data/vendor/assets/images/marker-icon.png +0 -0
- data/vendor/assets/images/marker-shadow.png +0 -0
- data/vendor/assets/images/spritesheet.png +0 -0
- data/vendor/assets/javascripts/leaflet.draw.js +39 -0
- data/vendor/assets/javascripts/leaflet.js +145 -0
- data/vendor/assets/javascripts/leaflet.label.js +9 -0
- data/vendor/assets/stylesheets/leaflet.css.erb +459 -0
- data/vendor/assets/stylesheets/leaflet.draw.css.erb +212 -0
- data/vendor/assets/stylesheets/leaflet.draw.ie.css +44 -0
- data/vendor/assets/stylesheets/leaflet.ie.css +51 -0
- data/vendor/assets/stylesheets/leaflet.label.css +33 -0
- metadata +317 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
describe("Control.Draw", function(){
|
2
|
+
var map, control, container;
|
3
|
+
|
4
|
+
beforeEach(function(){
|
5
|
+
map = L.map(document.createElement('div'));
|
6
|
+
control = new L.Control.Draw({
|
7
|
+
|
8
|
+
}).addTo(map);
|
9
|
+
container = control.getContainer();
|
10
|
+
});
|
11
|
+
|
12
|
+
it("exists", function() {
|
13
|
+
expect(container.innerHTML).to.be.ok();
|
14
|
+
});
|
15
|
+
});
|
@@ -0,0 +1,26 @@
|
|
1
|
+
function noSpecs() {
|
2
|
+
xit('has no specs');
|
3
|
+
}
|
4
|
+
|
5
|
+
if (!Array.prototype.map) {
|
6
|
+
Array.prototype.map = function(fun /*, thisp */) {
|
7
|
+
"use strict";
|
8
|
+
|
9
|
+
if (this === void 0 || this === null)
|
10
|
+
throw new TypeError();
|
11
|
+
|
12
|
+
var t = Object(this);
|
13
|
+
var len = t.length >>> 0;
|
14
|
+
if (typeof fun !== "function")
|
15
|
+
throw new TypeError();
|
16
|
+
|
17
|
+
var res = new Array(len);
|
18
|
+
var thisp = arguments[1];
|
19
|
+
for (var i = 0; i < len; i++) {
|
20
|
+
if (i in t)
|
21
|
+
res[i] = fun.call(thisp, t[i], i, t);
|
22
|
+
}
|
23
|
+
|
24
|
+
return res;
|
25
|
+
};
|
26
|
+
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
L.Control.Draw = L.Control.extend({
|
2
|
+
|
3
|
+
options: {
|
4
|
+
position: 'topleft',
|
5
|
+
draw: {},
|
6
|
+
edit: false
|
7
|
+
},
|
8
|
+
|
9
|
+
initialize: function (options) {
|
10
|
+
if (L.version <= "0.5.1") {
|
11
|
+
throw new Error('Leaflet.draw 0.2.0+ requires Leaflet 0.6.0+. Download latest from https://github.com/Leaflet/Leaflet/');
|
12
|
+
}
|
13
|
+
|
14
|
+
L.Control.prototype.initialize.call(this, options);
|
15
|
+
|
16
|
+
var id, toolbar;
|
17
|
+
|
18
|
+
this._toolbars = {};
|
19
|
+
|
20
|
+
// Initialize toolbars
|
21
|
+
if (L.DrawToolbar && this.options.draw) {
|
22
|
+
toolbar = new L.DrawToolbar(this.options.draw);
|
23
|
+
id = L.stamp(toolbar);
|
24
|
+
this._toolbars[id] = toolbar;
|
25
|
+
|
26
|
+
// Listen for when toolbar is enabled
|
27
|
+
this._toolbars[id].on('enable', this._toolbarEnabled, this);
|
28
|
+
}
|
29
|
+
|
30
|
+
if (L.EditToolbar && this.options.edit) {
|
31
|
+
toolbar = new L.EditToolbar(this.options.edit);
|
32
|
+
id = L.stamp(toolbar);
|
33
|
+
this._toolbars[id] = toolbar;
|
34
|
+
|
35
|
+
// Listen for when toolbar is enabled
|
36
|
+
this._toolbars[id].on('enable', this._toolbarEnabled, this);
|
37
|
+
}
|
38
|
+
},
|
39
|
+
|
40
|
+
onAdd: function (map) {
|
41
|
+
var container = L.DomUtil.create('div', 'leaflet-draw'),
|
42
|
+
addedTopClass = false,
|
43
|
+
topClassName = 'leaflet-draw-toolbar-top',
|
44
|
+
toolbarContainer;
|
45
|
+
|
46
|
+
for (var toolbarId in this._toolbars) {
|
47
|
+
if (this._toolbars.hasOwnProperty(toolbarId)) {
|
48
|
+
toolbarContainer = this._toolbars[toolbarId].addToolbar(map);
|
49
|
+
|
50
|
+
// Add class to the first toolbar to remove the margin
|
51
|
+
if (!addedTopClass) {
|
52
|
+
if (!L.DomUtil.hasClass(toolbarContainer, topClassName)) {
|
53
|
+
L.DomUtil.addClass(toolbarContainer.childNodes[0], topClassName);
|
54
|
+
}
|
55
|
+
addedTopClass = true;
|
56
|
+
}
|
57
|
+
|
58
|
+
container.appendChild(toolbarContainer);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
return container;
|
63
|
+
},
|
64
|
+
|
65
|
+
onRemove: function () {
|
66
|
+
for (var toolbarId in this._toolbars) {
|
67
|
+
if (this._toolbars.hasOwnProperty(toolbarId)) {
|
68
|
+
this._toolbars[toolbarId].removeToolbar();
|
69
|
+
}
|
70
|
+
}
|
71
|
+
},
|
72
|
+
|
73
|
+
setDrawingOptions: function (options) {
|
74
|
+
for (var toolbarId in this._toolbars) {
|
75
|
+
if (this._toolbars[toolbarId] instanceof L.DrawToolbar) {
|
76
|
+
this._toolbars[toolbarId].setOptions(options);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
},
|
80
|
+
|
81
|
+
_toolbarEnabled: function (e) {
|
82
|
+
var id = '' + L.stamp(e.target);
|
83
|
+
|
84
|
+
for (var toolbarId in this._toolbars) {
|
85
|
+
if (this._toolbars.hasOwnProperty(toolbarId) && toolbarId !== id) {
|
86
|
+
this._toolbars[toolbarId].disable();
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
});
|
91
|
+
|
92
|
+
L.Map.mergeOptions({
|
93
|
+
drawControl: false
|
94
|
+
});
|
95
|
+
|
96
|
+
L.Map.addInitHook(function () {
|
97
|
+
if (this.options.drawControl) {
|
98
|
+
this.drawControl = new L.Control.Draw();
|
99
|
+
this.addControl(this.drawControl);
|
100
|
+
}
|
101
|
+
});
|
@@ -0,0 +1,187 @@
|
|
1
|
+
L.Toolbar = L.Class.extend({
|
2
|
+
includes: [L.Mixin.Events],
|
3
|
+
|
4
|
+
initialize: function (options) {
|
5
|
+
L.setOptions(this, options);
|
6
|
+
|
7
|
+
this._modes = {};
|
8
|
+
this._actionButtons = [];
|
9
|
+
this._activeMode = null;
|
10
|
+
},
|
11
|
+
|
12
|
+
enabled: function () {
|
13
|
+
return this._activeMode !== null;
|
14
|
+
},
|
15
|
+
|
16
|
+
disable: function () {
|
17
|
+
if (!this.enabled()) { return; }
|
18
|
+
|
19
|
+
this._activeMode.handler.disable();
|
20
|
+
},
|
21
|
+
|
22
|
+
removeToolbar: function () {
|
23
|
+
// Dispose each handler
|
24
|
+
for (var handlerId in this._modes) {
|
25
|
+
if (this._modes.hasOwnProperty(handlerId)) {
|
26
|
+
// Unbind handler button
|
27
|
+
this._disposeButton(this._modes[handlerId].button, this._modes[handlerId].handler.enable);
|
28
|
+
|
29
|
+
// Make sure is disabled
|
30
|
+
this._modes[handlerId].handler.disable();
|
31
|
+
|
32
|
+
// Unbind handler
|
33
|
+
this._modes[handlerId].handler
|
34
|
+
.off('enabled', this._handlerActivated, this)
|
35
|
+
.off('disabled', this._handlerDeactivated, this);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
this._modes = {};
|
39
|
+
|
40
|
+
// Dispose the actions toolbar
|
41
|
+
for (var i = 0, l = this._actionButtons.length; i < l; i++) {
|
42
|
+
this._disposeButton(this._actionButtons[i].button, this._actionButtons[i].callback);
|
43
|
+
}
|
44
|
+
this._actionButtons = [];
|
45
|
+
this._actionsContainer = null;
|
46
|
+
},
|
47
|
+
|
48
|
+
_initModeHandler: function (handler, container, buttonIndex, classNamePredix) {
|
49
|
+
var type = handler.type;
|
50
|
+
|
51
|
+
this._modes[type] = {};
|
52
|
+
|
53
|
+
this._modes[type].handler = handler;
|
54
|
+
|
55
|
+
this._modes[type].button = this._createButton({
|
56
|
+
title: this.options[type].title,
|
57
|
+
className: classNamePredix + '-' + type,
|
58
|
+
container: container,
|
59
|
+
callback: this._modes[type].handler.enable,
|
60
|
+
context: this._modes[type].handler
|
61
|
+
});
|
62
|
+
|
63
|
+
this._modes[type].buttonIndex = buttonIndex;
|
64
|
+
|
65
|
+
this._modes[type].handler
|
66
|
+
.on('enabled', this._handlerActivated, this)
|
67
|
+
.on('disabled', this._handlerDeactivated, this);
|
68
|
+
},
|
69
|
+
|
70
|
+
_createButton: function (options) {
|
71
|
+
var link = L.DomUtil.create('a', options.className || '', options.container);
|
72
|
+
link.href = '#';
|
73
|
+
|
74
|
+
if (options.text) {
|
75
|
+
link.innerHTML = options.text;
|
76
|
+
}
|
77
|
+
|
78
|
+
if (options.title) {
|
79
|
+
link.title = options.title;
|
80
|
+
}
|
81
|
+
|
82
|
+
L.DomEvent
|
83
|
+
.on(link, 'click', L.DomEvent.stopPropagation)
|
84
|
+
.on(link, 'mousedown', L.DomEvent.stopPropagation)
|
85
|
+
.on(link, 'dblclick', L.DomEvent.stopPropagation)
|
86
|
+
.on(link, 'click', L.DomEvent.preventDefault)
|
87
|
+
.on(link, 'click', options.callback, options.context);
|
88
|
+
|
89
|
+
return link;
|
90
|
+
},
|
91
|
+
|
92
|
+
_disposeButton: function (button, callback) {
|
93
|
+
L.DomEvent
|
94
|
+
.off(button, 'click', L.DomEvent.stopPropagation)
|
95
|
+
.off(button, 'mousedown', L.DomEvent.stopPropagation)
|
96
|
+
.off(button, 'dblclick', L.DomEvent.stopPropagation)
|
97
|
+
.off(button, 'click', L.DomEvent.preventDefault)
|
98
|
+
.off(button, 'click', callback);
|
99
|
+
},
|
100
|
+
|
101
|
+
_handlerActivated: function (e) {
|
102
|
+
// Disable active mode (if present)
|
103
|
+
if (this._activeMode && this._activeMode.handler.enabled()) {
|
104
|
+
this._activeMode.handler.disable();
|
105
|
+
}
|
106
|
+
|
107
|
+
// Cache new active feature
|
108
|
+
this._activeMode = this._modes[e.handler];
|
109
|
+
|
110
|
+
L.DomUtil.addClass(this._activeMode.button, 'leaflet-draw-toolbar-button-enabled');
|
111
|
+
|
112
|
+
this._showActionsToolbar();
|
113
|
+
|
114
|
+
this.fire('enable');
|
115
|
+
},
|
116
|
+
|
117
|
+
_handlerDeactivated: function () {
|
118
|
+
this._hideActionsToolbar();
|
119
|
+
|
120
|
+
L.DomUtil.removeClass(this._activeMode.button, 'leaflet-draw-toolbar-button-enabled');
|
121
|
+
|
122
|
+
this._activeMode = null;
|
123
|
+
|
124
|
+
this.fire('disable');
|
125
|
+
},
|
126
|
+
|
127
|
+
_createActions: function (buttons) {
|
128
|
+
var container = L.DomUtil.create('ul', 'leaflet-draw-actions'),
|
129
|
+
buttonWidth = 50,
|
130
|
+
l = buttons.length,
|
131
|
+
containerWidth = (l * buttonWidth) + (l - 1), //l - 1 = the borders
|
132
|
+
li, button;
|
133
|
+
|
134
|
+
for (var i = 0; i < l; i++) {
|
135
|
+
li = L.DomUtil.create('li', '', container);
|
136
|
+
|
137
|
+
button = this._createButton({
|
138
|
+
title: buttons[i].title,
|
139
|
+
text: buttons[i].text,
|
140
|
+
container: li,
|
141
|
+
callback: buttons[i].callback,
|
142
|
+
context: buttons[i].context
|
143
|
+
});
|
144
|
+
|
145
|
+
this._actionButtons.push({
|
146
|
+
button: button,
|
147
|
+
callback: buttons[i].callback
|
148
|
+
});
|
149
|
+
}
|
150
|
+
|
151
|
+
container.style.width = containerWidth + 'px';
|
152
|
+
|
153
|
+
return container;
|
154
|
+
},
|
155
|
+
|
156
|
+
_showActionsToolbar: function () {
|
157
|
+
var buttonIndex = this._activeMode.buttonIndex,
|
158
|
+
lastButtonIndex = this._lastButtonIndex,
|
159
|
+
buttonHeight = 26, // TODO: this should be calculated
|
160
|
+
borderHeight = 1, // TODO: this should also be calculated
|
161
|
+
toolbarPosition = (buttonIndex * buttonHeight) + (buttonIndex * borderHeight) - 1;
|
162
|
+
|
163
|
+
// Correctly position the cancel button
|
164
|
+
this._actionsContainer.style.top = toolbarPosition + 'px';
|
165
|
+
|
166
|
+
if (buttonIndex === 0) {
|
167
|
+
L.DomUtil.addClass(this._toolbarContainer, 'leaflet-draw-toolbar-notop');
|
168
|
+
L.DomUtil.addClass(this._actionsContainer, 'leaflet-draw-actions-top');
|
169
|
+
}
|
170
|
+
|
171
|
+
if (buttonIndex === lastButtonIndex) {
|
172
|
+
L.DomUtil.addClass(this._toolbarContainer, 'leaflet-draw-toolbar-nobottom');
|
173
|
+
L.DomUtil.addClass(this._actionsContainer, 'leaflet-draw-actions-bottom');
|
174
|
+
}
|
175
|
+
|
176
|
+
this._actionsContainer.style.display = 'block';
|
177
|
+
},
|
178
|
+
|
179
|
+
_hideActionsToolbar: function () {
|
180
|
+
this._actionsContainer.style.display = 'none';
|
181
|
+
|
182
|
+
L.DomUtil.removeClass(this._toolbarContainer, 'leaflet-draw-toolbar-notop');
|
183
|
+
L.DomUtil.removeClass(this._toolbarContainer, 'leaflet-draw-toolbar-nobottom');
|
184
|
+
L.DomUtil.removeClass(this._actionsContainer, 'leaflet-draw-actions-top');
|
185
|
+
L.DomUtil.removeClass(this._actionsContainer, 'leaflet-draw-actions-bottom');
|
186
|
+
}
|
187
|
+
});
|
@@ -0,0 +1,52 @@
|
|
1
|
+
L.Tooltip = L.Class.extend({
|
2
|
+
initialize: function (map) {
|
3
|
+
this._map = map;
|
4
|
+
this._popupPane = map._panes.popupPane;
|
5
|
+
|
6
|
+
this._container = L.DomUtil.create('div', 'leaflet-draw-tooltip', this._popupPane);
|
7
|
+
this._singleLineLabel = false;
|
8
|
+
},
|
9
|
+
|
10
|
+
dispose: function () {
|
11
|
+
this._popupPane.removeChild(this._container);
|
12
|
+
this._container = null;
|
13
|
+
},
|
14
|
+
|
15
|
+
updateContent: function (labelText) {
|
16
|
+
labelText.subtext = labelText.subtext || '';
|
17
|
+
|
18
|
+
// update the vertical position (only if changed)
|
19
|
+
if (labelText.subtext.length === 0 && !this._singleLineLabel) {
|
20
|
+
L.DomUtil.addClass(this._container, 'leaflet-draw-tooltip-single');
|
21
|
+
this._singleLineLabel = true;
|
22
|
+
}
|
23
|
+
else if (labelText.subtext.length > 0 && this._singleLineLabel) {
|
24
|
+
L.DomUtil.removeClass(this._container, 'leaflet-draw-tooltip-single');
|
25
|
+
this._singleLineLabel = false;
|
26
|
+
}
|
27
|
+
|
28
|
+
this._container.innerHTML =
|
29
|
+
(labelText.subtext.length > 0 ? '<span class="leaflet-draw-tooltip-subtext">' + labelText.subtext + '</span>' + '<br />' : '') +
|
30
|
+
'<span>' + labelText.text + '</span>';
|
31
|
+
|
32
|
+
return this;
|
33
|
+
},
|
34
|
+
|
35
|
+
updatePosition: function (latlng) {
|
36
|
+
var pos = this._map.latLngToLayerPoint(latlng);
|
37
|
+
|
38
|
+
L.DomUtil.setPosition(this._container, pos);
|
39
|
+
|
40
|
+
return this;
|
41
|
+
},
|
42
|
+
|
43
|
+
showAsError: function () {
|
44
|
+
L.DomUtil.addClass(this._container, 'leaflet-error-draw-tooltip');
|
45
|
+
return this;
|
46
|
+
},
|
47
|
+
|
48
|
+
removeError: function () {
|
49
|
+
L.DomUtil.removeClass(this._container, 'leaflet-error-draw-tooltip');
|
50
|
+
return this;
|
51
|
+
}
|
52
|
+
});
|
@@ -0,0 +1,107 @@
|
|
1
|
+
L.DrawToolbar = L.Toolbar.extend({
|
2
|
+
|
3
|
+
options: {
|
4
|
+
polyline: {
|
5
|
+
title: 'Draw a polyline'
|
6
|
+
},
|
7
|
+
polygon: {
|
8
|
+
title: 'Draw a polygon'
|
9
|
+
},
|
10
|
+
rectangle: {
|
11
|
+
title: 'Draw a rectangle'
|
12
|
+
},
|
13
|
+
circle: {
|
14
|
+
title: 'Draw a circle'
|
15
|
+
},
|
16
|
+
marker: {
|
17
|
+
title: 'Add a marker'
|
18
|
+
}
|
19
|
+
},
|
20
|
+
|
21
|
+
initialize: function (options) {
|
22
|
+
L.Toolbar.prototype.initialize.call(this, options);
|
23
|
+
},
|
24
|
+
|
25
|
+
addToolbar: function (map) {
|
26
|
+
var container = L.DomUtil.create('div', 'leaflet-draw-section'),
|
27
|
+
buttonIndex = 0,
|
28
|
+
buttonClassPrefix = 'leaflet-draw-draw';
|
29
|
+
|
30
|
+
this._toolbarContainer = L.DomUtil.create('div', 'leaflet-draw-toolbar leaflet-bar');
|
31
|
+
|
32
|
+
|
33
|
+
if (this.options.polyline) {
|
34
|
+
this._initModeHandler(
|
35
|
+
new L.Draw.Polyline(map, this.options.polyline),
|
36
|
+
this._toolbarContainer,
|
37
|
+
buttonIndex++,
|
38
|
+
buttonClassPrefix
|
39
|
+
);
|
40
|
+
}
|
41
|
+
|
42
|
+
if (this.options.polygon) {
|
43
|
+
this._initModeHandler(
|
44
|
+
new L.Draw.Polygon(map, this.options.polygon),
|
45
|
+
this._toolbarContainer,
|
46
|
+
buttonIndex++,
|
47
|
+
buttonClassPrefix
|
48
|
+
);
|
49
|
+
}
|
50
|
+
|
51
|
+
if (this.options.rectangle) {
|
52
|
+
this._initModeHandler(
|
53
|
+
new L.Draw.Rectangle(map, this.options.rectangle),
|
54
|
+
this._toolbarContainer,
|
55
|
+
buttonIndex++,
|
56
|
+
buttonClassPrefix
|
57
|
+
);
|
58
|
+
}
|
59
|
+
|
60
|
+
if (this.options.circle) {
|
61
|
+
this._initModeHandler(
|
62
|
+
new L.Draw.Circle(map, this.options.circle),
|
63
|
+
this._toolbarContainer,
|
64
|
+
buttonIndex++,
|
65
|
+
buttonClassPrefix
|
66
|
+
);
|
67
|
+
}
|
68
|
+
|
69
|
+
if (this.options.marker) {
|
70
|
+
this._initModeHandler(
|
71
|
+
new L.Draw.Marker(map, this.options.marker),
|
72
|
+
this._toolbarContainer,
|
73
|
+
buttonIndex++,
|
74
|
+
buttonClassPrefix
|
75
|
+
);
|
76
|
+
}
|
77
|
+
|
78
|
+
// Save button index of the last button, -1 as we would have ++ after the last button
|
79
|
+
this._lastButtonIndex = --buttonIndex;
|
80
|
+
|
81
|
+
// Create the actions part of the toolbar
|
82
|
+
this._actionsContainer = this._createActions([
|
83
|
+
{
|
84
|
+
title: 'Cancel drawing',
|
85
|
+
text: 'Cancel',
|
86
|
+
callback: this.disable,
|
87
|
+
context: this
|
88
|
+
}
|
89
|
+
]);
|
90
|
+
|
91
|
+
// Add draw and cancel containers to the control container
|
92
|
+
container.appendChild(this._toolbarContainer);
|
93
|
+
container.appendChild(this._actionsContainer);
|
94
|
+
|
95
|
+
return container;
|
96
|
+
},
|
97
|
+
|
98
|
+
setOptions: function (options) {
|
99
|
+
L.setOptions(this, options);
|
100
|
+
|
101
|
+
for (var type in this._modes) {
|
102
|
+
if (this._modes.hasOwnProperty(type) && options.hasOwnProperty(type)) {
|
103
|
+
this._modes[type].handler.setOptions(options[type]);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
});
|