Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LSVGOverlay #684

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/components/LImageOverlay.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default {
| visible | | boolean | - | true |
| interactive | | boolean | - | false |
| bubblingMouseEvents | | boolean | - | true |
| url | | string | - | |
| bounds | | | - | |
| opacity | | number | - | 1.0 |
| alt | | string | - | '' |
Expand All @@ -68,6 +67,7 @@ export default {
| zIndex | | number | - | 1 |
| className | | string | - | '' |
| options | Leaflet options to pass to the component constructor | object | - | {} |
| url | | string | - | null |

## Events

Expand Down
87 changes: 87 additions & 0 deletions docs/components/LSVGOverlay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: LSVGOverlay
---

# LSVGOverlay

> Easily display a svg overlay.

---

## Demo

::: demo
<template>
<l-map style="height: 350px" :zoom="zoom" :center="center">
<l-tile-layer :url="url"></l-tile-layer>
<l-svg-overlay :svg="svg" :bounds="bounds"></l-svg-overlay>
</l-map>
</template>

<script>
import {LMap, LSVGOverlay, LTileLayer} from 'vue2-leaflet';

const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svgElement.setAttribute('xmlns', "http://www.w3.org/2000/svg");
svgElement.setAttribute('viewBox', "0 0 200 200");
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"/>`;

export default {
components: {
LMap,
'l-svg-overlay': LSVGOverlay,
LTileLayer
},
data () {
return {
zoom: 4,
center: [25, -110],
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
svg: svgElement,
bounds: [[ 32, -130], [ 13, -100]]
};
}
}
</script>

:::

## Props

| Prop name | Description | Type | Values | Default |
| ------------------- | ---------------------------------------------------- | ------------------ | ------ | ------------- |
| pane | | string | - | 'overlayPane' |
| attribution | | string | - | null |
| name | | string | - | undefined |
| layerType | | string | - | undefined |
| visible | | boolean | - | true |
| interactive | | boolean | - | false |
| bubblingMouseEvents | | boolean | - | true |
| bounds | | | - | |
| opacity | | number | - | 1.0 |
| alt | | string | - | '' |
| crossOrigin | | boolean | - | false |
| errorOverlayUrl | | string | - | '' |
| zIndex | | number | - | 1 |
| className | | string | - | '' |
| options | Leaflet options to pass to the component constructor | object | - | {} |
| svg | | string\|SVGElement | - | null |

## Events

| Event name | Type | Description |
| -------------- | ------- | -------------------------------------------------- |
| update:visible | boolean | Triggers when the visible prop needs to be updated |
| ready | object | Triggers when the component is ready |
7 changes: 7 additions & 0 deletions src/components/LImageOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { imageOverlay, DomEvent } from 'leaflet';
export default {
name: 'LImageOverlay',
mixins: [ImageOverlayMixin, Options],
props: {
url: {
type: String,
custom: true,
default: null
}
},
mounted() {
const options = optionsMerger(this.imageOverlayOptions, this);
this.mapObject = imageOverlay(this.url, this.bounds, options);
Expand Down
88 changes: 88 additions & 0 deletions src/components/LSVGOverlay.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<script>
import { optionsMerger, propsBinder, findRealParent } from '../utils/utils.js';
import SVGOverlayMixin from '../mixins/SVGOverlay.js';
import Options from '../mixins/Options.js';
import { svgOverlay, DomEvent } from 'leaflet';
/**
* Easily display a svg overlay.
*/
export default {
name: 'LSVGOverlay',
mixins: [SVGOverlayMixin, Options],
props: {
svg: {
type: [String, SVGElement],
default: null
}
},
mounted() {
const options = optionsMerger(this.svgOverlayOptions, this);
this.mapObject = svgOverlay(this.svg, this.bounds, options);
DomEvent.on(this.mapObject, this.$listeners);
propsBinder(this, this.mapObject, this.$options.props);
this.parentContainer = findRealParent(this.$parent);
this.parentContainer.addLayer(this, !this.visible);
this.$nextTick(() => {
/**
* Triggers when the component is ready
* @type {object}
* @property {object} mapObject - reference to leaflet map object
*/
this.$emit('ready', this.mapObject);
});
},
render() {
return null;
},
};
</script>

<docs>
## Demo
::: demo
<template>
<l-map style="height: 350px" :zoom="zoom" :center="center">
<l-tile-layer :url="url"></l-tile-layer>
<l-svg-overlay :svg="svg" :bounds="bounds"></l-svg-overlay>
</l-map>
</template>

<script>
import {LMap, LSVGOverlay, LTileLayer} from 'vue2-leaflet';

const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svgElement.setAttribute('xmlns', "http://www.w3.org/2000/svg");
svgElement.setAttribute('viewBox', "0 0 200 200");
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"/>`;

export default {
components: {
LMap,
'l-svg-overlay': LSVGOverlay,
LTileLayer
},
data () {
return {
zoom: 4,
center: [25, -110],
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
svg: svgElement,
bounds: [[ 32, -130], [ 13, -100]]
};
}
}
</script>
:::
</docs>
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export { default as LPolygon } from './components/LPolygon';
export { default as LPolyline } from './components/LPolyline';
export { default as LPopup } from './components/LPopup';
export { default as LRectangle } from './components/LRectangle';
export { default as LSVGOverlay } from './components/LSVGOverlay';
export { default as LTileLayer } from './components/LTileLayer';
export { default as LTooltip } from './components/LTooltip';
export { default as LWMSTileLayer } from './components/LWMSTileLayer';
4 changes: 0 additions & 4 deletions src/mixins/ImageOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import InteractiveLayer from './InteractiveLayer';
export default {
mixins: [Layer, InteractiveLayer],
props: {
url: {
type: String,
custom: true
},
bounds: {
custom: true
},
Expand Down
16 changes: 16 additions & 0 deletions src/mixins/SVGOverlay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ImageOverlay from './ImageOverlay.js';

export default {
mixins: [ImageOverlay],
mounted () {
this.svgOverlayOptions = this.imageOverlayOptions;
},
methods: {
getElement () {
return this.mapObject.getElement();
}
},
render () {
return null;
}
};
29 changes: 24 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ declare module "vue2-leaflet" {
}
class ImageOverlay extends Mixins(Layer, InteractiveLayer) {
// props
url: string;
/**
* @default true
*/
bounds: boolean;
/**
* @default 1.0
Expand Down Expand Up @@ -307,6 +303,10 @@ declare module "vue2-leaflet" {
*/
upperCase: boolean;
}
class SVGOverlay extends Mixins(ImageOverlay) {
// methods
getElement(): SVGElement;
}

// components
class LCircle extends Mixins(Circle) {
Expand Down Expand Up @@ -489,6 +489,13 @@ declare module "vue2-leaflet" {
setImagePath(newVal: string, oldVal?: string): void;
}
class LImageOverlay extends Mixins(ImageOverlay) {
// props
/**
* @default null
*/
url: string | null;

// data
mapObject: L.ImageOverlay;
parentContainer: any;
}
Expand Down Expand Up @@ -699,6 +706,17 @@ declare module "vue2-leaflet" {
mapObject: L.TileLayer.WMS;
parentContainer: any;
}
class LSVGOverlay extends Mixins(SVGOverlay) {
// props
/**
* @default null
*/
svg: string | SVGElement | null;

// data
mapObject: L.SVGOverlay;
parentContainer: any;
}

// utils
function findRealParent(firstVueParent: Vue): any;
Expand Down Expand Up @@ -734,6 +752,7 @@ declare module "vue2-leaflet" {
LRectangle,
LTileLayer,
LTooltip,
LWMSTileLayer
LWMSTileLayer,
LSVGOverlay
};
}