1 | import {ImageOverlay} from './ImageOverlay';
|
2 | import * as DomUtil from '../dom/DomUtil';
|
3 | import * as Util from '../core/Util';
|
4 |
|
5 | /*
|
6 | * @class SVGOverlay
|
7 | * @aka L.SVGOverlay
|
8 | * @inherits ImageOverlay
|
9 | *
|
10 | * Used to load, display and provide DOM access to an SVG file over specific bounds of the map. Extends `ImageOverlay`.
|
11 | *
|
12 | * An SVG overlay uses the [`<svg>`](https://developer.mozilla.org/docs/Web/SVG/Element/svg) element.
|
13 | *
|
14 | * @example
|
15 | *
|
16 | * ```js
|
17 | * var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
18 | * svgElement.setAttribute('xmlns', "http://www.w3.org/2000/svg");
|
19 | * svgElement.setAttribute('viewBox', "0 0 200 200");
|
20 | * svgElement.innerHTML = '<rect width="200" height="200"/><rect x="75" y="23" width="50" height="50" style="fill:red"/><rect x="75" y="123" width="50" height="50" style="fill:#0013ff"/>';
|
21 | * var svgElementBounds = [ [ 32, -130 ], [ 13, -100 ] ];
|
22 | * L.svgOverlay(svgElement, svgElementBounds).addTo(map);
|
23 | * ```
|
24 | */
|
25 |
|
26 | export var SVGOverlay = ImageOverlay.extend({
|
27 | _initImage: function () {
|
28 | var el = this._image = this._url;
|
29 |
|
30 | DomUtil.addClass(el, 'leaflet-image-layer');
|
31 | if (this._zoomAnimated) { DomUtil.addClass(el, 'leaflet-zoom-animated'); }
|
32 | if (this.options.className) { DomUtil.addClass(el, this.options.className); }
|
33 |
|
34 | el.onselectstart = Util.falseFn;
|
35 | el.onmousemove = Util.falseFn;
|
36 | }
|
37 |
|
38 | // @method getElement(): SVGElement
|
39 | // Returns the instance of [`SVGElement`](https://developer.mozilla.org/docs/Web/API/SVGElement)
|
40 | // used by this overlay.
|
41 | });
|
42 |
|
43 |
|
44 | // @factory L.svgOverlay(svg: String|SVGElement, bounds: LatLngBounds, options?: SVGOverlay options)
|
45 | // Instantiates an image overlay object given an SVG element and the geographical bounds it is tied to.
|
46 | // A viewBox attribute is required on the SVG element to zoom in and out properly.
|
47 |
|
48 | export function svgOverlay(el, bounds, options) {
|
49 | return new SVGOverlay(el, bounds, options);
|
50 | }
|