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,41 @@
|
|
1
|
+
L.Draw.Rectangle = L.Draw.SimpleShape.extend({
|
2
|
+
statics: {
|
3
|
+
TYPE: 'rectangle'
|
4
|
+
},
|
5
|
+
|
6
|
+
options: {
|
7
|
+
shapeOptions: {
|
8
|
+
stroke: true,
|
9
|
+
color: '#f06eaa',
|
10
|
+
weight: 4,
|
11
|
+
opacity: 0.5,
|
12
|
+
fill: true,
|
13
|
+
fillColor: null, //same as color by default
|
14
|
+
fillOpacity: 0.2,
|
15
|
+
clickable: true
|
16
|
+
}
|
17
|
+
},
|
18
|
+
|
19
|
+
initialize: function (map, options) {
|
20
|
+
// Save the type so super can fire, need to do this as cannot do this.TYPE :(
|
21
|
+
this.type = L.Draw.Rectangle.TYPE;
|
22
|
+
|
23
|
+
L.Draw.SimpleShape.prototype.initialize.call(this, map, options);
|
24
|
+
},
|
25
|
+
|
26
|
+
_initialLabelText: 'Click and drag to draw rectangle.',
|
27
|
+
|
28
|
+
_drawShape: function (latlng) {
|
29
|
+
if (!this._shape) {
|
30
|
+
this._shape = new L.Rectangle(new L.LatLngBounds(this._startLatLng, latlng), this.options.shapeOptions);
|
31
|
+
this._map.addLayer(this._shape);
|
32
|
+
} else {
|
33
|
+
this._shape.setBounds(new L.LatLngBounds(this._startLatLng, latlng));
|
34
|
+
}
|
35
|
+
},
|
36
|
+
|
37
|
+
_fireCreatedEvent: function () {
|
38
|
+
var rectangle = new L.Rectangle(this._shape.getBounds(), this.options.shapeOptions);
|
39
|
+
L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, rectangle);
|
40
|
+
}
|
41
|
+
});
|
@@ -0,0 +1,67 @@
|
|
1
|
+
L.SimpleShape = {};
|
2
|
+
|
3
|
+
L.Draw.SimpleShape = L.Draw.Feature.extend({
|
4
|
+
addHooks: function () {
|
5
|
+
L.Draw.Feature.prototype.addHooks.call(this);
|
6
|
+
if (this._map) {
|
7
|
+
this._map.dragging.disable();
|
8
|
+
//TODO refactor: move cursor to styles
|
9
|
+
this._container.style.cursor = 'crosshair';
|
10
|
+
|
11
|
+
this._tooltip.updateContent({ text: this._initialLabelText });
|
12
|
+
|
13
|
+
this._map
|
14
|
+
.on('mousedown', this._onMouseDown, this)
|
15
|
+
.on('mousemove', this._onMouseMove, this);
|
16
|
+
}
|
17
|
+
},
|
18
|
+
|
19
|
+
removeHooks: function () {
|
20
|
+
L.Draw.Feature.prototype.removeHooks.call(this);
|
21
|
+
if (this._map) {
|
22
|
+
this._map.dragging.enable();
|
23
|
+
//TODO refactor: move cursor to styles
|
24
|
+
this._container.style.cursor = '';
|
25
|
+
|
26
|
+
this._map
|
27
|
+
.off('mousedown', this._onMouseDown, this)
|
28
|
+
.off('mousemove', this._onMouseMove, this);
|
29
|
+
|
30
|
+
L.DomEvent.off(document, 'mouseup', this._onMouseUp);
|
31
|
+
|
32
|
+
// If the box element doesn't exist they must not have moved the mouse, so don't need to destroy/return
|
33
|
+
if (this._shape) {
|
34
|
+
this._map.removeLayer(this._shape);
|
35
|
+
delete this._shape;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
this._isDrawing = false;
|
39
|
+
},
|
40
|
+
|
41
|
+
_onMouseDown: function (e) {
|
42
|
+
this._isDrawing = true;
|
43
|
+
this._startLatLng = e.latlng;
|
44
|
+
|
45
|
+
L.DomEvent
|
46
|
+
.on(document, 'mouseup', this._onMouseUp, this)
|
47
|
+
.preventDefault(e.originalEvent);
|
48
|
+
},
|
49
|
+
|
50
|
+
_onMouseMove: function (e) {
|
51
|
+
var latlng = e.latlng;
|
52
|
+
|
53
|
+
this._tooltip.updatePosition(latlng);
|
54
|
+
if (this._isDrawing) {
|
55
|
+
this._tooltip.updateContent({ text: 'Release mouse to finish drawing.' });
|
56
|
+
this._drawShape(latlng);
|
57
|
+
}
|
58
|
+
},
|
59
|
+
|
60
|
+
_onMouseUp: function () {
|
61
|
+
if (this._shape) {
|
62
|
+
this._fireCreatedEvent();
|
63
|
+
}
|
64
|
+
|
65
|
+
this.disable();
|
66
|
+
}
|
67
|
+
});
|
@@ -0,0 +1,93 @@
|
|
1
|
+
/*L.Map.mergeOptions({
|
2
|
+
editControl: true
|
3
|
+
});*/
|
4
|
+
|
5
|
+
L.EditToolbar = L.Toolbar.extend({
|
6
|
+
options: {
|
7
|
+
edit: {
|
8
|
+
title: 'Edit layers',
|
9
|
+
selectedPathOptions: null // See Edit handler options, this is used to customize the style of selected paths
|
10
|
+
},
|
11
|
+
remove: {
|
12
|
+
title: 'Delete layers'
|
13
|
+
},
|
14
|
+
featureGroup: null /* REQUIRED! TODO: perhaps if not set then all layers on the map are selectable? */
|
15
|
+
},
|
16
|
+
|
17
|
+
initialize: function (options) {
|
18
|
+
L.Toolbar.prototype.initialize.call(this, options);
|
19
|
+
|
20
|
+
this._selectedFeatureCount = 0;
|
21
|
+
},
|
22
|
+
|
23
|
+
addToolbar: function (map) {
|
24
|
+
var container = L.DomUtil.create('div', 'leaflet-draw-section'),
|
25
|
+
buttonIndex = 0,
|
26
|
+
buttonClassPrefix = 'leaflet-draw-edit';
|
27
|
+
|
28
|
+
this._toolbarContainer = L.DomUtil.create('div', 'leaflet-draw-toolbar leaflet-bar'),
|
29
|
+
|
30
|
+
this._map = map;
|
31
|
+
|
32
|
+
if (this.options.edit) {
|
33
|
+
this._initModeHandler(
|
34
|
+
new L.EditToolbar.Edit(map, {
|
35
|
+
featureGroup: this.options.featureGroup,
|
36
|
+
selectedPathOptions: this.options.edit.selectedPathOptions
|
37
|
+
}),
|
38
|
+
this._toolbarContainer,
|
39
|
+
buttonIndex++,
|
40
|
+
buttonClassPrefix
|
41
|
+
);
|
42
|
+
}
|
43
|
+
|
44
|
+
if (this.options.remove) {
|
45
|
+
this._initModeHandler(
|
46
|
+
new L.EditToolbar.Delete(map, {
|
47
|
+
featureGroup: this.options.featureGroup
|
48
|
+
}),
|
49
|
+
this._toolbarContainer,
|
50
|
+
buttonIndex++,
|
51
|
+
buttonClassPrefix
|
52
|
+
);
|
53
|
+
}
|
54
|
+
|
55
|
+
// Save button index of the last button, -1 as we would have ++ after the last button
|
56
|
+
this._lastButtonIndex = --buttonIndex;
|
57
|
+
|
58
|
+
// Create the actions part of the toolbar
|
59
|
+
this._actionsContainer = this._createActions([
|
60
|
+
{
|
61
|
+
title: 'Save changes.',
|
62
|
+
text: 'Save',
|
63
|
+
callback: this._save,
|
64
|
+
context: this
|
65
|
+
},
|
66
|
+
{
|
67
|
+
title: 'Cancel editing, discards all changes.',
|
68
|
+
text: 'Cancel',
|
69
|
+
callback: this.disable,
|
70
|
+
context: this
|
71
|
+
}
|
72
|
+
]);
|
73
|
+
|
74
|
+
// Add draw and cancel containers to the control container
|
75
|
+
container.appendChild(this._toolbarContainer);
|
76
|
+
container.appendChild(this._actionsContainer);
|
77
|
+
|
78
|
+
return container;
|
79
|
+
},
|
80
|
+
|
81
|
+
disable: function () {
|
82
|
+
if (!this.enabled()) { return; }
|
83
|
+
|
84
|
+
this._activeMode.handler.revertLayers();
|
85
|
+
|
86
|
+
L.Toolbar.prototype.disable.call(this);
|
87
|
+
},
|
88
|
+
|
89
|
+
_save: function () {
|
90
|
+
this._activeMode.handler.save();
|
91
|
+
this._activeMode.handler.disable();
|
92
|
+
}
|
93
|
+
});
|
@@ -0,0 +1,63 @@
|
|
1
|
+
L.Edit = L.Edit || {};
|
2
|
+
|
3
|
+
L.Edit.Circle = L.Edit.SimpleShape.extend({
|
4
|
+
_createMoveMarker: function () {
|
5
|
+
var center = this._shape.getLatLng();
|
6
|
+
|
7
|
+
this._moveMarker = this._createMarker(center, this.options.moveIcon);
|
8
|
+
},
|
9
|
+
|
10
|
+
_createResizeMarker: function () {
|
11
|
+
var center = this._shape.getLatLng(),
|
12
|
+
resizemarkerPoint = this._getResizeMarkerPoint(center);
|
13
|
+
|
14
|
+
this._resizeMarkers = [];
|
15
|
+
this._resizeMarkers.push(this._createMarker(resizemarkerPoint, this.options.resizeIcon));
|
16
|
+
},
|
17
|
+
|
18
|
+
_getResizeMarkerPoint: function (latlng) {
|
19
|
+
// From L.shape.getBounds()
|
20
|
+
var delta = this._shape._radius * Math.cos(Math.PI / 4),
|
21
|
+
point = this._map.project(latlng);
|
22
|
+
return this._map.unproject([point.x + delta, point.y - delta]);
|
23
|
+
},
|
24
|
+
|
25
|
+
_move: function (latlng) {
|
26
|
+
var resizemarkerPoint = this._getResizeMarkerPoint(latlng);
|
27
|
+
|
28
|
+
// Move the resize marker
|
29
|
+
this._resizeMarkers[0].setLatLng(resizemarkerPoint);
|
30
|
+
|
31
|
+
// Move the circle
|
32
|
+
this._shape.setLatLng(latlng);
|
33
|
+
},
|
34
|
+
|
35
|
+
_resize: function (latlng) {
|
36
|
+
var moveLatLng = this._moveMarker.getLatLng(),
|
37
|
+
radius = moveLatLng.distanceTo(latlng);
|
38
|
+
|
39
|
+
this._shape.setRadius(radius);
|
40
|
+
}
|
41
|
+
});
|
42
|
+
|
43
|
+
L.Circle.addInitHook(function () {
|
44
|
+
if (L.Edit.Circle) {
|
45
|
+
this.editing = new L.Edit.Circle(this);
|
46
|
+
|
47
|
+
if (this.options.editable) {
|
48
|
+
this.editing.enable();
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
this.on('add', function () {
|
53
|
+
if (this.editing && this.editing.enabled()) {
|
54
|
+
this.editing.addHooks();
|
55
|
+
}
|
56
|
+
});
|
57
|
+
|
58
|
+
this.on('remove', function () {
|
59
|
+
if (this.editing && this.editing.enabled()) {
|
60
|
+
this.editing.removeHooks();
|
61
|
+
}
|
62
|
+
});
|
63
|
+
});
|
@@ -0,0 +1,267 @@
|
|
1
|
+
L.Edit = L.Edit || {};
|
2
|
+
|
3
|
+
/*
|
4
|
+
* L.Edit.Poly is an editing handler for polylines and polygons.
|
5
|
+
*/
|
6
|
+
|
7
|
+
L.Edit.Poly = L.Handler.extend({
|
8
|
+
options: {
|
9
|
+
icon: new L.DivIcon({
|
10
|
+
iconSize: new L.Point(8, 8),
|
11
|
+
className: 'leaflet-div-icon leaflet-editing-icon'
|
12
|
+
})
|
13
|
+
},
|
14
|
+
|
15
|
+
initialize: function (poly, options) {
|
16
|
+
this._poly = poly;
|
17
|
+
L.setOptions(this, options);
|
18
|
+
},
|
19
|
+
|
20
|
+
addHooks: function () {
|
21
|
+
if (this._poly._map) {
|
22
|
+
if (!this._markerGroup) {
|
23
|
+
this._initMarkers();
|
24
|
+
}
|
25
|
+
this._poly._map.addLayer(this._markerGroup);
|
26
|
+
}
|
27
|
+
},
|
28
|
+
|
29
|
+
removeHooks: function () {
|
30
|
+
if (this._poly._map) {
|
31
|
+
this._poly._map.removeLayer(this._markerGroup);
|
32
|
+
delete this._markerGroup;
|
33
|
+
delete this._markers;
|
34
|
+
}
|
35
|
+
},
|
36
|
+
|
37
|
+
updateMarkers: function () {
|
38
|
+
this._markerGroup.clearLayers();
|
39
|
+
this._initMarkers();
|
40
|
+
},
|
41
|
+
|
42
|
+
_initMarkers: function () {
|
43
|
+
if (!this._markerGroup) {
|
44
|
+
this._markerGroup = new L.LayerGroup();
|
45
|
+
}
|
46
|
+
this._markers = [];
|
47
|
+
|
48
|
+
var latlngs = this._poly._latlngs,
|
49
|
+
i, j, len, marker;
|
50
|
+
|
51
|
+
// TODO refactor holes implementation in Polygon to support it here
|
52
|
+
|
53
|
+
for (i = 0, len = latlngs.length; i < len; i++) {
|
54
|
+
|
55
|
+
marker = this._createMarker(latlngs[i], i);
|
56
|
+
marker.on('click', this._onMarkerClick, this);
|
57
|
+
this._markers.push(marker);
|
58
|
+
}
|
59
|
+
|
60
|
+
var markerLeft, markerRight;
|
61
|
+
|
62
|
+
for (i = 0, j = len - 1; i < len; j = i++) {
|
63
|
+
if (i === 0 && !(L.Polygon && (this._poly instanceof L.Polygon))) {
|
64
|
+
continue;
|
65
|
+
}
|
66
|
+
|
67
|
+
markerLeft = this._markers[j];
|
68
|
+
markerRight = this._markers[i];
|
69
|
+
|
70
|
+
this._createMiddleMarker(markerLeft, markerRight);
|
71
|
+
this._updatePrevNext(markerLeft, markerRight);
|
72
|
+
}
|
73
|
+
},
|
74
|
+
|
75
|
+
_createMarker: function (latlng, index) {
|
76
|
+
var marker = new L.Marker(latlng, {
|
77
|
+
draggable: true,
|
78
|
+
icon: this.options.icon
|
79
|
+
});
|
80
|
+
|
81
|
+
marker._origLatLng = latlng;
|
82
|
+
marker._index = index;
|
83
|
+
|
84
|
+
marker.on('drag', this._onMarkerDrag, this);
|
85
|
+
marker.on('dragend', this._fireEdit, this);
|
86
|
+
|
87
|
+
this._markerGroup.addLayer(marker);
|
88
|
+
|
89
|
+
return marker;
|
90
|
+
},
|
91
|
+
|
92
|
+
_removeMarker: function (marker) {
|
93
|
+
var i = marker._index;
|
94
|
+
|
95
|
+
this._markerGroup.removeLayer(marker);
|
96
|
+
this._markers.splice(i, 1);
|
97
|
+
this._poly.spliceLatLngs(i, 1);
|
98
|
+
this._updateIndexes(i, -1);
|
99
|
+
|
100
|
+
marker
|
101
|
+
.off('drag', this._onMarkerDrag, this)
|
102
|
+
.off('dragend', this._fireEdit, this)
|
103
|
+
.off('click', this._onMarkerClick, this);
|
104
|
+
},
|
105
|
+
|
106
|
+
_fireEdit: function () {
|
107
|
+
this._poly.edited = true;
|
108
|
+
this._poly.fire('edit');
|
109
|
+
},
|
110
|
+
|
111
|
+
_onMarkerDrag: function (e) {
|
112
|
+
var marker = e.target;
|
113
|
+
|
114
|
+
L.extend(marker._origLatLng, marker._latlng);
|
115
|
+
|
116
|
+
if (marker._middleLeft) {
|
117
|
+
marker._middleLeft.setLatLng(this._getMiddleLatLng(marker._prev, marker));
|
118
|
+
}
|
119
|
+
if (marker._middleRight) {
|
120
|
+
marker._middleRight.setLatLng(this._getMiddleLatLng(marker, marker._next));
|
121
|
+
}
|
122
|
+
|
123
|
+
this._poly.redraw();
|
124
|
+
},
|
125
|
+
|
126
|
+
_onMarkerClick: function (e) {
|
127
|
+
// we want to remove the marker on click, but if latlng count < 3, polyline would be invalid
|
128
|
+
if (this._poly._latlngs.length < 3) { return; }
|
129
|
+
|
130
|
+
var marker = e.target;
|
131
|
+
|
132
|
+
// remove the marker
|
133
|
+
this._removeMarker(marker);
|
134
|
+
|
135
|
+
// update prev/next links of adjacent markers
|
136
|
+
this._updatePrevNext(marker._prev, marker._next);
|
137
|
+
|
138
|
+
// remove ghost markers near the removed marker
|
139
|
+
if (marker._middleLeft) {
|
140
|
+
this._markerGroup.removeLayer(marker._middleLeft);
|
141
|
+
}
|
142
|
+
if (marker._middleRight) {
|
143
|
+
this._markerGroup.removeLayer(marker._middleRight);
|
144
|
+
}
|
145
|
+
|
146
|
+
// create a ghost marker in place of the removed one
|
147
|
+
if (marker._prev && marker._next) {
|
148
|
+
this._createMiddleMarker(marker._prev, marker._next);
|
149
|
+
|
150
|
+
} else if (!marker._prev) {
|
151
|
+
marker._next._middleLeft = null;
|
152
|
+
|
153
|
+
} else if (!marker._next) {
|
154
|
+
marker._prev._middleRight = null;
|
155
|
+
}
|
156
|
+
|
157
|
+
this._fireEdit();
|
158
|
+
},
|
159
|
+
|
160
|
+
_updateIndexes: function (index, delta) {
|
161
|
+
this._markerGroup.eachLayer(function (marker) {
|
162
|
+
if (marker._index > index) {
|
163
|
+
marker._index += delta;
|
164
|
+
}
|
165
|
+
});
|
166
|
+
},
|
167
|
+
|
168
|
+
_createMiddleMarker: function (marker1, marker2) {
|
169
|
+
var latlng = this._getMiddleLatLng(marker1, marker2),
|
170
|
+
marker = this._createMarker(latlng),
|
171
|
+
onClick,
|
172
|
+
onDragStart,
|
173
|
+
onDragEnd;
|
174
|
+
|
175
|
+
marker.setOpacity(0.6);
|
176
|
+
|
177
|
+
marker1._middleRight = marker2._middleLeft = marker;
|
178
|
+
|
179
|
+
onDragStart = function () {
|
180
|
+
var i = marker2._index;
|
181
|
+
|
182
|
+
marker._index = i;
|
183
|
+
|
184
|
+
marker
|
185
|
+
.off('click', onClick, this)
|
186
|
+
.on('click', this._onMarkerClick, this);
|
187
|
+
|
188
|
+
latlng.lat = marker.getLatLng().lat;
|
189
|
+
latlng.lng = marker.getLatLng().lng;
|
190
|
+
this._poly.spliceLatLngs(i, 0, latlng);
|
191
|
+
this._markers.splice(i, 0, marker);
|
192
|
+
|
193
|
+
marker.setOpacity(1);
|
194
|
+
|
195
|
+
this._updateIndexes(i, 1);
|
196
|
+
marker2._index++;
|
197
|
+
this._updatePrevNext(marker1, marker);
|
198
|
+
this._updatePrevNext(marker, marker2);
|
199
|
+
};
|
200
|
+
|
201
|
+
onDragEnd = function () {
|
202
|
+
marker.off('dragstart', onDragStart, this);
|
203
|
+
marker.off('dragend', onDragEnd, this);
|
204
|
+
|
205
|
+
this._createMiddleMarker(marker1, marker);
|
206
|
+
this._createMiddleMarker(marker, marker2);
|
207
|
+
};
|
208
|
+
|
209
|
+
onClick = function () {
|
210
|
+
onDragStart.call(this);
|
211
|
+
onDragEnd.call(this);
|
212
|
+
this._fireEdit();
|
213
|
+
};
|
214
|
+
|
215
|
+
marker
|
216
|
+
.on('click', onClick, this)
|
217
|
+
.on('dragstart', onDragStart, this)
|
218
|
+
.on('dragend', onDragEnd, this);
|
219
|
+
|
220
|
+
this._markerGroup.addLayer(marker);
|
221
|
+
},
|
222
|
+
|
223
|
+
_updatePrevNext: function (marker1, marker2) {
|
224
|
+
if (marker1) {
|
225
|
+
marker1._next = marker2;
|
226
|
+
}
|
227
|
+
if (marker2) {
|
228
|
+
marker2._prev = marker1;
|
229
|
+
}
|
230
|
+
},
|
231
|
+
|
232
|
+
_getMiddleLatLng: function (marker1, marker2) {
|
233
|
+
var map = this._poly._map,
|
234
|
+
p1 = map.latLngToLayerPoint(marker1.getLatLng()),
|
235
|
+
p2 = map.latLngToLayerPoint(marker2.getLatLng());
|
236
|
+
|
237
|
+
return map.layerPointToLatLng(p1._add(p2)._divideBy(2));
|
238
|
+
}
|
239
|
+
});
|
240
|
+
|
241
|
+
L.Polyline.addInitHook(function () {
|
242
|
+
|
243
|
+
// Check to see if handler has already been initialized. This is to support versions of Leaflet that still have L.Handler.PolyEdit
|
244
|
+
if (this.editing) {
|
245
|
+
return;
|
246
|
+
}
|
247
|
+
|
248
|
+
if (L.Edit.Poly) {
|
249
|
+
this.editing = new L.Edit.Poly(this);
|
250
|
+
|
251
|
+
if (this.options.editable) {
|
252
|
+
this.editing.enable();
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
this.on('add', function () {
|
257
|
+
if (this.editing && this.editing.enabled()) {
|
258
|
+
this.editing.addHooks();
|
259
|
+
}
|
260
|
+
});
|
261
|
+
|
262
|
+
this.on('remove', function () {
|
263
|
+
if (this.editing && this.editing.enabled()) {
|
264
|
+
this.editing.removeHooks();
|
265
|
+
}
|
266
|
+
});
|
267
|
+
});
|