Skip to content

Commit d8f3ca1

Browse files
committed
Add a locator map for the spatial extent
1 parent 1a28e05 commit d8f3ca1

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

src/components/Catalog.vue

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
bg-variant="light"
6565
class="float-right"
6666
>
67+
<template v-if="spatialExtent">
68+
<div id="locator-map"></div>
69+
</template>
6770
<div class="table-responsive">
6871
<table class="table">
6972
<tbody>
@@ -133,6 +136,7 @@
133136

134137
<script>
135138
import { HtmlRenderer, Parser } from "commonmark";
139+
import Leaflet from "leaflet";
136140
import spdxToHTML from "spdx-to-html";
137141
import { mapActions, mapGetters } from "vuex";
138142
@@ -185,7 +189,8 @@ export default {
185189
}
186190
},
187191
currentPage: 1,
188-
perPage: 25
192+
perPage: 25,
193+
locatorMap: null
189194
};
190195
},
191196
computed: {
@@ -327,8 +332,65 @@ export default {
327332
return this.catalog.version;
328333
}
329334
},
335+
mounted() {
336+
this.initialize();
337+
},
330338
methods: {
331339
...mapActions(["load"]),
340+
initialize() {
341+
if (this.spatialExtent != null) {
342+
this.initializeLocatorMap();
343+
}
344+
},
345+
initializeLocatorMap() {
346+
this.locatorMap = Leaflet.map("locator-map", {
347+
attributionControl: false,
348+
zoomControl: false,
349+
boxZoom: false,
350+
doubleClickZoom: false,
351+
dragging: false,
352+
scrollWheelZoom: false,
353+
touchZoom: false
354+
});
355+
356+
Leaflet.tileLayer(
357+
"https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}@2x.png",
358+
{
359+
attribution: `Map data <a href="https://www.openstreetmap.org/copyright">&copy; OpenStreetMap contributors</a>, &copy; <a href="https://carto.com/attributions">CARTO</a>`
360+
}
361+
).addTo(this.locatorMap);
362+
Leaflet.tileLayer(
363+
"https://{s}.basemaps.cartocdn.com/dark_only_labels/{z}/{x}/{y}@2x.png",
364+
{
365+
zIndex: 1000
366+
}
367+
).addTo(this.locatorMap);
368+
369+
const [minX, minY, maxX, maxY] = this.spatialExtent;
370+
const coordinates = [
371+
[[minX, minY], [minX, maxY], [maxX, maxY], [maxX, minY], [minX, minY]]
372+
];
373+
374+
const overlayLayer = Leaflet.geoJSON(
375+
{
376+
type: "Polygon",
377+
coordinates
378+
},
379+
{
380+
pane: "tilePane",
381+
style: {
382+
weight: 3,
383+
color: "#ffd65d",
384+
opacity: 1,
385+
fillOpacity: 0.15
386+
}
387+
}
388+
).addTo(this.locatorMap);
389+
390+
this.locatorMap.fitBounds(overlayLayer.getBounds(), {
391+
padding: [95, 95]
392+
});
393+
},
332394
sortCompare(a, b, key) {
333395
if (key === "link") {
334396
key = "title";
@@ -372,4 +434,14 @@ ul.links li,
372434
ul.items li {
373435
margin: 0 0 0.2em;
374436
}
437+
438+
.leaflet-container {
439+
background-color: #262626;
440+
}
441+
442+
#locator-map {
443+
height: 200px;
444+
width: 100%;
445+
margin-bottom: 10px;
446+
}
375447
</style>

0 commit comments

Comments
 (0)