Skip to content

Commit 494dd67

Browse files
committed
feat: add control layer
1 parent aef9142 commit 494dd67

File tree

9 files changed

+153
-19
lines changed

9 files changed

+153
-19
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<img src="https://img.shields.io/twitter/follow/xwpisme?style=social&logo=twitter"
1515
alt="follow on Twitter">
1616
</a>
17-
1817
</p>
1918

2019
Here is Vue components for Leaflet maps, which is inspired by [react-leaflet](https://github.com/PaulLeCam/react-leaflet) and [vue-google-maps](https://github.com/GuillaumeLeclerc/vue-google-maps).

examples/Layout.vue

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ import {
1010
LPolygon,
1111
LPolyline,
1212
LRectangle,
13+
LControlAttribution,
14+
LControlLayers,
15+
LControlZoom,
16+
LControlScale
1317
} from '../src';
1418
import '../node_modules/leaflet/dist/leaflet.css';
19+
import L from 'leaflet';
1520
1621
const mapOptions = {
1722
zoom: 13,
1823
center: { lat: 51.505, lng: -0.09 },
1924
minZoom: 8,
2025
maxZoom: 15,
21-
attributionControl: true,
22-
zoomControl: true
26+
attributionControl: false,
27+
zoomControl: false
2328
}
2429
2530
const tileLayerOptions = {
@@ -31,11 +36,28 @@ const tileLayerOptions = {
3136
accessToken: 'pk.eyJ1IjoieHdwaXNtZSIsImEiOiJ5cTlCQTlRIn0.QdV-wNUKbgs7jAlbVE747Q'
3237
}
3338
39+
const baseLayerOptions = {
40+
geoqBlue: new L.TileLayer(
41+
"http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",
42+
{
43+
attribution: "geoq blue"
44+
}
45+
),
46+
'高德影像': new L.TileLayer(
47+
"http://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
48+
{
49+
subdomains: "1234",
50+
attribution: "高德影像"
51+
}
52+
)
53+
}
54+
55+
3456
</script>
3557

3658
<template>
3759
<div>
38-
<h1>Marker/Tooltip/Popup</h1>
60+
<h1>Basic UI Layers</h1>
3961
<l-map id="map1" :options="mapOptions">
4062
<l-tilelayer urlTemplate="https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}"
4163
:options="tileLayerOptions" />
@@ -59,7 +81,7 @@ const tileLayerOptions = {
5981
<h1>Vector Layers</h1>
6082
<l-map id="map2" :options="mapOptions">
6183
<l-tilelayer urlTemplate="https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}"
62-
:options="tileLayerOptions"/>
84+
:options="tileLayerOptions" />
6385
<l-circle :latlng="[51.508, -0.11]" :options="{
6486
color: 'red',
6587
fillColor: '#f03',
@@ -90,14 +112,17 @@ const tileLayerOptions = {
90112
</div>
91113
<div>
92114
<h1>Control</h1>
93-
<l-map id="map3" :options="mapOptions">
115+
<l-map id="map3" :options="{
116+
...mapOptions,
117+
zoom: 10,
118+
center: { lat: 26.33280692289788, lng: 114.78515624999999 },
119+
}">
94120
<l-tilelayer urlTemplate="https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}"
95121
:options="tileLayerOptions" />
96-
<!-- <l-marker id="marker3" :latlng="{ lat: 51.505, lng: -0.2 }" :options="{
97-
title: 'marker3'
98-
}">
99-
<l-popup :options="{ content: 'popup with marker3' }" />
100-
</l-marker> -->
122+
<LControlScale />
123+
<LControlZoom :options="{ position: 'topright' }" />
124+
<LControlAttribution />
125+
<LControlLayers :base-layers="baseLayerOptions" />
101126
</l-map>
102127
</div>
103128
</template>

src/components/LCircle.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import L, { CircleOptions, LatLngExpression } from 'leaflet'
3-
import { PropType, inject, nextTick, useAttrs, useSlots } from 'vue';
3+
import { PropType, inject, nextTick } from 'vue';
44
import { MapProvide } from '../core/Map';
55
import { MAP_PROVIDE, getMapInjectKey } from '../utils/injectKey';
66

src/components/LControl.vue

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script setup lang="ts">
2+
import L from 'leaflet'
3+
import { PropType, inject, nextTick } from 'vue';
4+
import { MapProvide } from '../core/Map';
5+
import { MAP_PROVIDE, getMapInjectKey } from '../utils/injectKey';
6+
7+
8+
const mapProvide = inject<MapProvide>(MAP_PROVIDE);
9+
10+
const key = getMapInjectKey();
11+
12+
const props = defineProps({
13+
options: {
14+
type: Object as PropType<L.Control.AttributionOptions>,
15+
required: false
16+
}
17+
})
18+
19+
nextTick(() => {
20+
const attribution = L.control.attribution(props.options);
21+
mapProvide?.getMap(key)?.addControl(attribution);
22+
})
23+
24+
</script>
25+
26+
<template></template>

src/components/LControlLayers.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script setup lang="ts">
2+
import L from 'leaflet'
3+
import { PropType, inject, nextTick } from 'vue';
4+
import { MapProvide } from '../core/Map';
5+
import { MAP_PROVIDE, getMapInjectKey } from '../utils/injectKey';
6+
7+
8+
const mapProvide = inject<MapProvide>(MAP_PROVIDE);
9+
10+
const key = getMapInjectKey();
11+
12+
const props = defineProps({
13+
baseLayers: {
14+
type: Object as PropType<L.Control.LayersObject>,
15+
required: false
16+
},
17+
overlays: {
18+
type: Object as PropType<L.Control.LayersObject>,
19+
required: false
20+
},
21+
options: {
22+
type: Object as PropType<L.Control.LayersOptions>,
23+
required: false
24+
}
25+
})
26+
27+
nextTick(() => {
28+
const layers = L.control.layers(props.baseLayers, props.overlays, props.options);
29+
mapProvide?.getMap(key)?.addControl(layers);
30+
})
31+
32+
</script>
33+
34+
<template></template>

src/components/LControlScale.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script setup lang="ts">
2+
import L from 'leaflet'
3+
import { PropType, inject, nextTick } from 'vue';
4+
import { MapProvide } from '../core/Map';
5+
import { MAP_PROVIDE, getMapInjectKey } from '../utils/injectKey';
6+
7+
8+
const mapProvide = inject<MapProvide>(MAP_PROVIDE);
9+
10+
const key = getMapInjectKey();
11+
12+
const props = defineProps({
13+
options: {
14+
type: Object as PropType<L.Control.ScaleOptions>,
15+
required: false
16+
}
17+
})
18+
19+
nextTick(() => {
20+
const scale = L.control.scale(props.options);
21+
mapProvide?.getMap(key)?.addControl(scale);
22+
})
23+
24+
</script>
25+
26+
<template></template>

src/components/LControlZoom.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script setup lang="ts">
2+
import L from 'leaflet'
3+
import { PropType, inject, nextTick } from 'vue';
4+
import { MapProvide } from '../core/Map';
5+
import { MAP_PROVIDE, getMapInjectKey } from '../utils/injectKey';
6+
7+
8+
const mapProvide = inject<MapProvide>(MAP_PROVIDE);
9+
10+
const key = getMapInjectKey();
11+
12+
const props = defineProps({
13+
options: {
14+
type: Object as PropType<L.Control.ZoomOptions>,
15+
required: false
16+
}
17+
})
18+
19+
nextTick(() => {
20+
const zoom = L.control.zoom(props.options);
21+
mapProvide?.getMap(key)?.addControl(zoom);
22+
})
23+
24+
</script>
25+
26+
<template></template>

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ export { default as LCircleMarker } from './components/LCircleMarker.vue';
88
export { default as LPolygon } from './components/LPolygon.vue';
99
export { default as LPolyline } from './components/LPolyline.vue';
1010
export { default as LRectangle } from './components/LRectangle.vue';
11+
export { default as LControlAttribution } from './components/LControlAttribution.vue';
12+
export { default as LControlLayers } from './components/LControlLayers.vue';
13+
export { default as LControlScale } from './components/LControlScale.vue';
14+
export { default as LControlZoom } from './components/LControlZoom.vue';
15+

0 commit comments

Comments
 (0)