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,31 @@
|
|
1
|
+
/*
|
2
|
+
* L.Transformation is an utility class to perform simple point transformations through a 2d-matrix.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Transformation = L.Class.extend({
|
6
|
+
initialize: function (/*Number*/ a, /*Number*/ b, /*Number*/ c, /*Number*/ d) {
|
7
|
+
this._a = a;
|
8
|
+
this._b = b;
|
9
|
+
this._c = c;
|
10
|
+
this._d = d;
|
11
|
+
},
|
12
|
+
|
13
|
+
transform: function (point, scale) {
|
14
|
+
return this._transform(point.clone(), scale);
|
15
|
+
},
|
16
|
+
|
17
|
+
// destructive transform (faster)
|
18
|
+
_transform: function (/*Point*/ point, /*Number*/ scale) /*-> Point*/ {
|
19
|
+
scale = scale || 1;
|
20
|
+
point.x = scale * (this._a * point.x + this._b);
|
21
|
+
point.y = scale * (this._c * point.y + this._d);
|
22
|
+
return point;
|
23
|
+
},
|
24
|
+
|
25
|
+
untransform: function (/*Point*/ point, /*Number*/ scale) /*-> Point*/ {
|
26
|
+
scale = scale || 1;
|
27
|
+
return new L.Point(
|
28
|
+
(point.x / scale - this._b) / this._a,
|
29
|
+
(point.y / scale - this._d) / this._c);
|
30
|
+
}
|
31
|
+
});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
* L.FeatureGroup extends L.LayerGroup by introducing mouse events and bindPopup method shared between a group of layers.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.FeatureGroup = L.LayerGroup.extend({
|
6
|
+
includes: L.Mixin.Events,
|
7
|
+
|
8
|
+
addLayer: function (layer) {
|
9
|
+
this._initEvents(layer);
|
10
|
+
L.LayerGroup.prototype.addLayer.call(this, layer);
|
11
|
+
|
12
|
+
if (this._popupContent && layer.bindPopup) {
|
13
|
+
layer.bindPopup(this._popupContent);
|
14
|
+
}
|
15
|
+
},
|
16
|
+
|
17
|
+
bindPopup: function (content) {
|
18
|
+
this._popupContent = content;
|
19
|
+
|
20
|
+
return this.invoke('bindPopup', content);
|
21
|
+
},
|
22
|
+
|
23
|
+
setStyle: function (style) {
|
24
|
+
return this.invoke('setStyle', style);
|
25
|
+
},
|
26
|
+
|
27
|
+
_events: ['click', 'dblclick', 'mouseover', 'mouseout'],
|
28
|
+
|
29
|
+
_initEvents: function (layer) {
|
30
|
+
for (var i = 0, len = this._events.length; i < len; i++) {
|
31
|
+
layer.on(this._events[i], this._propagateEvent, this);
|
32
|
+
}
|
33
|
+
},
|
34
|
+
|
35
|
+
_propagateEvent: function (e) {
|
36
|
+
e.layer = e.target;
|
37
|
+
e.target = this;
|
38
|
+
this.fire(e.type, e);
|
39
|
+
}
|
40
|
+
});
|
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
L.GeoJSON = L.FeatureGroup.extend({
|
3
|
+
initialize: function (geojson, options) {
|
4
|
+
L.Util.setOptions(this, options);
|
5
|
+
this._geojson = geojson;
|
6
|
+
this._layers = {};
|
7
|
+
|
8
|
+
if (geojson) {
|
9
|
+
this.addGeoJSON(geojson);
|
10
|
+
}
|
11
|
+
},
|
12
|
+
|
13
|
+
addGeoJSON: function (geojson) {
|
14
|
+
if (geojson.features) {
|
15
|
+
for (var i = 0, len = geojson.features.length; i < len; i++) {
|
16
|
+
this.addGeoJSON(geojson.features[i]);
|
17
|
+
}
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
|
21
|
+
var isFeature = (geojson.type === 'Feature'),
|
22
|
+
geometry = (isFeature ? geojson.geometry : geojson),
|
23
|
+
layer = L.GeoJSON.geometryToLayer(geometry, this.options.pointToLayer);
|
24
|
+
|
25
|
+
this.fire('featureparse', {
|
26
|
+
layer: layer,
|
27
|
+
properties: geojson.properties,
|
28
|
+
geometryType: geometry.type,
|
29
|
+
bbox: geojson.bbox,
|
30
|
+
id: geojson.id
|
31
|
+
});
|
32
|
+
|
33
|
+
this.addLayer(layer);
|
34
|
+
}
|
35
|
+
});
|
36
|
+
|
37
|
+
L.Util.extend(L.GeoJSON, {
|
38
|
+
geometryToLayer: function (geometry, pointToLayer) {
|
39
|
+
var coords = geometry.coordinates,
|
40
|
+
latlng, latlngs,
|
41
|
+
i, len,
|
42
|
+
layer,
|
43
|
+
layers = [];
|
44
|
+
|
45
|
+
switch (geometry.type) {
|
46
|
+
case 'Point':
|
47
|
+
latlng = this.coordsToLatLng(coords);
|
48
|
+
return pointToLayer ? pointToLayer(latlng) : new L.Marker(latlng);
|
49
|
+
|
50
|
+
case 'MultiPoint':
|
51
|
+
for (i = 0, len = coords.length; i < len; i++) {
|
52
|
+
latlng = this.coordsToLatLng(coords[i]);
|
53
|
+
layer = pointToLayer ? pointToLayer(latlng) : new L.Marker(latlng);
|
54
|
+
layers.push(layer);
|
55
|
+
}
|
56
|
+
return new L.FeatureGroup(layers);
|
57
|
+
|
58
|
+
case 'LineString':
|
59
|
+
latlngs = this.coordsToLatLngs(coords);
|
60
|
+
return new L.Polyline(latlngs);
|
61
|
+
|
62
|
+
case 'Polygon':
|
63
|
+
latlngs = this.coordsToLatLngs(coords, 1);
|
64
|
+
return new L.Polygon(latlngs);
|
65
|
+
|
66
|
+
case 'MultiLineString':
|
67
|
+
latlngs = this.coordsToLatLngs(coords, 1);
|
68
|
+
return new L.MultiPolyline(latlngs);
|
69
|
+
|
70
|
+
case "MultiPolygon":
|
71
|
+
latlngs = this.coordsToLatLngs(coords, 2);
|
72
|
+
return new L.MultiPolygon(latlngs);
|
73
|
+
|
74
|
+
case "GeometryCollection":
|
75
|
+
for (i = 0, len = geometry.geometries.length; i < len; i++) {
|
76
|
+
layer = this.geometryToLayer(geometry.geometries[i], pointToLayer);
|
77
|
+
layers.push(layer);
|
78
|
+
}
|
79
|
+
return new L.FeatureGroup(layers);
|
80
|
+
|
81
|
+
default:
|
82
|
+
throw new Error('Invalid GeoJSON object.');
|
83
|
+
}
|
84
|
+
},
|
85
|
+
|
86
|
+
coordsToLatLng: function (/*Array*/ coords, /*Boolean*/ reverse)/*: LatLng*/ {
|
87
|
+
var lat = parseFloat(coords[reverse ? 0 : 1]),
|
88
|
+
lng = parseFloat(coords[reverse ? 1 : 0]);
|
89
|
+
return new L.LatLng(lat, lng, true);
|
90
|
+
},
|
91
|
+
|
92
|
+
coordsToLatLngs: function (/*Array*/ coords, /*Number*/ levelsDeep, /*Boolean*/ reverse)/*: Array*/ {
|
93
|
+
var latlng, latlngs = [],
|
94
|
+
i, len = coords.length;
|
95
|
+
|
96
|
+
for (i = 0; i < len; i++) {
|
97
|
+
latlng = levelsDeep ?
|
98
|
+
this.coordsToLatLngs(coords[i], levelsDeep - 1, reverse) :
|
99
|
+
this.coordsToLatLng(coords[i], reverse);
|
100
|
+
latlngs.push(latlng);
|
101
|
+
}
|
102
|
+
return latlngs;
|
103
|
+
}
|
104
|
+
});
|
@@ -0,0 +1,58 @@
|
|
1
|
+
L.ImageOverlay = L.Class.extend({
|
2
|
+
includes: L.Mixin.Events,
|
3
|
+
|
4
|
+
initialize: function (/*String*/ url, /*LatLngBounds*/ bounds) {
|
5
|
+
this._url = url;
|
6
|
+
this._bounds = bounds;
|
7
|
+
},
|
8
|
+
|
9
|
+
onAdd: function (map) {
|
10
|
+
this._map = map;
|
11
|
+
|
12
|
+
if (!this._image) {
|
13
|
+
this._initImage();
|
14
|
+
}
|
15
|
+
|
16
|
+
map.getPanes().overlayPane.appendChild(this._image);
|
17
|
+
|
18
|
+
map.on('viewreset', this._reset, this);
|
19
|
+
this._reset();
|
20
|
+
},
|
21
|
+
|
22
|
+
onRemove: function (map) {
|
23
|
+
map.getPanes().overlayPane.removeChild(this._image);
|
24
|
+
map.off('viewreset', this._reset, this);
|
25
|
+
},
|
26
|
+
|
27
|
+
_initImage: function () {
|
28
|
+
this._image = L.DomUtil.create('img', 'leaflet-image-layer');
|
29
|
+
|
30
|
+
this._image.style.visibility = 'hidden';
|
31
|
+
//TODO opacity option
|
32
|
+
|
33
|
+
//TODO createImage util method to remove duplication
|
34
|
+
L.Util.extend(this._image, {
|
35
|
+
galleryimg: 'no',
|
36
|
+
onselectstart: L.Util.falseFn,
|
37
|
+
onmousemove: L.Util.falseFn,
|
38
|
+
onload: L.Util.bind(this._onImageLoad, this),
|
39
|
+
src: this._url
|
40
|
+
});
|
41
|
+
},
|
42
|
+
|
43
|
+
_reset: function () {
|
44
|
+
var topLeft = this._map.latLngToLayerPoint(this._bounds.getNorthWest()),
|
45
|
+
bottomRight = this._map.latLngToLayerPoint(this._bounds.getSouthEast()),
|
46
|
+
size = bottomRight.subtract(topLeft);
|
47
|
+
|
48
|
+
L.DomUtil.setPosition(this._image, topLeft);
|
49
|
+
|
50
|
+
this._image.style.width = size.x + 'px';
|
51
|
+
this._image.style.height = size.y + 'px';
|
52
|
+
},
|
53
|
+
|
54
|
+
_onImageLoad: function () {
|
55
|
+
this._image.style.visibility = '';
|
56
|
+
this.fire('load');
|
57
|
+
}
|
58
|
+
});
|
@@ -0,0 +1,74 @@
|
|
1
|
+
/*
|
2
|
+
* L.LayerGroup is a class to combine several layers so you can manipulate the group (e.g. add/remove it) as one layer.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.LayerGroup = L.Class.extend({
|
6
|
+
initialize: function (layers) {
|
7
|
+
this._layers = {};
|
8
|
+
|
9
|
+
if (layers) {
|
10
|
+
for (var i = 0, len = layers.length; i < len; i++) {
|
11
|
+
this.addLayer(layers[i]);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
},
|
15
|
+
|
16
|
+
addLayer: function (layer) {
|
17
|
+
var id = L.Util.stamp(layer);
|
18
|
+
this._layers[id] = layer;
|
19
|
+
|
20
|
+
if (this._map) {
|
21
|
+
this._map.addLayer(layer);
|
22
|
+
}
|
23
|
+
return this;
|
24
|
+
},
|
25
|
+
|
26
|
+
removeLayer: function (layer) {
|
27
|
+
var id = L.Util.stamp(layer);
|
28
|
+
delete this._layers[id];
|
29
|
+
|
30
|
+
if (this._map) {
|
31
|
+
this._map.removeLayer(layer);
|
32
|
+
}
|
33
|
+
return this;
|
34
|
+
},
|
35
|
+
|
36
|
+
clearLayers: function () {
|
37
|
+
this._iterateLayers(this.removeLayer, this);
|
38
|
+
return this;
|
39
|
+
},
|
40
|
+
|
41
|
+
invoke: function (methodName) {
|
42
|
+
var args = Array.prototype.slice.call(arguments, 1),
|
43
|
+
i, layer;
|
44
|
+
|
45
|
+
for (i in this._layers) {
|
46
|
+
if (this._layers.hasOwnProperty(i)) {
|
47
|
+
layer = this._layers[i];
|
48
|
+
|
49
|
+
if (layer[methodName]) {
|
50
|
+
layer[methodName].apply(layer, args);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
return this;
|
55
|
+
},
|
56
|
+
|
57
|
+
onAdd: function (map) {
|
58
|
+
this._map = map;
|
59
|
+
this._iterateLayers(map.addLayer, map);
|
60
|
+
},
|
61
|
+
|
62
|
+
onRemove: function (map) {
|
63
|
+
this._iterateLayers(map.removeLayer, map);
|
64
|
+
delete this._map;
|
65
|
+
},
|
66
|
+
|
67
|
+
_iterateLayers: function (method, context) {
|
68
|
+
for (var i in this._layers) {
|
69
|
+
if (this._layers.hasOwnProperty(i)) {
|
70
|
+
method.call(context, this._layers[i]);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
});
|
@@ -0,0 +1,179 @@
|
|
1
|
+
|
2
|
+
L.Popup = L.Class.extend({
|
3
|
+
includes: L.Mixin.Events,
|
4
|
+
|
5
|
+
options: {
|
6
|
+
minWidth: 50,
|
7
|
+
maxWidth: 300,
|
8
|
+
autoPan: true,
|
9
|
+
closeButton: true,
|
10
|
+
offset: new L.Point(0, 2),
|
11
|
+
autoPanPadding: new L.Point(5, 5),
|
12
|
+
className: ''
|
13
|
+
},
|
14
|
+
|
15
|
+
initialize: function (options, source) {
|
16
|
+
L.Util.setOptions(this, options);
|
17
|
+
|
18
|
+
this._source = source;
|
19
|
+
},
|
20
|
+
|
21
|
+
onAdd: function (map) {
|
22
|
+
this._map = map;
|
23
|
+
if (!this._container) {
|
24
|
+
this._initLayout();
|
25
|
+
}
|
26
|
+
this._updateContent();
|
27
|
+
|
28
|
+
this._container.style.opacity = '0';
|
29
|
+
|
30
|
+
this._map._panes.popupPane.appendChild(this._container);
|
31
|
+
this._map.on('viewreset', this._updatePosition, this);
|
32
|
+
|
33
|
+
if (this._map.options.closePopupOnClick) {
|
34
|
+
this._map.on('preclick', this._close, this);
|
35
|
+
}
|
36
|
+
|
37
|
+
this._update();
|
38
|
+
|
39
|
+
this._container.style.opacity = '1'; //TODO fix ugly opacity hack
|
40
|
+
|
41
|
+
this._opened = true;
|
42
|
+
},
|
43
|
+
|
44
|
+
onRemove: function (map) {
|
45
|
+
map._panes.popupPane.removeChild(this._container);
|
46
|
+
L.Util.falseFn(this._container.offsetWidth);
|
47
|
+
|
48
|
+
map.off('viewreset', this._updatePosition, this);
|
49
|
+
map.off('click', this._close, this);
|
50
|
+
|
51
|
+
this._container.style.opacity = '0';
|
52
|
+
|
53
|
+
this._opened = false;
|
54
|
+
},
|
55
|
+
|
56
|
+
setLatLng: function (latlng) {
|
57
|
+
this._latlng = latlng;
|
58
|
+
if (this._opened) {
|
59
|
+
this._update();
|
60
|
+
}
|
61
|
+
return this;
|
62
|
+
},
|
63
|
+
|
64
|
+
setContent: function (content) {
|
65
|
+
this._content = content;
|
66
|
+
if (this._opened) {
|
67
|
+
this._update();
|
68
|
+
}
|
69
|
+
return this;
|
70
|
+
},
|
71
|
+
|
72
|
+
_close: function () {
|
73
|
+
if (this._opened) {
|
74
|
+
this._map.closePopup();
|
75
|
+
}
|
76
|
+
},
|
77
|
+
|
78
|
+
_initLayout: function () {
|
79
|
+
this._container = L.DomUtil.create('div', 'leaflet-popup ' + this.options.className);
|
80
|
+
|
81
|
+
if (this.options.closeButton) {
|
82
|
+
this._closeButton = L.DomUtil.create('a', 'leaflet-popup-close-button', this._container);
|
83
|
+
this._closeButton.href = '#close';
|
84
|
+
L.DomEvent.addListener(this._closeButton, 'click', this._onCloseButtonClick, this);
|
85
|
+
}
|
86
|
+
|
87
|
+
this._wrapper = L.DomUtil.create('div', 'leaflet-popup-content-wrapper', this._container);
|
88
|
+
L.DomEvent.disableClickPropagation(this._wrapper);
|
89
|
+
this._contentNode = L.DomUtil.create('div', 'leaflet-popup-content', this._wrapper);
|
90
|
+
|
91
|
+
this._tipContainer = L.DomUtil.create('div', 'leaflet-popup-tip-container', this._container);
|
92
|
+
this._tip = L.DomUtil.create('div', 'leaflet-popup-tip', this._tipContainer);
|
93
|
+
},
|
94
|
+
|
95
|
+
_update: function () {
|
96
|
+
this._container.style.visibility = 'hidden';
|
97
|
+
|
98
|
+
this._updateContent();
|
99
|
+
this._updateLayout();
|
100
|
+
this._updatePosition();
|
101
|
+
|
102
|
+
this._container.style.visibility = '';
|
103
|
+
|
104
|
+
this._adjustPan();
|
105
|
+
},
|
106
|
+
|
107
|
+
_updateContent: function () {
|
108
|
+
if (!this._content) {
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
|
112
|
+
if (typeof this._content === 'string') {
|
113
|
+
this._contentNode.innerHTML = this._content;
|
114
|
+
} else {
|
115
|
+
this._contentNode.innerHTML = '';
|
116
|
+
this._contentNode.appendChild(this._content);
|
117
|
+
}
|
118
|
+
},
|
119
|
+
|
120
|
+
_updateLayout: function () {
|
121
|
+
this._container.style.width = '';
|
122
|
+
this._container.style.whiteSpace = 'nowrap';
|
123
|
+
|
124
|
+
var width = this._container.offsetWidth;
|
125
|
+
|
126
|
+
this._container.style.width = (width > this.options.maxWidth ?
|
127
|
+
this.options.maxWidth : (width < this.options.minWidth ? this.options.minWidth : width)) + 'px';
|
128
|
+
this._container.style.whiteSpace = '';
|
129
|
+
|
130
|
+
this._containerWidth = this._container.offsetWidth;
|
131
|
+
},
|
132
|
+
|
133
|
+
_updatePosition: function () {
|
134
|
+
var pos = this._map.latLngToLayerPoint(this._latlng);
|
135
|
+
|
136
|
+
this._containerBottom = -pos.y - this.options.offset.y;
|
137
|
+
this._containerLeft = pos.x - Math.round(this._containerWidth / 2) + this.options.offset.x;
|
138
|
+
|
139
|
+
this._container.style.bottom = this._containerBottom + 'px';
|
140
|
+
this._container.style.left = this._containerLeft + 'px';
|
141
|
+
},
|
142
|
+
|
143
|
+
_adjustPan: function () {
|
144
|
+
if (!this.options.autoPan) {
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
|
148
|
+
var containerHeight = this._container.offsetHeight,
|
149
|
+
layerPos = new L.Point(
|
150
|
+
this._containerLeft,
|
151
|
+
-containerHeight - this._containerBottom),
|
152
|
+
containerPos = this._map.layerPointToContainerPoint(layerPos),
|
153
|
+
adjustOffset = new L.Point(0, 0),
|
154
|
+
padding = this.options.autoPanPadding,
|
155
|
+
size = this._map.getSize();
|
156
|
+
|
157
|
+
if (containerPos.x < 0) {
|
158
|
+
adjustOffset.x = containerPos.x - padding.x;
|
159
|
+
}
|
160
|
+
if (containerPos.x + this._containerWidth > size.x) {
|
161
|
+
adjustOffset.x = containerPos.x + this._containerWidth - size.x + padding.x;
|
162
|
+
}
|
163
|
+
if (containerPos.y < 0) {
|
164
|
+
adjustOffset.y = containerPos.y - padding.y;
|
165
|
+
}
|
166
|
+
if (containerPos.y + containerHeight > size.y) {
|
167
|
+
adjustOffset.y = containerPos.y + containerHeight - size.y + padding.y;
|
168
|
+
}
|
169
|
+
|
170
|
+
if (adjustOffset.x || adjustOffset.y) {
|
171
|
+
this._map.panBy(adjustOffset);
|
172
|
+
}
|
173
|
+
},
|
174
|
+
|
175
|
+
_onCloseButtonClick: function (e) {
|
176
|
+
this._close();
|
177
|
+
L.DomEvent.stop(e);
|
178
|
+
}
|
179
|
+
});
|