From 3c99fde45db83b531c41c350ed4d0ac2a3c40c62 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:45:13 +0200 Subject: Adding debian version 1.1.0-3. Signed-off-by: Daniel Baumann --- .../leaflet.js/layer/vector/Canvas.js | 465 +++++++++++++++++++++ .../leaflet.js/layer/vector/Circle.js | 113 +++++ .../leaflet.js/layer/vector/CircleMarker.js | 105 +++++ .../leaflet.js/layer/vector/Path.js | 144 +++++++ .../leaflet.js/layer/vector/Polygon.js | 184 ++++++++ .../leaflet.js/layer/vector/Polyline.js | 328 +++++++++++++++ .../leaflet.js/layer/vector/Rectangle.js | 57 +++ .../layer/vector/Renderer.getRenderer.js | 41 ++ .../leaflet.js/layer/vector/Renderer.js | 140 +++++++ .../leaflet.js/layer/vector/SVG.Util.js | 39 ++ .../leaflet.js/layer/vector/SVG.VML.js | 143 +++++++ .../missing-sources/leaflet.js/layer/vector/SVG.js | 220 ++++++++++ .../leaflet.js/layer/vector/index.js | 14 + 13 files changed, 1993 insertions(+) create mode 100644 debian/missing-sources/leaflet.js/layer/vector/Canvas.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/Circle.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/CircleMarker.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/Path.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/Polygon.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/Polyline.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/Rectangle.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/Renderer.getRenderer.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/Renderer.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/SVG.Util.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/SVG.VML.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/SVG.js create mode 100644 debian/missing-sources/leaflet.js/layer/vector/index.js (limited to 'debian/missing-sources/leaflet.js/layer/vector') diff --git a/debian/missing-sources/leaflet.js/layer/vector/Canvas.js b/debian/missing-sources/leaflet.js/layer/vector/Canvas.js new file mode 100644 index 0000000..58d0d97 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/Canvas.js @@ -0,0 +1,465 @@ +import {Renderer} from './Renderer'; +import * as DomUtil from '../../dom/DomUtil'; +import * as DomEvent from '../../dom/DomEvent'; +import * as Browser from '../../core/Browser'; +import * as Util from '../../core/Util'; +import {Bounds} from '../../geometry/Bounds'; + +/* + * @class Canvas + * @inherits Renderer + * @aka L.Canvas + * + * Allows vector layers to be displayed with [``](https://developer.mozilla.org/docs/Web/API/Canvas_API). + * Inherits `Renderer`. + * + * Due to [technical limitations](http://caniuse.com/#search=canvas), Canvas is not + * available in all web browsers, notably IE8, and overlapping geometries might + * not display properly in some edge cases. + * + * @example + * + * Use Canvas by default for all paths in the map: + * + * ```js + * var map = L.map('map', { + * renderer: L.canvas() + * }); + * ``` + * + * Use a Canvas renderer with extra padding for specific vector geometries: + * + * ```js + * var map = L.map('map'); + * var myRenderer = L.canvas({ padding: 0.5 }); + * var line = L.polyline( coordinates, { renderer: myRenderer } ); + * var circle = L.circle( center, { renderer: myRenderer } ); + * ``` + */ + +export var Canvas = Renderer.extend({ + getEvents: function () { + var events = Renderer.prototype.getEvents.call(this); + events.viewprereset = this._onViewPreReset; + return events; + }, + + _onViewPreReset: function () { + // Set a flag so that a viewprereset+moveend+viewreset only updates&redraws once + this._postponeUpdatePaths = true; + }, + + onAdd: function () { + Renderer.prototype.onAdd.call(this); + + // Redraw vectors since canvas is cleared upon removal, + // in case of removing the renderer itself from the map. + this._draw(); + }, + + _initContainer: function () { + var container = this._container = document.createElement('canvas'); + + DomEvent.on(container, 'mousemove', Util.throttle(this._onMouseMove, 32, this), this); + DomEvent.on(container, 'click dblclick mousedown mouseup contextmenu', this._onClick, this); + DomEvent.on(container, 'mouseout', this._handleMouseOut, this); + + this._ctx = container.getContext('2d'); + }, + + _destroyContainer: function () { + delete this._ctx; + DomUtil.remove(this._container); + DomEvent.off(this._container); + delete this._container; + }, + + _updatePaths: function () { + if (this._postponeUpdatePaths) { return; } + + var layer; + this._redrawBounds = null; + for (var id in this._layers) { + layer = this._layers[id]; + layer._update(); + } + this._redraw(); + }, + + _update: function () { + if (this._map._animatingZoom && this._bounds) { return; } + + this._drawnLayers = {}; + + Renderer.prototype._update.call(this); + + var b = this._bounds, + container = this._container, + size = b.getSize(), + m = Browser.retina ? 2 : 1; + + DomUtil.setPosition(container, b.min); + + // set canvas size (also clearing it); use double size on retina + container.width = m * size.x; + container.height = m * size.y; + container.style.width = size.x + 'px'; + container.style.height = size.y + 'px'; + + if (Browser.retina) { + this._ctx.scale(2, 2); + } + + // translate so we use the same path coordinates after canvas element moves + this._ctx.translate(-b.min.x, -b.min.y); + + // Tell paths to redraw themselves + this.fire('update'); + }, + + _reset: function () { + Renderer.prototype._reset.call(this); + + if (this._postponeUpdatePaths) { + this._postponeUpdatePaths = false; + this._updatePaths(); + } + }, + + _initPath: function (layer) { + this._updateDashArray(layer); + this._layers[Util.stamp(layer)] = layer; + + var order = layer._order = { + layer: layer, + prev: this._drawLast, + next: null + }; + if (this._drawLast) { this._drawLast.next = order; } + this._drawLast = order; + this._drawFirst = this._drawFirst || this._drawLast; + }, + + _addPath: function (layer) { + this._requestRedraw(layer); + }, + + _removePath: function (layer) { + var order = layer._order; + var next = order.next; + var prev = order.prev; + + if (next) { + next.prev = prev; + } else { + this._drawLast = prev; + } + if (prev) { + prev.next = next; + } else { + this._drawFirst = next; + } + + delete layer._order; + + delete this._layers[L.stamp(layer)]; + + this._requestRedraw(layer); + }, + + _updatePath: function (layer) { + // Redraw the union of the layer's old pixel + // bounds and the new pixel bounds. + this._extendRedrawBounds(layer); + layer._project(); + layer._update(); + // The redraw will extend the redraw bounds + // with the new pixel bounds. + this._requestRedraw(layer); + }, + + _updateStyle: function (layer) { + this._updateDashArray(layer); + this._requestRedraw(layer); + }, + + _updateDashArray: function (layer) { + if (layer.options.dashArray) { + var parts = layer.options.dashArray.split(','), + dashArray = [], + i; + for (i = 0; i < parts.length; i++) { + dashArray.push(Number(parts[i])); + } + layer.options._dashArray = dashArray; + } + }, + + _requestRedraw: function (layer) { + if (!this._map) { return; } + + this._extendRedrawBounds(layer); + this._redrawRequest = this._redrawRequest || Util.requestAnimFrame(this._redraw, this); + }, + + _extendRedrawBounds: function (layer) { + if (layer._pxBounds) { + var padding = (layer.options.weight || 0) + 1; + this._redrawBounds = this._redrawBounds || new Bounds(); + this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding])); + this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding])); + } + }, + + _redraw: function () { + this._redrawRequest = null; + + if (this._redrawBounds) { + this._redrawBounds.min._floor(); + this._redrawBounds.max._ceil(); + } + + this._clear(); // clear layers in redraw bounds + this._draw(); // draw layers + + this._redrawBounds = null; + }, + + _clear: function () { + var bounds = this._redrawBounds; + if (bounds) { + var size = bounds.getSize(); + this._ctx.clearRect(bounds.min.x, bounds.min.y, size.x, size.y); + } else { + this._ctx.clearRect(0, 0, this._container.width, this._container.height); + } + }, + + _draw: function () { + var layer, bounds = this._redrawBounds; + this._ctx.save(); + if (bounds) { + var size = bounds.getSize(); + this._ctx.beginPath(); + this._ctx.rect(bounds.min.x, bounds.min.y, size.x, size.y); + this._ctx.clip(); + } + + this._drawing = true; + + for (var order = this._drawFirst; order; order = order.next) { + layer = order.layer; + if (!bounds || (layer._pxBounds && layer._pxBounds.intersects(bounds))) { + layer._updatePath(); + } + } + + this._drawing = false; + + this._ctx.restore(); // Restore state before clipping. + }, + + _updatePoly: function (layer, closed) { + if (!this._drawing) { return; } + + var i, j, len2, p, + parts = layer._parts, + len = parts.length, + ctx = this._ctx; + + if (!len) { return; } + + this._drawnLayers[layer._leaflet_id] = layer; + + ctx.beginPath(); + + for (i = 0; i < len; i++) { + for (j = 0, len2 = parts[i].length; j < len2; j++) { + p = parts[i][j]; + ctx[j ? 'lineTo' : 'moveTo'](p.x, p.y); + } + if (closed) { + ctx.closePath(); + } + } + + this._fillStroke(ctx, layer); + + // TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature + }, + + _updateCircle: function (layer) { + + if (!this._drawing || layer._empty()) { return; } + + var p = layer._point, + ctx = this._ctx, + r = Math.max(Math.round(layer._radius), 1), + s = (Math.max(Math.round(layer._radiusY), 1) || r) / r; + + this._drawnLayers[layer._leaflet_id] = layer; + + if (s !== 1) { + ctx.save(); + ctx.scale(1, s); + } + + ctx.beginPath(); + ctx.arc(p.x, p.y / s, r, 0, Math.PI * 2, false); + + if (s !== 1) { + ctx.restore(); + } + + this._fillStroke(ctx, layer); + }, + + _fillStroke: function (ctx, layer) { + var options = layer.options; + + if (options.fill) { + ctx.globalAlpha = options.fillOpacity; + ctx.fillStyle = options.fillColor || options.color; + ctx.fill(options.fillRule || 'evenodd'); + } + + if (options.stroke && options.weight !== 0) { + if (ctx.setLineDash) { + ctx.setLineDash(layer.options && layer.options._dashArray || []); + } + ctx.globalAlpha = options.opacity; + ctx.lineWidth = options.weight; + ctx.strokeStyle = options.color; + ctx.lineCap = options.lineCap; + ctx.lineJoin = options.lineJoin; + ctx.stroke(); + } + }, + + // Canvas obviously doesn't have mouse events for individual drawn objects, + // so we emulate that by calculating what's under the mouse on mousemove/click manually + + _onClick: function (e) { + var point = this._map.mouseEventToLayerPoint(e), layer, clickedLayer; + + for (var order = this._drawFirst; order; order = order.next) { + layer = order.layer; + if (layer.options.interactive && layer._containsPoint(point) && !this._map._draggableMoved(layer)) { + clickedLayer = layer; + } + } + if (clickedLayer) { + DomEvent.fakeStop(e); + this._fireEvent([clickedLayer], e); + } + }, + + _onMouseMove: function (e) { + if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) { return; } + + var point = this._map.mouseEventToLayerPoint(e); + this._handleMouseHover(e, point); + }, + + + _handleMouseOut: function (e) { + var layer = this._hoveredLayer; + if (layer) { + // if we're leaving the layer, fire mouseout + DomUtil.removeClass(this._container, 'leaflet-interactive'); + this._fireEvent([layer], e, 'mouseout'); + this._hoveredLayer = null; + } + }, + + _handleMouseHover: function (e, point) { + var layer, candidateHoveredLayer; + + for (var order = this._drawFirst; order; order = order.next) { + layer = order.layer; + if (layer.options.interactive && layer._containsPoint(point)) { + candidateHoveredLayer = layer; + } + } + + if (candidateHoveredLayer !== this._hoveredLayer) { + this._handleMouseOut(e); + + if (candidateHoveredLayer) { + DomUtil.addClass(this._container, 'leaflet-interactive'); // change cursor + this._fireEvent([candidateHoveredLayer], e, 'mouseover'); + this._hoveredLayer = candidateHoveredLayer; + } + } + + if (this._hoveredLayer) { + this._fireEvent([this._hoveredLayer], e); + } + }, + + _fireEvent: function (layers, e, type) { + this._map._fireDOMEvent(e, type || e.type, layers); + }, + + _bringToFront: function (layer) { + var order = layer._order; + var next = order.next; + var prev = order.prev; + + if (next) { + next.prev = prev; + } else { + // Already last + return; + } + if (prev) { + prev.next = next; + } else if (next) { + // Update first entry unless this is the + // single entry + this._drawFirst = next; + } + + order.prev = this._drawLast; + this._drawLast.next = order; + + order.next = null; + this._drawLast = order; + + this._requestRedraw(layer); + }, + + _bringToBack: function (layer) { + var order = layer._order; + var next = order.next; + var prev = order.prev; + + if (prev) { + prev.next = next; + } else { + // Already first + return; + } + if (next) { + next.prev = prev; + } else if (prev) { + // Update last entry unless this is the + // single entry + this._drawLast = prev; + } + + order.prev = null; + + order.next = this._drawFirst; + this._drawFirst.prev = order; + this._drawFirst = order; + + this._requestRedraw(layer); + } +}); + +// @factory L.canvas(options?: Renderer options) +// Creates a Canvas renderer with the given options. +export function canvas(options) { + return Browser.canvas ? new Canvas(options) : null; +} diff --git a/debian/missing-sources/leaflet.js/layer/vector/Circle.js b/debian/missing-sources/leaflet.js/layer/vector/Circle.js new file mode 100644 index 0000000..400273a --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/Circle.js @@ -0,0 +1,113 @@ +import {CircleMarker} from './CircleMarker'; +import {Path} from './Path'; +import * as Util from '../../core/Util'; +import {toLatLng} from '../../geo/LatLng'; +import {LatLngBounds} from '../../geo/LatLngBounds'; +import {Earth} from '../../geo/crs/CRS.Earth'; + + +/* + * @class Circle + * @aka L.Circle + * @inherits CircleMarker + * + * A class for drawing circle overlays on a map. Extends `CircleMarker`. + * + * It's an approximation and starts to diverge from a real circle closer to poles (due to projection distortion). + * + * @example + * + * ```js + * L.circle([50.5, 30.5], {radius: 200}).addTo(map); + * ``` + */ + +export var Circle = CircleMarker.extend({ + + initialize: function (latlng, options, legacyOptions) { + if (typeof options === 'number') { + // Backwards compatibility with 0.7.x factory (latlng, radius, options?) + options = Util.extend({}, legacyOptions, {radius: options}); + } + Util.setOptions(this, options); + this._latlng = toLatLng(latlng); + + if (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); } + + // @section + // @aka Circle options + // @option radius: Number; Radius of the circle, in meters. + this._mRadius = this.options.radius; + }, + + // @method setRadius(radius: Number): this + // Sets the radius of a circle. Units are in meters. + setRadius: function (radius) { + this._mRadius = radius; + return this.redraw(); + }, + + // @method getRadius(): Number + // Returns the current radius of a circle. Units are in meters. + getRadius: function () { + return this._mRadius; + }, + + // @method getBounds(): LatLngBounds + // Returns the `LatLngBounds` of the path. + getBounds: function () { + var half = [this._radius, this._radiusY || this._radius]; + + return new LatLngBounds( + this._map.layerPointToLatLng(this._point.subtract(half)), + this._map.layerPointToLatLng(this._point.add(half))); + }, + + setStyle: Path.prototype.setStyle, + + _project: function () { + + var lng = this._latlng.lng, + lat = this._latlng.lat, + map = this._map, + crs = map.options.crs; + + if (crs.distance === Earth.distance) { + var d = Math.PI / 180, + latR = (this._mRadius / Earth.R) / d, + top = map.project([lat + latR, lng]), + bottom = map.project([lat - latR, lng]), + p = top.add(bottom).divideBy(2), + lat2 = map.unproject(p).lat, + lngR = Math.acos((Math.cos(latR * d) - Math.sin(lat * d) * Math.sin(lat2 * d)) / + (Math.cos(lat * d) * Math.cos(lat2 * d))) / d; + + if (isNaN(lngR) || lngR === 0) { + lngR = latR / Math.cos(Math.PI / 180 * lat); // Fallback for edge case, #2425 + } + + this._point = p.subtract(map.getPixelOrigin()); + this._radius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x; + this._radiusY = p.y - top.y; + + } else { + var latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._mRadius, 0])); + + this._point = map.latLngToLayerPoint(this._latlng); + this._radius = this._point.x - map.latLngToLayerPoint(latlng2).x; + } + + this._updateBounds(); + } +}); + +// @factory L.circle(latlng: LatLng, options?: Circle options) +// Instantiates a circle object given a geographical point, and an options object +// which contains the circle radius. +// @alternative +// @factory L.circle(latlng: LatLng, radius: Number, options?: Circle options) +// Obsolete way of instantiating a circle, for compatibility with 0.7.x code. +// Do not use in new applications or plugins. +export function circle(latlng, options, legacyOptions) { + return new Circle(latlng, options, legacyOptions); +} diff --git a/debian/missing-sources/leaflet.js/layer/vector/CircleMarker.js b/debian/missing-sources/leaflet.js/layer/vector/CircleMarker.js new file mode 100644 index 0000000..994ecd0 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/CircleMarker.js @@ -0,0 +1,105 @@ +import {Path} from './Path'; +import * as Util from '../../core/Util'; +import {toLatLng} from '../../geo/LatLng'; +import {Bounds} from '../../geometry/Bounds'; + + +/* + * @class CircleMarker + * @aka L.CircleMarker + * @inherits Path + * + * A circle of a fixed size with radius specified in pixels. Extends `Path`. + */ + +export var CircleMarker = Path.extend({ + + // @section + // @aka CircleMarker options + options: { + fill: true, + + // @option radius: Number = 10 + // Radius of the circle marker, in pixels + radius: 10 + }, + + initialize: function (latlng, options) { + Util.setOptions(this, options); + this._latlng = toLatLng(latlng); + this._radius = this.options.radius; + }, + + // @method setLatLng(latLng: LatLng): this + // Sets the position of a circle marker to a new location. + setLatLng: function (latlng) { + this._latlng = toLatLng(latlng); + this.redraw(); + return this.fire('move', {latlng: this._latlng}); + }, + + // @method getLatLng(): LatLng + // Returns the current geographical position of the circle marker + getLatLng: function () { + return this._latlng; + }, + + // @method setRadius(radius: Number): this + // Sets the radius of a circle marker. Units are in pixels. + setRadius: function (radius) { + this.options.radius = this._radius = radius; + return this.redraw(); + }, + + // @method getRadius(): Number + // Returns the current radius of the circle + getRadius: function () { + return this._radius; + }, + + setStyle : function (options) { + var radius = options && options.radius || this._radius; + Path.prototype.setStyle.call(this, options); + this.setRadius(radius); + return this; + }, + + _project: function () { + this._point = this._map.latLngToLayerPoint(this._latlng); + this._updateBounds(); + }, + + _updateBounds: function () { + var r = this._radius, + r2 = this._radiusY || r, + w = this._clickTolerance(), + p = [r + w, r2 + w]; + this._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p)); + }, + + _update: function () { + if (this._map) { + this._updatePath(); + } + }, + + _updatePath: function () { + this._renderer._updateCircle(this); + }, + + _empty: function () { + return this._radius && !this._renderer._bounds.intersects(this._pxBounds); + }, + + // Needed by the `Canvas` renderer for interactivity + _containsPoint: function (p) { + return p.distanceTo(this._point) <= this._radius + this._clickTolerance(); + } +}); + + +// @factory L.circleMarker(latlng: LatLng, options?: CircleMarker options) +// Instantiates a circle marker object given a geographical point, and an optional options object. +export function circleMarker(latlng, options) { + return new CircleMarker(latlng, options); +} diff --git a/debian/missing-sources/leaflet.js/layer/vector/Path.js b/debian/missing-sources/leaflet.js/layer/vector/Path.js new file mode 100644 index 0000000..0323437 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/Path.js @@ -0,0 +1,144 @@ +import {Layer} from '../Layer'; +import * as Util from '../../core/Util'; + +/* + * @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`. + */ + +export var Path = 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, + + // @option bubblingMouseEvents: Boolean = true + // When `true`, a mouse event on this path will trigger the same event on the map + // (unless [`L.DomEvent.stopPropagation`](#domevent-stoppropagation) is used). + bubblingMouseEvents: 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); + }, + + onRemove: function () { + this._renderer._removePath(this); + }, + + // @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) { + Util.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 child classes + this._project(); + this._update(); + }, + + _clickTolerance: function () { + // used when doing hit detection for Canvas layers + return (this.options.stroke ? this.options.weight / 2 : 0) + this._renderer.options.tolerance; + } +}); diff --git a/debian/missing-sources/leaflet.js/layer/vector/Polygon.js b/debian/missing-sources/leaflet.js/layer/vector/Polygon.js new file mode 100644 index 0000000..925dbb5 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/Polygon.js @@ -0,0 +1,184 @@ +import {Polyline} from './Polyline'; +import {LatLng} from '../../geo/LatLng'; +import * as LineUtil from '../../geometry/LineUtil'; +import {Point} from '../../geometry/Point'; +import {Bounds} from '../../geometry/Bounds'; +import * as PolyUtil from '../../geometry/PolyUtil'; + +/* + * @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 = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]]; + * + * 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 = [ + * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring + * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole + * ]; + * ``` + * + * Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape. + * + * ```js + * var latlngs = [ + * [ // first polygon + * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring + * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole + * ], + * [ // second polygon + * [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]] + * ] + * ]; + * ``` + */ + +export var Polygon = Polyline.extend({ + + options: { + fill: true + }, + + isEmpty: function () { + return !this._latlngs.length || !this._latlngs[0].length; + }, + + 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, j, p1, p2, f, area, x, y, center, + points = this._rings[0], + len = points.length; + + if (!len) { return null; } + + // polygon centroid algorithm; only uses the first ring if there are multiple + + area = x = y = 0; + + for (i = 0, j = len - 1; i < len; j = i++) { + p1 = points[i]; + p2 = points[j]; + + f = p1.y * p2.x - p2.y * p1.x; + x += (p1.x + p2.x) * f; + y += (p1.y + p2.y) * f; + area += f * 3; + } + + if (area === 0) { + // Polygon is so small that all points are on same pixel. + center = points[0]; + } else { + center = [x / area, y / area]; + } + return this._map.layerPointToLatLng(center); + }, + + _convertLatLngs: function (latlngs) { + var result = Polyline.prototype._convertLatLngs.call(this, latlngs), + len = result.length; + + // remove last point if it equals first one + if (len >= 2 && result[0] instanceof LatLng && result[0].equals(result[len - 1])) { + result.pop(); + } + return result; + }, + + _setLatLngs: function (latlngs) { + Polyline.prototype._setLatLngs.call(this, latlngs); + if (LineUtil.isFlat(this._latlngs)) { + this._latlngs = [this._latlngs]; + } + }, + + _defaultShape: function () { + return LineUtil.isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0]; + }, + + _clipPoints: function () { + // polygons need a different clipping algorithm so we redefine that + + var bounds = this._renderer._bounds, + w = this.options.weight, + p = new Point(w, w); + + // increase clip padding by stroke width to avoid stroke on clip edges + bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p)); + + this._parts = []; + if (!this._pxBounds || !this._pxBounds.intersects(bounds)) { + return; + } + + if (this.options.noClip) { + this._parts = this._rings; + return; + } + + for (var i = 0, len = this._rings.length, clipped; i < len; i++) { + clipped = PolyUtil.clipPolygon(this._rings[i], bounds, true); + if (clipped.length) { + this._parts.push(clipped); + } + } + }, + + _updatePath: function () { + this._renderer._updatePoly(this, true); + }, + + // Needed by the `Canvas` renderer for interactivity + _containsPoint: function (p) { + var inside = false, + part, p1, p2, i, j, k, len, len2; + + if (!this._pxBounds.contains(p)) { return false; } + + // ray casting algorithm for detecting if point is in polygon + for (i = 0, len = this._parts.length; i < len; i++) { + part = this._parts[i]; + + for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) { + p1 = part[j]; + p2 = part[k]; + + if (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) { + inside = !inside; + } + } + } + + // also check if it's on polygon stroke + return inside || Polyline.prototype._containsPoint.call(this, p, true); + } + +}); + + +// @factory L.polygon(latlngs: LatLng[], options?: Polyline options) +export function polygon(latlngs, options) { + return new Polygon(latlngs, options); +} diff --git a/debian/missing-sources/leaflet.js/layer/vector/Polyline.js b/debian/missing-sources/leaflet.js/layer/vector/Polyline.js new file mode 100644 index 0000000..26511f7 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/Polyline.js @@ -0,0 +1,328 @@ +import {Path} from './Path'; +import * as Util from '../../core/Util'; +import * as LineUtil from '../../geometry/LineUtil'; +import {LatLng, toLatLng} from '../../geo/LatLng'; +import {LatLngBounds} from '../../geo/LatLngBounds'; +import {Bounds} from '../../geometry/Bounds'; +import {Point} from '../../geometry/Point'; + +/* + * @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 = [ + * [45.51, -122.68], + * [37.77, -122.43], + * [34.04, -118.2] + * ]; + * + * 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 = [ + * [[45.51, -122.68], + * [37.77, -122.43], + * [34.04, -118.2]], + * [[40.78, -73.91], + * [41.83, -87.62], + * [32.76, -96.72]] + * ]; + * ``` + */ + + +export var Polyline = 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) { + Util.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; + }, + + // @method closestLayerPoint: Point + // Returns the point closest to `p` on the Polyline. + closestLayerPoint: function (p) { + var minDistance = Infinity, + minPoint = null, + closest = 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 = toLatLng(latlng); + latlngs.push(latlng); + this._bounds.extend(latlng); + return this.redraw(); + }, + + _setLatLngs: function (latlngs) { + this._bounds = new LatLngBounds(); + this._latlngs = this._convertLatLngs(latlngs); + }, + + _defaultShape: function () { + return LineUtil.isFlat(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 = LineUtil.isFlat(latlngs); + + for (var i = 0, len = latlngs.length; i < len; i++) { + if (flat) { + result[i] = toLatLng(latlngs[i]); + this._bounds.extend(result[i]); + } else { + result[i] = this._convertLatLngs(latlngs[i]); + } + } + + return result; + }, + + _project: function () { + var pxBounds = new Bounds(); + this._rings = []; + this._projectLatlngs(this._latlngs, this._rings, pxBounds); + + var w = this._clickTolerance(), + p = new 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 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 = 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] = LineUtil.simplify(parts[i], tolerance); + } + }, + + _update: function () { + if (!this._map) { return; } + + this._clipPoints(); + this._simplifyPoints(); + this._updatePath(); + }, + + _updatePath: function () { + this._renderer._updatePoly(this); + }, + + // Needed by the `Canvas` renderer for interactivity + _containsPoint: function (p, closed) { + var i, j, k, len, len2, part, + w = this._clickTolerance(); + + if (!this._pxBounds || !this._pxBounds.contains(p)) { return false; } + + // hit detection for polylines + for (i = 0, len = this._parts.length; i < len; i++) { + part = this._parts[i]; + + for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) { + if (!closed && (j === 0)) { continue; } + + if (LineUtil.pointToSegmentDistance(p, part[k], part[j]) <= w) { + return true; + } + } + } + return false; + } +}); + +// @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. +export function polyline(latlngs, options) { + return new Polyline(latlngs, options); +} + +// Retrocompat. Allow plugins to support Leaflet versions before and after 1.1. +Polyline._flat = LineUtil._flat; diff --git a/debian/missing-sources/leaflet.js/layer/vector/Rectangle.js b/debian/missing-sources/leaflet.js/layer/vector/Rectangle.js new file mode 100644 index 0000000..ceec041 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/Rectangle.js @@ -0,0 +1,57 @@ +import {Polygon} from './Polygon'; +import {toLatLngBounds} from '../../geo/LatLngBounds'; + +/* + * L.Rectangle extends Polygon and creates a rectangle when passed a LatLngBounds object. + */ + +/* + * @class Rectangle + * @aka L.Rectangle + * @inherits Polygon + * + * A class for drawing rectangle overlays on a map. Extends `Polygon`. + * + * @example + * + * ```js + * // define rectangle geographical bounds + * var bounds = [[54.559322, -5.767822], [56.1210604, -3.021240]]; + * + * // create an orange rectangle + * L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map); + * + * // zoom the map to the rectangle bounds + * map.fitBounds(bounds); + * ``` + * + */ + + +export var Rectangle = Polygon.extend({ + initialize: function (latLngBounds, options) { + Polygon.prototype.initialize.call(this, this._boundsToLatLngs(latLngBounds), options); + }, + + // @method setBounds(latLngBounds: LatLngBounds): this + // Redraws the rectangle with the passed bounds. + setBounds: function (latLngBounds) { + return this.setLatLngs(this._boundsToLatLngs(latLngBounds)); + }, + + _boundsToLatLngs: function (latLngBounds) { + latLngBounds = toLatLngBounds(latLngBounds); + return [ + latLngBounds.getSouthWest(), + latLngBounds.getNorthWest(), + latLngBounds.getNorthEast(), + latLngBounds.getSouthEast() + ]; + } +}); + + +// @factory L.rectangle(latLngBounds: LatLngBounds, options?: Polyline options) +export function rectangle(latLngBounds, options) { + return new Rectangle(latLngBounds, options); +} diff --git a/debian/missing-sources/leaflet.js/layer/vector/Renderer.getRenderer.js b/debian/missing-sources/leaflet.js/layer/vector/Renderer.getRenderer.js new file mode 100644 index 0000000..92cd615 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/Renderer.getRenderer.js @@ -0,0 +1,41 @@ +import {Map} from '../../map/Map'; +import {Canvas, canvas} from './Canvas'; +import {SVG, svg} from './SVG'; + +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 && canvas()) || 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 = (SVG && svg({pane: name})) || (Canvas && canvas({pane: name})); + this._paneRenderers[name] = renderer; + } + return renderer; + } +}); diff --git a/debian/missing-sources/leaflet.js/layer/vector/Renderer.js b/debian/missing-sources/leaflet.js/layer/vector/Renderer.js new file mode 100644 index 0000000..424a179 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/Renderer.js @@ -0,0 +1,140 @@ +import {Layer} from '../Layer'; +import * as DomUtil from '../../dom/DomUtil'; +import * as Util from '../../core/Util'; +import * as Browser from '../../core/Browser'; +import {Bounds} from '../../geometry/Bounds'; + + + +/* + * @class Renderer + * @inherits Layer + * @aka L.Renderer + * + * Base class for vector renderer implementations (`SVG`, `Canvas`). Handles the + * DOM container of the renderer, its bounds, and its zoom animation. + * + * A `Renderer` works as an implicit layer group for all `Path`s - the renderer + * itself can be added or removed to the map. All paths use a renderer, which can + * be implicit (the map will decide the type of renderer and use it automatically) + * or explicit (using the [`renderer`](#path-renderer) option of the path). + * + * Do not use this class directly, use `SVG` and `Canvas` instead. + * + * @event update: Event + * Fired when the renderer updates its bounds, center and zoom, for example when + * its map has moved + */ + +export var Renderer = Layer.extend({ + + // @section + // @aka Renderer options + options: { + // @option padding: Number = 0.1 + // How much to extend the clip area around the map view (relative to its size) + // e.g. 0.1 would be 10% of map view in each direction + padding: 0.1, + + // @option tolerance: Number = 0 + // How much to extend click tolerance round a path/object on the map + tolerance : 0 + }, + + initialize: function (options) { + Util.setOptions(this, options); + Util.stamp(this); + this._layers = this._layers || {}; + }, + + onAdd: function () { + if (!this._container) { + this._initContainer(); // defined by renderer implementations + + if (this._zoomAnimated) { + DomUtil.addClass(this._container, 'leaflet-zoom-animated'); + } + } + + this.getPane().appendChild(this._container); + this._update(); + this.on('update', this._updatePaths, this); + }, + + onRemove: function () { + this.off('update', this._updatePaths, this); + this._destroyContainer(); + }, + + getEvents: function () { + var events = { + viewreset: this._reset, + zoom: this._onZoom, + moveend: this._update, + zoomend: this._onZoomEnd + }; + 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 = 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 (Browser.any3d) { + DomUtil.setTransform(this._container, topLeftOffset, scale); + } else { + DomUtil.setPosition(this._container, topLeftOffset); + } + }, + + _reset: function () { + this._update(); + this._updateTransform(this._center, this._zoom); + + for (var id in this._layers) { + this._layers[id]._reset(); + } + }, + + _onZoomEnd: function () { + for (var id in this._layers) { + this._layers[id]._project(); + } + }, + + _updatePaths: function () { + for (var id in this._layers) { + this._layers[id]._update(); + } + }, + + _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 Bounds(min, min.add(size.multiplyBy(1 + p * 2)).round()); + + this._center = this._map.getCenter(); + this._zoom = this._map.getZoom(); + } +}); diff --git a/debian/missing-sources/leaflet.js/layer/vector/SVG.Util.js b/debian/missing-sources/leaflet.js/layer/vector/SVG.Util.js new file mode 100644 index 0000000..2a54797 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/SVG.Util.js @@ -0,0 +1,39 @@ +import * as Browser from '../../core/Browser'; + +// @namespace SVG; @section +// There are several static functions which can be called without instantiating L.SVG: + +// @function create(name: String): SVGElement +// Returns a instance of [SVGElement](https://developer.mozilla.org/docs/Web/API/SVGElement), +// corresponding to the class name passed. For example, using 'line' will return +// an instance of [SVGLineElement](https://developer.mozilla.org/docs/Web/API/SVGLineElement). +export function svgCreate(name) { + return document.createElementNS('http://www.w3.org/2000/svg', name); +} + +// @function pointsToPath(rings: Point[], closed: Boolean): String +// Generates a SVG path string for multiple rings, with each ring turning +// into "M..L..L.." instructions +export function pointsToPath(rings, closed) { + var str = '', + i, j, len, len2, points, p; + + for (i = 0, len = rings.length; i < len; i++) { + points = rings[i]; + + for (j = 0, len2 = points.length; j < len2; j++) { + p = points[j]; + str += (j ? 'L' : 'M') + p.x + ' ' + p.y; + } + + // closes the ring for polygons; "x" is VML syntax + str += closed ? (Browser.svg ? 'z' : 'x') : ''; + } + + // SVG complains about empty path strings + return str || 'M0 0'; +} + + + + diff --git a/debian/missing-sources/leaflet.js/layer/vector/SVG.VML.js b/debian/missing-sources/leaflet.js/layer/vector/SVG.VML.js new file mode 100644 index 0000000..86832e6 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/SVG.VML.js @@ -0,0 +1,143 @@ +import * as DomUtil from '../../dom/DomUtil'; +import * as Util from '../../core/Util'; +import {Renderer} from './Renderer'; + +/* + * Thanks to Dmitry Baranovsky and his Raphael library for inspiration! + */ + + +export var vmlCreate = (function () { + try { + document.namespaces.add('lvml', 'urn:schemas-microsoft-com:vml'); + return function (name) { + return document.createElement(''); + }; + } catch (e) { + return function (name) { + return document.createElement('<' + name + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">'); + }; + } +})(); + + +/* + * @class SVG + * + * Although SVG is not available on IE7 and IE8, these browsers support [VML](https://en.wikipedia.org/wiki/Vector_Markup_Language), and the SVG renderer will fall back to VML in this case. + * + * VML was deprecated in 2012, which means VML functionality exists only for backwards compatibility + * with old versions of Internet Explorer. + */ + +// mixin to redefine some SVG methods to handle VML syntax which is similar but with some differences +export var vmlMixin = { + + _initContainer: function () { + this._container = DomUtil.create('div', 'leaflet-vml-container'); + }, + + _update: function () { + if (this._map._animatingZoom) { return; } + Renderer.prototype._update.call(this); + this.fire('update'); + }, + + _initPath: function (layer) { + var container = layer._container = vmlCreate('shape'); + + DomUtil.addClass(container, 'leaflet-vml-shape ' + (this.options.className || '')); + + container.coordsize = '1 1'; + + layer._path = vmlCreate('path'); + container.appendChild(layer._path); + + this._updateStyle(layer); + this._layers[Util.stamp(layer)] = layer; + }, + + _addPath: function (layer) { + var container = layer._container; + this._container.appendChild(container); + + if (layer.options.interactive) { + layer.addInteractiveTarget(container); + } + }, + + _removePath: function (layer) { + var container = layer._container; + DomUtil.remove(container); + layer.removeInteractiveTarget(container); + delete this._layers[Util.stamp(layer)]; + }, + + _updateStyle: function (layer) { + var stroke = layer._stroke, + fill = layer._fill, + options = layer.options, + container = layer._container; + + container.stroked = !!options.stroke; + container.filled = !!options.fill; + + if (options.stroke) { + if (!stroke) { + stroke = layer._stroke = vmlCreate('stroke'); + } + container.appendChild(stroke); + stroke.weight = options.weight + 'px'; + stroke.color = options.color; + stroke.opacity = options.opacity; + + if (options.dashArray) { + stroke.dashStyle = Util.isArray(options.dashArray) ? + options.dashArray.join(' ') : + options.dashArray.replace(/( *, *)/g, ' '); + } else { + stroke.dashStyle = ''; + } + stroke.endcap = options.lineCap.replace('butt', 'flat'); + stroke.joinstyle = options.lineJoin; + + } else if (stroke) { + container.removeChild(stroke); + layer._stroke = null; + } + + if (options.fill) { + if (!fill) { + fill = layer._fill = vmlCreate('fill'); + } + container.appendChild(fill); + fill.color = options.fillColor || options.color; + fill.opacity = options.fillOpacity; + + } else if (fill) { + container.removeChild(fill); + layer._fill = null; + } + }, + + _updateCircle: function (layer) { + var p = layer._point.round(), + r = Math.round(layer._radius), + r2 = Math.round(layer._radiusY || r); + + this._setPath(layer, layer._empty() ? 'M0 0' : + 'AL ' + p.x + ',' + p.y + ' ' + r + ',' + r2 + ' 0,' + (65535 * 360)); + }, + + _setPath: function (layer, path) { + layer._path.v = path; + }, + + _bringToFront: function (layer) { + DomUtil.toFront(layer._container); + }, + + _bringToBack: function (layer) { + DomUtil.toBack(layer._container); + } +}; diff --git a/debian/missing-sources/leaflet.js/layer/vector/SVG.js b/debian/missing-sources/leaflet.js/layer/vector/SVG.js new file mode 100644 index 0000000..8c085e4 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/SVG.js @@ -0,0 +1,220 @@ +import {Renderer} from './Renderer'; +import * as DomUtil from '../../dom/DomUtil'; +import * as DomEvent from '../../dom/DomEvent'; +import * as Browser from '../../core/Browser'; +import {stamp} from '../../core/Util'; +import {svgCreate, pointsToPath} from './SVG.Util'; +export {pointsToPath}; +import {vmlMixin, vmlCreate} from './SVG.VML'; + +export var create = Browser.vml ? vmlCreate : svgCreate; + +/* + * @class SVG + * @inherits Renderer + * @aka L.SVG + * + * Allows vector layers to be displayed with [SVG](https://developer.mozilla.org/docs/Web/SVG). + * Inherits `Renderer`. + * + * Due to [technical limitations](http://caniuse.com/#search=svg), SVG is not + * available in all web browsers, notably Android 2.x and 3.x. + * + * Although SVG is not available on IE7 and IE8, these browsers support + * [VML](https://en.wikipedia.org/wiki/Vector_Markup_Language) + * (a now deprecated technology), and the SVG renderer will fall back to VML in + * this case. + * + * @example + * + * Use SVG by default for all paths in the map: + * + * ```js + * var map = L.map('map', { + * renderer: L.svg() + * }); + * ``` + * + * Use a SVG renderer with extra padding for specific vector geometries: + * + * ```js + * var map = L.map('map'); + * var myRenderer = L.svg({ padding: 0.5 }); + * var line = L.polyline( coordinates, { renderer: myRenderer } ); + * var circle = L.circle( center, { renderer: myRenderer } ); + * ``` + */ + +export var SVG = Renderer.extend({ + + getEvents: function () { + var events = Renderer.prototype.getEvents.call(this); + events.zoomstart = this._onZoomStart; + return events; + }, + + _initContainer: function () { + this._container = create('svg'); + + // makes it possible to click through svg root; we'll reset it back in individual paths + this._container.setAttribute('pointer-events', 'none'); + + this._rootGroup = create('g'); + this._container.appendChild(this._rootGroup); + }, + + _destroyContainer: function () { + DomUtil.remove(this._container); + DomEvent.off(this._container); + delete this._container; + delete this._rootGroup; + delete this._svgSize; + }, + + _onZoomStart: function () { + // Drag-then-pinch interactions might mess up the center and zoom. + // In this case, the easiest way to prevent this is re-do the renderer + // bounds and padding when the zooming starts. + this._update(); + }, + + _update: function () { + if (this._map._animatingZoom && this._bounds) { return; } + + Renderer.prototype._update.call(this); + + var b = this._bounds, + size = b.getSize(), + container = this._container; + + // set size of svg-container if changed + if (!this._svgSize || !this._svgSize.equals(size)) { + this._svgSize = size; + container.setAttribute('width', size.x); + container.setAttribute('height', size.y); + } + + // movement: update container viewBox so that we don't have to change coordinates of individual layers + DomUtil.setPosition(container, b.min); + container.setAttribute('viewBox', [b.min.x, b.min.y, size.x, size.y].join(' ')); + + this.fire('update'); + }, + + // methods below are called by vector layers implementations + + _initPath: function (layer) { + var path = layer._path = create('path'); + + // @namespace Path + // @option className: String = null + // Custom class name set on an element. Only for SVG renderer. + if (layer.options.className) { + DomUtil.addClass(path, layer.options.className); + } + + if (layer.options.interactive) { + DomUtil.addClass(path, 'leaflet-interactive'); + } + + this._updateStyle(layer); + this._layers[stamp(layer)] = layer; + }, + + _addPath: function (layer) { + if (!this._rootGroup) { this._initContainer(); } + this._rootGroup.appendChild(layer._path); + layer.addInteractiveTarget(layer._path); + }, + + _removePath: function (layer) { + DomUtil.remove(layer._path); + layer.removeInteractiveTarget(layer._path); + delete this._layers[stamp(layer)]; + }, + + _updatePath: function (layer) { + layer._project(); + layer._update(); + }, + + _updateStyle: function (layer) { + var path = layer._path, + options = layer.options; + + if (!path) { return; } + + if (options.stroke) { + path.setAttribute('stroke', options.color); + path.setAttribute('stroke-opacity', options.opacity); + path.setAttribute('stroke-width', options.weight); + path.setAttribute('stroke-linecap', options.lineCap); + path.setAttribute('stroke-linejoin', options.lineJoin); + + if (options.dashArray) { + path.setAttribute('stroke-dasharray', options.dashArray); + } else { + path.removeAttribute('stroke-dasharray'); + } + + if (options.dashOffset) { + path.setAttribute('stroke-dashoffset', options.dashOffset); + } else { + path.removeAttribute('stroke-dashoffset'); + } + } else { + path.setAttribute('stroke', 'none'); + } + + if (options.fill) { + path.setAttribute('fill', options.fillColor || options.color); + path.setAttribute('fill-opacity', options.fillOpacity); + path.setAttribute('fill-rule', options.fillRule || 'evenodd'); + } else { + path.setAttribute('fill', 'none'); + } + }, + + _updatePoly: function (layer, closed) { + this._setPath(layer, pointsToPath(layer._parts, closed)); + }, + + _updateCircle: function (layer) { + var p = layer._point, + r = Math.max(Math.round(layer._radius), 1), + r2 = Math.max(Math.round(layer._radiusY), 1) || r, + arc = 'a' + r + ',' + r2 + ' 0 1,0 '; + + // drawing a circle with two half-arcs + var d = layer._empty() ? 'M0 0' : + 'M' + (p.x - r) + ',' + p.y + + arc + (r * 2) + ',0 ' + + arc + (-r * 2) + ',0 '; + + this._setPath(layer, d); + }, + + _setPath: function (layer, path) { + layer._path.setAttribute('d', path); + }, + + // SVG does not have the concept of zIndex so we resort to changing the DOM order of elements + _bringToFront: function (layer) { + DomUtil.toFront(layer._path); + }, + + _bringToBack: function (layer) { + DomUtil.toBack(layer._path); + } +}); + +if (Browser.vml) { + SVG.include(vmlMixin); +} + +// @namespace SVG +// @factory L.svg(options?: Renderer options) +// Creates a SVG renderer with the given options. +export function svg(options) { + return Browser.svg || Browser.vml ? new SVG(options) : null; +} diff --git a/debian/missing-sources/leaflet.js/layer/vector/index.js b/debian/missing-sources/leaflet.js/layer/vector/index.js new file mode 100644 index 0000000..2373a41 --- /dev/null +++ b/debian/missing-sources/leaflet.js/layer/vector/index.js @@ -0,0 +1,14 @@ +export {Renderer} from './Renderer'; +export {Canvas, canvas} from './Canvas'; +import {SVG, create, pointsToPath, svg} from './SVG'; +SVG.create = create; +SVG.pointsToPath = pointsToPath; +export {SVG, svg}; +import './Renderer.getRenderer'; // This is a bit of a hack, but needed because circular dependencies + +export {Path} from './Path'; +export {CircleMarker, circleMarker} from './CircleMarker'; +export {Circle, circle} from './Circle'; +export {Polyline, polyline} from './Polyline'; +export {Polygon, polygon} from './Polygon'; +export {Rectangle, rectangle} from './Rectangle'; -- cgit v1.2.3