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,51 @@
|
|
1
|
+
|
2
|
+
L.Projection.Mercator = {
|
3
|
+
MAX_LATITUDE: 85.0840591556,
|
4
|
+
|
5
|
+
R_MINOR: 6356752.3142,
|
6
|
+
R_MAJOR: 6378137,
|
7
|
+
|
8
|
+
project: function (/*LatLng*/ latlng) /*-> Point*/ {
|
9
|
+
var d = L.LatLng.DEG_TO_RAD,
|
10
|
+
max = this.MAX_LATITUDE,
|
11
|
+
lat = Math.max(Math.min(max, latlng.lat), -max),
|
12
|
+
r = this.R_MAJOR,
|
13
|
+
r2 = this.R_MINOR,
|
14
|
+
x = latlng.lng * d * r,
|
15
|
+
y = lat * d,
|
16
|
+
tmp = r2 / r,
|
17
|
+
eccent = Math.sqrt(1.0 - tmp * tmp),
|
18
|
+
con = eccent * Math.sin(y);
|
19
|
+
|
20
|
+
con = Math.pow((1 - con) / (1 + con), eccent * 0.5);
|
21
|
+
|
22
|
+
var ts = Math.tan(0.5 * ((Math.PI * 0.5) - y)) / con;
|
23
|
+
y = -r2 * Math.log(ts);
|
24
|
+
|
25
|
+
return new L.Point(x, y);
|
26
|
+
},
|
27
|
+
|
28
|
+
unproject: function (/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ {
|
29
|
+
var d = L.LatLng.RAD_TO_DEG,
|
30
|
+
r = this.R_MAJOR,
|
31
|
+
r2 = this.R_MINOR,
|
32
|
+
lng = point.x * d / r,
|
33
|
+
tmp = r2 / r,
|
34
|
+
eccent = Math.sqrt(1 - (tmp * tmp)),
|
35
|
+
ts = Math.exp(- point.y / r2),
|
36
|
+
phi = (Math.PI / 2) - 2 * Math.atan(ts),
|
37
|
+
numIter = 15,
|
38
|
+
tol = 1e-7,
|
39
|
+
i = numIter,
|
40
|
+
dphi = 0.1,
|
41
|
+
con;
|
42
|
+
|
43
|
+
while ((Math.abs(dphi) > tol) && (--i > 0)) {
|
44
|
+
con = eccent * Math.sin(phi);
|
45
|
+
dphi = (Math.PI / 2) - 2 * Math.atan(ts * Math.pow((1.0 - con) / (1.0 + con), 0.5 * eccent)) - phi;
|
46
|
+
phi += dphi;
|
47
|
+
}
|
48
|
+
|
49
|
+
return new L.LatLng(phi * d, lng, unbounded);
|
50
|
+
}
|
51
|
+
};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
L.Projection.SphericalMercator = {
|
3
|
+
MAX_LATITUDE: 85.0511287798,
|
4
|
+
|
5
|
+
project: function (/*LatLng*/ latlng) /*-> Point*/ {
|
6
|
+
var d = L.LatLng.DEG_TO_RAD,
|
7
|
+
max = this.MAX_LATITUDE,
|
8
|
+
lat = Math.max(Math.min(max, latlng.lat), -max),
|
9
|
+
x = latlng.lng * d,
|
10
|
+
y = lat * d;
|
11
|
+
y = Math.log(Math.tan((Math.PI / 4) + (y / 2)));
|
12
|
+
|
13
|
+
return new L.Point(x, y);
|
14
|
+
},
|
15
|
+
|
16
|
+
unproject: function (/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ {
|
17
|
+
var d = L.LatLng.RAD_TO_DEG,
|
18
|
+
lng = point.x * d,
|
19
|
+
lat = (2 * Math.atan(Math.exp(point.y)) - (Math.PI / 2)) * d;
|
20
|
+
|
21
|
+
return new L.LatLng(lat, lng, unbounded);
|
22
|
+
}
|
23
|
+
};
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/*
|
2
|
+
* L.Bounds represents a rectangular area on the screen in pixel coordinates.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Bounds = L.Class.extend({
|
6
|
+
initialize: function (min, max) { //(Point, Point) or Point[]
|
7
|
+
if (!min) {
|
8
|
+
return;
|
9
|
+
}
|
10
|
+
var points = (min instanceof Array ? min : [min, max]);
|
11
|
+
for (var i = 0, len = points.length; i < len; i++) {
|
12
|
+
this.extend(points[i]);
|
13
|
+
}
|
14
|
+
},
|
15
|
+
|
16
|
+
// extend the bounds to contain the given point
|
17
|
+
extend: function (/*Point*/ point) {
|
18
|
+
if (!this.min && !this.max) {
|
19
|
+
this.min = new L.Point(point.x, point.y);
|
20
|
+
this.max = new L.Point(point.x, point.y);
|
21
|
+
} else {
|
22
|
+
this.min.x = Math.min(point.x, this.min.x);
|
23
|
+
this.max.x = Math.max(point.x, this.max.x);
|
24
|
+
this.min.y = Math.min(point.y, this.min.y);
|
25
|
+
this.max.y = Math.max(point.y, this.max.y);
|
26
|
+
}
|
27
|
+
},
|
28
|
+
|
29
|
+
getCenter: function (round)/*->Point*/ {
|
30
|
+
return new L.Point(
|
31
|
+
(this.min.x + this.max.x) / 2,
|
32
|
+
(this.min.y + this.max.y) / 2, round);
|
33
|
+
},
|
34
|
+
|
35
|
+
contains: function (/*Bounds or Point*/ obj)/*->Boolean*/ {
|
36
|
+
var min, max;
|
37
|
+
|
38
|
+
if (obj instanceof L.Bounds) {
|
39
|
+
min = obj.min;
|
40
|
+
max = obj.max;
|
41
|
+
} else {
|
42
|
+
min = max = obj;
|
43
|
+
}
|
44
|
+
|
45
|
+
return (min.x >= this.min.x) &&
|
46
|
+
(max.x <= this.max.x) &&
|
47
|
+
(min.y >= this.min.y) &&
|
48
|
+
(max.y <= this.max.y);
|
49
|
+
}
|
50
|
+
});
|
@@ -0,0 +1,194 @@
|
|
1
|
+
/*
|
2
|
+
* L.LineUtil contains different utility functions for line segments
|
3
|
+
* and polylines (clipping, simplification, distances, etc.)
|
4
|
+
*/
|
5
|
+
|
6
|
+
L.LineUtil = {
|
7
|
+
|
8
|
+
// Simplify polyline with vertex reduction and Douglas-Peucker simplification.
|
9
|
+
// Improves rendering performance dramatically by lessening the number of points to draw.
|
10
|
+
|
11
|
+
simplify: function (/*Point[]*/ points, /*Number*/ tolerance) {
|
12
|
+
if (!tolerance || !points.length) {
|
13
|
+
return points.slice();
|
14
|
+
}
|
15
|
+
|
16
|
+
// stage 1: vertex reduction
|
17
|
+
points = this.reducePoints(points, tolerance);
|
18
|
+
|
19
|
+
// stage 2: Douglas-Peucker simplification
|
20
|
+
points = this.simplifyDP(points, tolerance);
|
21
|
+
|
22
|
+
return points;
|
23
|
+
},
|
24
|
+
|
25
|
+
// distance from a point to a segment between two points
|
26
|
+
pointToSegmentDistance: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
|
27
|
+
return Math.sqrt(this._sqPointToSegmentDist(p, p1, p2));
|
28
|
+
},
|
29
|
+
|
30
|
+
closestPointOnSegment: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
|
31
|
+
var point = this._sqClosestPointOnSegment(p, p1, p2);
|
32
|
+
point.distance = Math.sqrt(point._sqDist);
|
33
|
+
return point;
|
34
|
+
},
|
35
|
+
|
36
|
+
// Douglas-Peucker simplification, see http://en.wikipedia.org/wiki/Douglas-Peucker_algorithm
|
37
|
+
simplifyDP: function (points, tol) {
|
38
|
+
var maxDist2 = 0,
|
39
|
+
index = 0,
|
40
|
+
t2 = tol * tol,
|
41
|
+
len = points.length,
|
42
|
+
i, dist2;
|
43
|
+
|
44
|
+
if (len < 3) {
|
45
|
+
return points;
|
46
|
+
}
|
47
|
+
|
48
|
+
for (i = 0; i < len - 1; i++) {
|
49
|
+
dist2 = this._sqPointToSegmentDist(points[i], points[0], points[len - 1]);
|
50
|
+
if (dist2 > maxDist2) {
|
51
|
+
index = i;
|
52
|
+
maxDist2 = dist2;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
var part1, part2;
|
57
|
+
|
58
|
+
if (maxDist2 >= t2) {
|
59
|
+
part1 = points.slice(0, index);
|
60
|
+
part2 = points.slice(index);
|
61
|
+
|
62
|
+
part1 = this.simplifyDP(part1, tol);
|
63
|
+
part2 = this.simplifyDP(part2, tol);
|
64
|
+
|
65
|
+
return part1.concat(part2);
|
66
|
+
} else {
|
67
|
+
return [points[0], points[len - 1]];
|
68
|
+
}
|
69
|
+
},
|
70
|
+
|
71
|
+
// reduce points that are too close to each other to a single point
|
72
|
+
reducePoints: function (points, tol) {
|
73
|
+
var reducedPoints = [points[0]],
|
74
|
+
t2 = tol * tol;
|
75
|
+
|
76
|
+
for (var i = 1, prev = 0, len = points.length; i < len; i++) {
|
77
|
+
if (this._sqDist(points[i], points[prev]) < t2) {
|
78
|
+
continue;
|
79
|
+
}
|
80
|
+
reducedPoints.push(points[i]);
|
81
|
+
prev = i;
|
82
|
+
}
|
83
|
+
if (prev < len - 1) {
|
84
|
+
reducedPoints.push(points[len - 1]);
|
85
|
+
}
|
86
|
+
return reducedPoints;
|
87
|
+
},
|
88
|
+
|
89
|
+
/*jshint bitwise:false */ // temporarily allow bitwise oprations
|
90
|
+
|
91
|
+
// Cohen-Sutherland line clipping algorithm.
|
92
|
+
// Used to avoid rendering parts of a polyline that are not currently visible.
|
93
|
+
|
94
|
+
clipSegment: function (a, b, bounds, useLastCode) {
|
95
|
+
var min = bounds.min,
|
96
|
+
max = bounds.max;
|
97
|
+
|
98
|
+
var codeA = useLastCode ? this._lastCode : this._getBitCode(a, bounds),
|
99
|
+
codeB = this._getBitCode(b, bounds);
|
100
|
+
|
101
|
+
// save 2nd code to avoid calculating it on the next segment
|
102
|
+
this._lastCode = codeB;
|
103
|
+
|
104
|
+
while (true) {
|
105
|
+
// if a,b is inside the clip window (trivial accept)
|
106
|
+
if (!(codeA | codeB)) {
|
107
|
+
return [a, b];
|
108
|
+
// if a,b is outside the clip window (trivial reject)
|
109
|
+
} else if (codeA & codeB) {
|
110
|
+
return false;
|
111
|
+
// other cases
|
112
|
+
} else {
|
113
|
+
var codeOut = codeA || codeB,
|
114
|
+
p = this._getEdgeIntersection(a, b, codeOut, bounds),
|
115
|
+
newCode = this._getBitCode(p, bounds);
|
116
|
+
|
117
|
+
if (codeOut === codeA) {
|
118
|
+
a = p;
|
119
|
+
codeA = newCode;
|
120
|
+
} else {
|
121
|
+
b = p;
|
122
|
+
codeB = newCode;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
},
|
127
|
+
|
128
|
+
_getEdgeIntersection: function (a, b, code, bounds) {
|
129
|
+
var dx = b.x - a.x,
|
130
|
+
dy = b.y - a.y,
|
131
|
+
min = bounds.min,
|
132
|
+
max = bounds.max;
|
133
|
+
|
134
|
+
if (code & 8) { // top
|
135
|
+
return new L.Point(a.x + dx * (max.y - a.y) / dy, max.y);
|
136
|
+
} else if (code & 4) { // bottom
|
137
|
+
return new L.Point(a.x + dx * (min.y - a.y) / dy, min.y);
|
138
|
+
} else if (code & 2) { // right
|
139
|
+
return new L.Point(max.x, a.y + dy * (max.x - a.x) / dx);
|
140
|
+
} else if (code & 1) { // left
|
141
|
+
return new L.Point(min.x, a.y + dy * (min.x - a.x) / dx);
|
142
|
+
}
|
143
|
+
},
|
144
|
+
|
145
|
+
_getBitCode: function (/*Point*/ p, bounds) {
|
146
|
+
var code = 0;
|
147
|
+
|
148
|
+
if (p.x < bounds.min.x) { // left
|
149
|
+
code |= 1;
|
150
|
+
} else if (p.x > bounds.max.x) { // right
|
151
|
+
code |= 2;
|
152
|
+
}
|
153
|
+
if (p.y < bounds.min.y) { // bottom
|
154
|
+
code |= 4;
|
155
|
+
} else if (p.y > bounds.max.y) { // top
|
156
|
+
code |= 8;
|
157
|
+
}
|
158
|
+
|
159
|
+
return code;
|
160
|
+
},
|
161
|
+
|
162
|
+
/*jshint bitwise:true */
|
163
|
+
|
164
|
+
// square distance (to avoid unnecessary Math.sqrt calls)
|
165
|
+
_sqDist: function (p1, p2) {
|
166
|
+
var dx = p2.x - p1.x,
|
167
|
+
dy = p2.y - p1.y;
|
168
|
+
return dx * dx + dy * dy;
|
169
|
+
},
|
170
|
+
|
171
|
+
// return closest point on segment with attribute _sqDist - square distance to segment
|
172
|
+
_sqClosestPointOnSegment: function (p, p1, p2) {
|
173
|
+
var x2 = p2.x - p1.x,
|
174
|
+
y2 = p2.y - p1.y,
|
175
|
+
apoint = p1;
|
176
|
+
if (x2 || y2) {
|
177
|
+
var dot = (p.x - p1.x) * x2 + (p.y - p1.y) * y2,
|
178
|
+
t = dot / this._sqDist(p1, p2);
|
179
|
+
|
180
|
+
if (t > 1) {
|
181
|
+
apoint = p2;
|
182
|
+
} else if (t > 0) {
|
183
|
+
apoint = new L.Point(p1.x + x2 * t, p1.y + y2 * t);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
apoint._sqDist = this._sqDist(p, apoint);
|
187
|
+
return apoint;
|
188
|
+
},
|
189
|
+
|
190
|
+
// distance from a point to a segment between two points
|
191
|
+
_sqPointToSegmentDist: function (p, p1, p2) {
|
192
|
+
return this._sqClosestPointOnSegment(p, p1, p2)._sqDist;
|
193
|
+
}
|
194
|
+
};
|
@@ -0,0 +1,66 @@
|
|
1
|
+
/*
|
2
|
+
* L.Point represents a point with x and y coordinates.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Point = function (/*Number*/ x, /*Number*/ y, /*Boolean*/ round) {
|
6
|
+
this.x = (round ? Math.round(x) : x);
|
7
|
+
this.y = (round ? Math.round(y) : y);
|
8
|
+
};
|
9
|
+
|
10
|
+
L.Point.prototype = {
|
11
|
+
add: function (point) {
|
12
|
+
return this.clone()._add(point);
|
13
|
+
},
|
14
|
+
|
15
|
+
_add: function (point) {
|
16
|
+
this.x += point.x;
|
17
|
+
this.y += point.y;
|
18
|
+
return this;
|
19
|
+
},
|
20
|
+
|
21
|
+
subtract: function (point) {
|
22
|
+
return this.clone()._subtract(point);
|
23
|
+
},
|
24
|
+
|
25
|
+
// destructive subtract (faster)
|
26
|
+
_subtract: function (point) {
|
27
|
+
this.x -= point.x;
|
28
|
+
this.y -= point.y;
|
29
|
+
return this;
|
30
|
+
},
|
31
|
+
|
32
|
+
divideBy: function (num, round) {
|
33
|
+
return new L.Point(this.x / num, this.y / num, round);
|
34
|
+
},
|
35
|
+
|
36
|
+
multiplyBy: function (num) {
|
37
|
+
return new L.Point(this.x * num, this.y * num);
|
38
|
+
},
|
39
|
+
|
40
|
+
distanceTo: function (point) {
|
41
|
+
var x = point.x - this.x,
|
42
|
+
y = point.y - this.y;
|
43
|
+
return Math.sqrt(x * x + y * y);
|
44
|
+
},
|
45
|
+
|
46
|
+
round: function () {
|
47
|
+
return this.clone()._round();
|
48
|
+
},
|
49
|
+
|
50
|
+
// destructive round
|
51
|
+
_round: function () {
|
52
|
+
this.x = Math.round(this.x);
|
53
|
+
this.y = Math.round(this.y);
|
54
|
+
return this;
|
55
|
+
},
|
56
|
+
|
57
|
+
clone: function () {
|
58
|
+
return new L.Point(this.x, this.y);
|
59
|
+
},
|
60
|
+
|
61
|
+
toString: function () {
|
62
|
+
return 'Point(' +
|
63
|
+
L.Util.formatNum(this.x) + ', ' +
|
64
|
+
L.Util.formatNum(this.y) + ')';
|
65
|
+
}
|
66
|
+
};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
/*
|
2
|
+
* L.PolyUtil contains utilify functions for polygons (clipping, etc.).
|
3
|
+
*/
|
4
|
+
|
5
|
+
/*jshint bitwise:false */ // allow bitwise oprations here
|
6
|
+
|
7
|
+
L.PolyUtil = {};
|
8
|
+
|
9
|
+
/*
|
10
|
+
* Sutherland-Hodgeman polygon clipping algorithm.
|
11
|
+
* Used to avoid rendering parts of a polygon that are not currently visible.
|
12
|
+
*/
|
13
|
+
L.PolyUtil.clipPolygon = function (points, bounds) {
|
14
|
+
var min = bounds.min,
|
15
|
+
max = bounds.max,
|
16
|
+
clippedPoints,
|
17
|
+
edges = [1, 4, 2, 8],
|
18
|
+
i, j, k,
|
19
|
+
a, b,
|
20
|
+
len, edge, p,
|
21
|
+
lu = L.LineUtil;
|
22
|
+
|
23
|
+
for (i = 0, len = points.length; i < len; i++) {
|
24
|
+
points[i]._code = lu._getBitCode(points[i], bounds);
|
25
|
+
}
|
26
|
+
|
27
|
+
// for each edge (left, bottom, right, top)
|
28
|
+
for (k = 0; k < 4; k++) {
|
29
|
+
edge = edges[k];
|
30
|
+
clippedPoints = [];
|
31
|
+
|
32
|
+
for (i = 0, len = points.length, j = len - 1; i < len; j = i++) {
|
33
|
+
a = points[i];
|
34
|
+
b = points[j];
|
35
|
+
|
36
|
+
// if a is inside the clip window
|
37
|
+
if (!(a._code & edge)) {
|
38
|
+
// if b is outside the clip window (a->b goes out of screen)
|
39
|
+
if (b._code & edge) {
|
40
|
+
p = lu._getEdgeIntersection(b, a, edge, bounds);
|
41
|
+
p._code = lu._getBitCode(p, bounds);
|
42
|
+
clippedPoints.push(p);
|
43
|
+
}
|
44
|
+
clippedPoints.push(a);
|
45
|
+
|
46
|
+
// else if b is inside the clip window (a->b enters the screen)
|
47
|
+
} else if (!(b._code & edge)) {
|
48
|
+
p = lu._getEdgeIntersection(b, a, edge, bounds);
|
49
|
+
p._code = lu._getBitCode(p, bounds);
|
50
|
+
clippedPoints.push(p);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
points = clippedPoints;
|
54
|
+
}
|
55
|
+
|
56
|
+
return points;
|
57
|
+
};
|
58
|
+
|
59
|
+
/*jshint bitwise:true */
|