- getEvents: function () {
- var events = {
- viewreset: this._reset,
- zoom: this._onZoom,
- moveend: this._update
- };
- if (this._zoomAnimated) {
- events.zoomanim = this._onAnimZoom;
- }
- return events;
- },
-
- _onAnimZoom: function (ev) {
- this._updateTransform(ev.center, ev.zoom);
- },
-
- _onZoom: function () {
- this._updateTransform(this._map.getCenter(), this._map.getZoom());
- },
-
- _updateTransform: function (center, zoom) {
- var scale = this._map.getZoomScale(zoom, this._zoom),
- position = L.DomUtil.getPosition(this._container),
- viewHalf = this._map.getSize().multiplyBy(0.5 + this.options.padding),
- currentCenterPoint = this._map.project(this._center, zoom),
- destCenterPoint = this._map.project(center, zoom),
- centerOffset = destCenterPoint.subtract(currentCenterPoint),
-
- topLeftOffset = viewHalf.multiplyBy(-scale).add(position).add(viewHalf).subtract(centerOffset);
-
- if (L.Browser.any3d) {
- L.DomUtil.setTransform(this._container, topLeftOffset, scale);
- } else {
- L.DomUtil.setPosition(this._container, topLeftOffset);
- }
- },
-
- _reset: function () {
- this._update();
- this._updateTransform(this._center, this._zoom);
- },
-
- _update: function () {
- // Update pixel bounds of renderer container (for positioning/sizing/clipping later)
- // Subclasses are responsible of firing the 'update' event.
- var p = this.options.padding,
- size = this._map.getSize(),
- min = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round();
-
- this._bounds = new L.Bounds(min, min.add(size.multiplyBy(1 + p * 2)).round());
-
- this._center = this._map.getCenter();
- this._zoom = this._map.getZoom();
- }
-});
-
-
-L.Map.include({
- // @namespace Map; @method getRenderer(layer: Path): Renderer
- // Returns the instance of `Renderer` that should be used to render the given
- // `Path`. It will ensure that the `renderer` options of the map and paths
- // are respected, and that the renderers do exist on the map.
- getRenderer: function (layer) {
- // @namespace Path; @option renderer: Renderer
- // Use this specific instance of `Renderer` for this path. Takes
- // precedence over the map's [default renderer](#map-renderer).
- var renderer = layer.options.renderer || this._getPaneRenderer(layer.options.pane) || this.options.renderer || this._renderer;
-
- if (!renderer) {
- // @namespace Map; @option preferCanvas: Boolean = false
- // Whether `Path`s should be rendered on a `Canvas` renderer.
- // By default, all `Path`s are rendered in a `SVG` renderer.
- renderer = this._renderer = (this.options.preferCanvas && L.canvas()) || L.svg();
- }
-
- if (!this.hasLayer(renderer)) {
- this.addLayer(renderer);
- }
- return renderer;
- },
-
- _getPaneRenderer: function (name) {
- if (name === 'overlayPane' || name === undefined) {
- return false;
- }
-
- var renderer = this._paneRenderers[name];
- if (renderer === undefined) {
- renderer = (L.SVG && L.svg({pane: name})) || (L.Canvas && L.canvas({pane: name}));
- this._paneRenderers[name] = renderer;
- }
- return renderer;
- }
-});
-
-
-
-/*
- * @class Path
- * @aka L.Path
- * @inherits Interactive layer
- *
- * An abstract class that contains options and constants shared between vector
- * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.
- */
-
-L.Path = L.Layer.extend({
-
- // @section
- // @aka Path options
- options: {
- // @option stroke: Boolean = true
- // Whether to draw stroke along the path. Set it to `false` to disable borders on polygons or circles.
- stroke: true,
-
- // @option color: String = '#3388ff'
- // Stroke color
- color: '#3388ff',
-
- // @option weight: Number = 3
- // Stroke width in pixels
- weight: 3,
-
- // @option opacity: Number = 1.0
- // Stroke opacity
- opacity: 1,
-
- // @option lineCap: String= 'round'
- // A string that defines [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap) of the stroke.
- lineCap: 'round',
-
- // @option lineJoin: String = 'round'
- // A string that defines [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin) of the stroke.
- lineJoin: 'round',
-
- // @option dashArray: String = null
- // A string that defines the stroke [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray). Doesn't work on `Canvas`-powered layers in [some old browsers](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/setLineDash#Browser_compatibility).
- dashArray: null,
-
- // @option dashOffset: String = null
- // A string that defines the [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset). Doesn't work on `Canvas`-powered layers in [some old browsers](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/setLineDash#Browser_compatibility).
- dashOffset: null,
-
- // @option fill: Boolean = depends
- // Whether to fill the path with color. Set it to `false` to disable filling on polygons or circles.
- fill: false,
-
- // @option fillColor: String = *
- // Fill color. Defaults to the value of the [`color`](#path-color) option
- fillColor: null,
-
- // @option fillOpacity: Number = 0.2
- // Fill opacity.
- fillOpacity: 0.2,
-
- // @option fillRule: String = 'evenodd'
- // A string that defines [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule) is determined.
- fillRule: 'evenodd',
-
- // className: '',
-
- // Option inherited from "Interactive layer" abstract class
- interactive: true
- },
-
- beforeAdd: function (map) {
- // Renderer is set here because we need to call renderer.getEvents
- // before this.getEvents.
- this._renderer = map.getRenderer(this);
- },
-
- onAdd: function () {
- this._renderer._initPath(this);
- this._reset();
- this._renderer._addPath(this);
- this._renderer.on('update', this._update, this);
- },
-
- onRemove: function () {
- this._renderer._removePath(this);
- this._renderer.off('update', this._update, this);
- },
-
- getEvents: function () {
- return {
- zoomend: this._project,
- viewreset: this._reset
- };
- },
-
- // @method redraw(): this
- // Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.
- redraw: function () {
- if (this._map) {
- this._renderer._updatePath(this);
- }
- return this;
- },
-
- // @method setStyle(style: Path options): this
- // Changes the appearance of a Path based on the options in the `Path options` object.
- setStyle: function (style) {
- L.setOptions(this, style);
- if (this._renderer) {
- this._renderer._updateStyle(this);
- }
- return this;
- },
-
- // @method bringToFront(): this
- // Brings the layer to the top of all path layers.
- bringToFront: function () {
- if (this._renderer) {
- this._renderer._bringToFront(this);
- }
- return this;
- },
-
- // @method bringToBack(): this
- // Brings the layer to the bottom of all path layers.
- bringToBack: function () {
- if (this._renderer) {
- this._renderer._bringToBack(this);
- }
- return this;
- },
-
- getElement: function () {
- return this._path;
- },
-
- _reset: function () {
- // defined in children classes
- this._project();
- this._update();
- },
-
- _clickTolerance: function () {
- // used when doing hit detection for Canvas layers
- return (this.options.stroke ? this.options.weight / 2 : 0) + (L.Browser.touch ? 10 : 0);
- }
-});
-
-
-
-/*
- * @namespace LineUtil
- *
- * Various utility functions for polyine points processing, used by Leaflet internally to make polylines lightning-fast.
- */
-
-L.LineUtil = {
-
- // Simplify polyline with vertex reduction and Douglas-Peucker simplification.
- // Improves rendering performance dramatically by lessening the number of points to draw.
-
- // @function simplify(points: Point[], tolerance: Number): Point[]
- // Dramatically reduces the number of points in a polyline while retaining
- // its shape and returns a new array of simplified points, using the
- // [Douglas-Peucker algorithm](http://en.wikipedia.org/wiki/Douglas-Peucker_algorithm).
- // Used for a huge performance boost when processing/displaying Leaflet polylines for
- // each zoom level and also reducing visual noise. tolerance affects the amount of
- // simplification (lesser value means higher quality but slower and with more points).
- // Also released as a separated micro-library [Simplify.js](http://mourner.github.com/simplify-js/).
- simplify: function (points, tolerance) {
- if (!tolerance || !points.length) {
- return points.slice();
- }
-
- var sqTolerance = tolerance * tolerance;
-
- // stage 1: vertex reduction
- points = this._reducePoints(points, sqTolerance);
-
- // stage 2: Douglas-Peucker simplification
- points = this._simplifyDP(points, sqTolerance);
-
- return points;
- },
-
- // @function pointToSegmentDistance(p: Point, p1: Point, p2: Point): Number
- // Returns the distance between point `p` and segment `p1` to `p2`.
- pointToSegmentDistance: function (p, p1, p2) {
- return Math.sqrt(this._sqClosestPointOnSegment(p, p1, p2, true));
- },
-
- // @function closestPointOnSegment(p: Point, p1: Point, p2: Point): Number
- // Returns the closest point from a point `p` on a segment `p1` to `p2`.
- closestPointOnSegment: function (p, p1, p2) {
- return this._sqClosestPointOnSegment(p, p1, p2);
- },
-
- // Douglas-Peucker simplification, see http://en.wikipedia.org/wiki/Douglas-Peucker_algorithm
- _simplifyDP: function (points, sqTolerance) {
-
- var len = points.length,
- ArrayConstructor = typeof Uint8Array !== undefined + '' ? Uint8Array : Array,
- markers = new ArrayConstructor(len);
-
- markers[0] = markers[len - 1] = 1;
-
- this._simplifyDPStep(points, markers, sqTolerance, 0, len - 1);
-
- var i,
- newPoints = [];
-
- for (i = 0; i < len; i++) {
- if (markers[i]) {
- newPoints.push(points[i]);
- }
- }
-
- return newPoints;
- },
-
- _simplifyDPStep: function (points, markers, sqTolerance, first, last) {
-
- var maxSqDist = 0,
- index, i, sqDist;
-
- for (i = first + 1; i <= last - 1; i++) {
- sqDist = this._sqClosestPointOnSegment(points[i], points[first], points[last], true);
-
- if (sqDist > maxSqDist) {
- index = i;
- maxSqDist = sqDist;
- }
- }
-
- if (maxSqDist > sqTolerance) {
- markers[index] = 1;
-
- this._simplifyDPStep(points, markers, sqTolerance, first, index);
- this._simplifyDPStep(points, markers, sqTolerance, index, last);
- }
- },
-
- // reduce points that are too close to each other to a single point
- _reducePoints: function (points, sqTolerance) {
- var reducedPoints = [points[0]];
-
- for (var i = 1, prev = 0, len = points.length; i < len; i++) {
- if (this._sqDist(points[i], points[prev]) > sqTolerance) {
- reducedPoints.push(points[i]);
- prev = i;
- }
- }
- if (prev < len - 1) {
- reducedPoints.push(points[len - 1]);
- }
- return reducedPoints;
- },
-
-
- // @function clipSegment(a: Point, b: Point, bounds: Bounds, useLastCode?: Boolean, round?: Boolean): Point[]|Boolean
- // Clips the segment a to b by rectangular bounds with the
- // [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm)
- // (modifying the segment points directly!). Used by Leaflet to only show polyline
- // points that are on the screen or near, increasing performance.
- clipSegment: function (a, b, bounds, useLastCode, round) {
- var codeA = useLastCode ? this._lastCode : this._getBitCode(a, bounds),
- codeB = this._getBitCode(b, bounds),
-
- codeOut, p, newCode;
-
- // save 2nd code to avoid calculating it on the next segment
- this._lastCode = codeB;
-
- while (true) {
- // if a,b is inside the clip window (trivial accept)
- if (!(codeA | codeB)) {
- return [a, b];
- }
-
- // if a,b is outside the clip window (trivial reject)
- if (codeA & codeB) {
- return false;
- }
-
- // other cases
- codeOut = codeA || codeB;
- p = this._getEdgeIntersection(a, b, codeOut, bounds, round);
- newCode = this._getBitCode(p, bounds);
-
- if (codeOut === codeA) {
- a = p;
- codeA = newCode;
- } else {
- b = p;
- codeB = newCode;
- }
- }
- },
-
- _getEdgeIntersection: function (a, b, code, bounds, round) {
- var dx = b.x - a.x,
- dy = b.y - a.y,
- min = bounds.min,
- max = bounds.max,
- x, y;
-
- if (code & 8) { // top
- x = a.x + dx * (max.y - a.y) / dy;
- y = max.y;
-
- } else if (code & 4) { // bottom
- x = a.x + dx * (min.y - a.y) / dy;
- y = min.y;
-
- } else if (code & 2) { // right
- x = max.x;
- y = a.y + dy * (max.x - a.x) / dx;
-
- } else if (code & 1) { // left
- x = min.x;
- y = a.y + dy * (min.x - a.x) / dx;
- }
-
- return new L.Point(x, y, round);
- },
-
- _getBitCode: function (p, bounds) {
- var code = 0;
-
- if (p.x < bounds.min.x) { // left
- code |= 1;
- } else if (p.x > bounds.max.x) { // right
- code |= 2;
- }
-
- if (p.y < bounds.min.y) { // bottom
- code |= 4;
- } else if (p.y > bounds.max.y) { // top
- code |= 8;
- }
-
- return code;
- },
-
- // square distance (to avoid unnecessary Math.sqrt calls)
- _sqDist: function (p1, p2) {
- var dx = p2.x - p1.x,
- dy = p2.y - p1.y;
- return dx * dx + dy * dy;
- },
-
- // return closest point on segment or distance to that point
- _sqClosestPointOnSegment: function (p, p1, p2, sqDist) {
- var x = p1.x,
- y = p1.y,
- dx = p2.x - x,
- dy = p2.y - y,
- dot = dx * dx + dy * dy,
- t;
-
- if (dot > 0) {
- t = ((p.x - x) * dx + (p.y - y) * dy) / dot;
-
- if (t > 1) {
- x = p2.x;
- y = p2.y;
- } else if (t > 0) {
- x += dx * t;
- y += dy * t;
- }
- }
-
- dx = p.x - x;
- dy = p.y - y;
-
- return sqDist ? dx * dx + dy * dy : new L.Point(x, y);
- }
-};
-
-
-
-/*
- * @class Polyline
- * @aka L.Polyline
- * @inherits Path
- *
- * A class for drawing polyline overlays on a map. Extends `Path`.
- *
- * @example
- *
- * ```js
- * // create a red polyline from an array of LatLng points
- * var latlngs = [
- * [-122.68, 45.51],
- * [-122.43, 37.77],
- * [-118.2, 34.04]
- * ];
- *
- * var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);
- *
- * // zoom the map to the polyline
- * map.fitBounds(polyline.getBounds());
- * ```
- *
- * You can also pass a multi-dimensional array to represent a `MultiPolyline` shape:
- *
- * ```js
- * // create a red polyline from an array of arrays of LatLng points
- * var latlngs = [
- * [[-122.68, 45.51],
- * [-122.43, 37.77],
- * [-118.2, 34.04]],
- * [[-73.91, 40.78],
- * [-87.62, 41.83],
- * [-96.72, 32.76]]
- * ];
- * ```
- */
-
-L.Polyline = L.Path.extend({
-
- // @section
- // @aka Polyline options
- options: {
- // @option smoothFactor: Number = 1.0
- // How much to simplify the polyline on each zoom level. More means
- // better performance and smoother look, and less means more accurate representation.
- smoothFactor: 1.0,
-
- // @option noClip: Boolean = false
- // Disable polyline clipping.
- noClip: false
- },
-
- initialize: function (latlngs, options) {
- L.setOptions(this, options);
- this._setLatLngs(latlngs);
- },
-
- // @method getLatLngs(): LatLng[]
- // Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.
- getLatLngs: function () {
- return this._latlngs;
- },
-
- // @method setLatLngs(latlngs: LatLng[]): this
- // Replaces all the points in the polyline with the given array of geographical points.
- setLatLngs: function (latlngs) {
- this._setLatLngs(latlngs);
- return this.redraw();
- },
-
- // @method isEmpty(): Boolean
- // Returns `true` if the Polyline has no LatLngs.
- isEmpty: function () {
- return !this._latlngs.length;
- },
-
- closestLayerPoint: function (p) {
- var minDistance = Infinity,
- minPoint = null,
- closest = L.LineUtil._sqClosestPointOnSegment,
- p1, p2;
-
- for (var j = 0, jLen = this._parts.length; j < jLen; j++) {
- var points = this._parts[j];
-
- for (var i = 1, len = points.length; i < len; i++) {
- p1 = points[i - 1];
- p2 = points[i];
-
- var sqDist = closest(p, p1, p2, true);
-
- if (sqDist < minDistance) {
- minDistance = sqDist;
- minPoint = closest(p, p1, p2);
- }
- }
- }
- if (minPoint) {
- minPoint.distance = Math.sqrt(minDistance);
- }
- return minPoint;
- },
-
- // @method getCenter(): LatLng
- // Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the polyline.
- getCenter: function () {
- // throws error when not yet added to map as this center calculation requires projected coordinates
- if (!this._map) {
- throw new Error('Must add layer to map before using getCenter()');
- }
-
- var i, halfDist, segDist, dist, p1, p2, ratio,
- points = this._rings[0],
- len = points.length;
-
- if (!len) { return null; }
-
- // polyline centroid algorithm; only uses the first ring if there are multiple
-
- for (i = 0, halfDist = 0; i < len - 1; i++) {
- halfDist += points[i].distanceTo(points[i + 1]) / 2;
- }
-
- // The line is so small in the current view that all points are on the same pixel.
- if (halfDist === 0) {
- return this._map.layerPointToLatLng(points[0]);
- }
-
- for (i = 0, dist = 0; i < len - 1; i++) {
- p1 = points[i];
- p2 = points[i + 1];
- segDist = p1.distanceTo(p2);
- dist += segDist;
-
- if (dist > halfDist) {
- ratio = (dist - halfDist) / segDist;
- return this._map.layerPointToLatLng([
- p2.x - ratio * (p2.x - p1.x),
- p2.y - ratio * (p2.y - p1.y)
- ]);
- }
- }
- },
-
- // @method getBounds(): LatLngBounds
- // Returns the `LatLngBounds` of the path.
- getBounds: function () {
- return this._bounds;
- },
-
- // @method addLatLng(latlng: LatLng, latlngs? LatLng[]): this
- // Adds a given point to the polyline. By default, adds to the first ring of
- // the polyline in case of a multi-polyline, but can be overridden by passing
- // a specific ring as a LatLng array (that you can earlier access with [`getLatLngs`](#polyline-getlatlngs)).
- addLatLng: function (latlng, latlngs) {
- latlngs = latlngs || this._defaultShape();
- latlng = L.latLng(latlng);
- latlngs.push(latlng);
- this._bounds.extend(latlng);
- return this.redraw();
- },
-
- _setLatLngs: function (latlngs) {
- this._bounds = new L.LatLngBounds();
- this._latlngs = this._convertLatLngs(latlngs);
- },
-
- _defaultShape: function () {
- return L.Polyline._flat(this._latlngs) ? this._latlngs : this._latlngs[0];
- },
-
- // recursively convert latlngs input into actual LatLng instances; calculate bounds along the way
- _convertLatLngs: function (latlngs) {
- var result = [],
- flat = L.Polyline._flat(latlngs);
-
- for (var i = 0, len = latlngs.length; i < len; i++) {
- if (flat) {
- result[i] = L.latLng(latlngs[i]);
- this._bounds.extend(result[i]);
- } else {
- result[i] = this._convertLatLngs(latlngs[i]);
- }
- }
-
- return result;
- },
-
- _project: function () {
- var pxBounds = new L.Bounds();
- this._rings = [];
- this._projectLatlngs(this._latlngs, this._rings, pxBounds);
-
- var w = this._clickTolerance(),
- p = new L.Point(w, w);
-
- if (this._bounds.isValid() && pxBounds.isValid()) {
- pxBounds.min._subtract(p);
- pxBounds.max._add(p);
- this._pxBounds = pxBounds;
- }
- },
-
- // recursively turns latlngs into a set of rings with projected coordinates
- _projectLatlngs: function (latlngs, result, projectedBounds) {
- var flat = latlngs[0] instanceof L.LatLng,
- len = latlngs.length,
- i, ring;
-
- if (flat) {
- ring = [];
- for (i = 0; i < len; i++) {
- ring[i] = this._map.latLngToLayerPoint(latlngs[i]);
- projectedBounds.extend(ring[i]);
- }
- result.push(ring);
- } else {
- for (i = 0; i < len; i++) {
- this._projectLatlngs(latlngs[i], result, projectedBounds);
- }
- }
- },
-
- // clip polyline by renderer bounds so that we have less to render for performance
- _clipPoints: function () {
- var bounds = this._renderer._bounds;
-
- this._parts = [];
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) {
- return;
- }
-
- if (this.options.noClip) {
- this._parts = this._rings;
- return;
- }
-
- var parts = this._parts,
- i, j, k, len, len2, segment, points;
-
- for (i = 0, k = 0, len = this._rings.length; i < len; i++) {
- points = this._rings[i];
-
- for (j = 0, len2 = points.length; j < len2 - 1; j++) {
- segment = L.LineUtil.clipSegment(points[j], points[j + 1], bounds, j, true);
-
- if (!segment) { continue; }
-
- parts[k] = parts[k] || [];
- parts[k].push(segment[0]);
-
- // if segment goes out of screen, or it's the last one, it's the end of the line part
- if ((segment[1] !== points[j + 1]) || (j === len2 - 2)) {
- parts[k].push(segment[1]);
- k++;
- }
- }
- }
- },
-
- // simplify each clipped part of the polyline for performance
- _simplifyPoints: function () {
- var parts = this._parts,
- tolerance = this.options.smoothFactor;
-
- for (var i = 0, len = parts.length; i < len; i++) {
- parts[i] = L.LineUtil.simplify(parts[i], tolerance);
- }
- },
-
- _update: function () {
- if (!this._map) { return; }
-
- this._clipPoints();
- this._simplifyPoints();
- this._updatePath();
- },
-
- _updatePath: function () {
- this._renderer._updatePoly(this);
- }
-});
-
-// @factory L.polyline(latlngs: LatLng[], options?: Polyline options)
-// Instantiates a polyline object given an array of geographical points and
-// optionally an options object. You can create a `Polyline` object with
-// multiple separate lines (`MultiPolyline`) by passing an array of arrays
-// of geographic points.
-L.polyline = function (latlngs, options) {
- return new L.Polyline(latlngs, options);
-};
-
-L.Polyline._flat = function (latlngs) {
- // true if it's a flat array of latlngs; false if nested
- return !L.Util.isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined');
-};
-
-
-
-/*
- * @namespace PolyUtil
- * Various utility functions for polygon geometries.
- */
-
-L.PolyUtil = {};
-
-/* @function clipPolygon(points: Point[], bounds: Bounds, round?: Boolean): Point[]
- * Clips the polygon geometry defined by the given `points` by the given bounds (using the [Sutherland-Hodgeman algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm)).
- * Used by Leaflet to only show polygon points that are on the screen or near, increasing
- * performance. Note that polygon points needs different algorithm for clipping
- * than polyline, so there's a seperate method for it.
- */
-L.PolyUtil.clipPolygon = function (points, bounds, round) {
- var clippedPoints,
- edges = [1, 4, 2, 8],
- i, j, k,
- a, b,
- len, edge, p,
- lu = L.LineUtil;
-
- for (i = 0, len = points.length; i < len; i++) {
- points[i]._code = lu._getBitCode(points[i], bounds);
- }
-
- // for each edge (left, bottom, right, top)
- for (k = 0; k < 4; k++) {
- edge = edges[k];
- clippedPoints = [];
-
- for (i = 0, len = points.length, j = len - 1; i < len; j = i++) {
- a = points[i];
- b = points[j];
-
- // if a is inside the clip window
- if (!(a._code & edge)) {
- // if b is outside the clip window (a->b goes out of screen)
- if (b._code & edge) {
- p = lu._getEdgeIntersection(b, a, edge, bounds, round);
- p._code = lu._getBitCode(p, bounds);
- clippedPoints.push(p);
- }
- clippedPoints.push(a);
-
- // else if b is inside the clip window (a->b enters the screen)
- } else if (!(b._code & edge)) {
- p = lu._getEdgeIntersection(b, a, edge, bounds, round);
- p._code = lu._getBitCode(p, bounds);
- clippedPoints.push(p);
- }
- }
- points = clippedPoints;
- }
-
- return points;
-};
-
-
-
-/*
- * @class Polygon
- * @aka L.Polygon
- * @inherits Polyline
- *
- * A class for drawing polygon overlays on a map. Extends `Polyline`.
- *
- * Note that points you pass when creating a polygon shouldn't have an additional last point equal to the first one — it's better to filter out such points.
- *
- *
- * @example
- *
- * ```js
- * // create a red polygon from an array of LatLng points
- * var latlngs = [[-111.03, 41],[-111.04, 45],[-104.05, 45],[-104.05, 41]];
- *
- * var polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
- *
- * // zoom the map to the polygon
- * map.fitBounds(polygon.getBounds());
- * ```
- *
- * You can also pass an array of arrays of latlngs, with the first array representing the outer shape and the other arrays representing holes in the outer shape:
- *
- * ```js
- * var latlngs = [
- * [[-111.03, 41],[-111.04, 45],[-104.05, 45],[-104.05, 41]], // outer ring
- * [[-108.58,37.29],[-108.58,40.71],[-102.50,40.71],[-102.50,37.29]] // hole
- * ];
- * ```
- *
- * Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.
- *
- * ```js
- * var latlngs = [
- * [ // first polygon
- * [[-111.03, 41],[-111.04, 45],[-104.05, 45],[-104.05, 41]], // outer ring
- * [[-108.58,37.29],[-108.58,40.71],[-102.50,40.71],[-102.50,37.29]] // hole
- * ],
- * [ // second polygon
- * [[-109.05, 37],[-109.03, 41],[-102.05, 41],[-102.04, 37],[-109.05, 38]]
- * ]
- * ];
- * ```
- */