Skip to content

Commit 80134c5

Browse files
committed
Locator map with fixed label z-indexes
1 parent 8b09a94 commit 80134c5

File tree

1 file changed

+63
-24
lines changed

1 file changed

+63
-24
lines changed

src/components/Item.vue

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
</div>
7878

7979
<div class="col-md-4">
80-
<!-- TODO locator map -->
80+
<div id="locator-map"></div>
8181
<div class="table-responsive">
8282
<table class="table">
8383
<thead>
@@ -145,19 +145,8 @@ export default {
145145
},
146146
data() {
147147
return {
148+
locatorMap: null,
148149
map: null,
149-
baseLayer: Leaflet.tileLayer(
150-
"https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}@2x.png",
151-
{
152-
attribution: `Map data <a href="https://www.openstreetmap.org/copyright">&copy; OpenStreetMap contributors</a>, &copy; <a href="https://carto.com/attributions">CARTO</a>`
153-
}
154-
),
155-
labelLayer: Leaflet.tileLayer(
156-
"https://{s}.basemaps.cartocdn.com/dark_only_labels/{z}/{x}/{y}@2x.png",
157-
{
158-
zIndex: 1000
159-
}
160-
),
161150
previewLayer: null,
162151
overlayLayer: null,
163152
geojsonOptions: {
@@ -343,6 +332,48 @@ export default {
343332
},
344333
methods: {
345334
initialize() {
335+
this.initializePreviewMap();
336+
this.initializeLocatorMap();
337+
},
338+
initializeLocatorMap() {
339+
this.locatorMap = Leaflet.map("locator-map", {
340+
attributionControl: false,
341+
zoomControl: false,
342+
boxZoom: false,
343+
doubleClickZoom: false,
344+
dragging: false,
345+
scrollWheelZoom: false,
346+
touchZoom: false
347+
});
348+
349+
Leaflet.tileLayer(
350+
"https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}@2x.png",
351+
{
352+
attribution: `Map data <a href="https://www.openstreetmap.org/copyright">&copy; OpenStreetMap contributors</a>, &copy; <a href="https://carto.com/attributions">CARTO</a>`
353+
}
354+
).addTo(this.locatorMap);
355+
Leaflet.tileLayer(
356+
"https://{s}.basemaps.cartocdn.com/dark_only_labels/{z}/{x}/{y}@2x.png",
357+
{
358+
zIndex: 1000
359+
}
360+
).addTo(this.locatorMap);
361+
362+
const overlayLayer = Leaflet.geoJSON(this.item, {
363+
pane: "tilePane",
364+
style: {
365+
weight: 1,
366+
color: "#ffd65d",
367+
opacity: 1,
368+
fillOpacity: 1
369+
}
370+
}).addTo(this.locatorMap);
371+
372+
this.locatorMap.fitBounds(overlayLayer.getBounds(), {
373+
padding: [95, 95]
374+
});
375+
},
376+
initializePreviewMap() {
346377
this.map = Leaflet.map("map");
347378
this.map.on("moveend", this.updateHash);
348379
this.map.on("zoomend", this.updateHash);
@@ -361,18 +392,29 @@ export default {
361392
this.map.getContainer().classList.add("leaflet-pseudo-fullscreen");
362393
}
363394
364-
this.baseLayer.addTo(this.map);
365-
this.labelLayer.addTo(this.map);
395+
Leaflet.tileLayer(
396+
"https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}@2x.png",
397+
{
398+
attribution: `Map data <a href="https://www.openstreetmap.org/copyright">&copy; OpenStreetMap contributors</a>, &copy; <a href="https://carto.com/attributions">CARTO</a>`
399+
}
400+
).addTo(this.map);
401+
Leaflet.tileLayer(
402+
"https://{s}.basemaps.cartocdn.com/dark_only_labels/{z}/{x}/{y}@2x.png",
403+
{
404+
zIndex: 1000
405+
}
406+
).addTo(this.map);
366407
367408
if (this.tileSource) {
368409
this.tileLayer = Leaflet.tileLayer(this.tileSource, {
369410
attribution: this.attribution
370411
}).addTo(this.map);
371412
}
372413
373-
this.overlayLayer = Leaflet.geoJSON(this.item, this.geojsonOptions).addTo(
374-
this.map
375-
);
414+
this.overlayLayer = Leaflet.geoJSON(this.item, {
415+
...this.geojsonOptions,
416+
pane: "tilePane"
417+
}).addTo(this.map);
376418
377419
if (this.center != null) {
378420
const [zoom, lat, lng] = this.center;
@@ -532,13 +574,10 @@ code {
532574
z-index: 99999;
533575
}
534576
535-
.vue2leaflet-map {
577+
#locator-map {
578+
height: 200px;
536579
width: 100%;
537-
height: 100%;
538-
border: 1px solid #fff;
539-
background-color: #090909;
540-
z-index: 1;
541-
position: relative;
580+
margin-bottom: 10px;
542581
}
543582
544583
#map-container {

0 commit comments

Comments
 (0)