Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb30d88
commit be41815
Showing
5 changed files
with
371 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<!-- Example Reference: https://codesandbox.io/s/v-mapbox-with-nuxt-lbrt6?file=/pages/index.vue --> | ||
<template> | ||
<client-only> | ||
<mgl-map | ||
:mapbox-gl="mapboxgl" | ||
:access-token="mapOptions.accessToken" | ||
:map-style.sync="mapOptions.style" | ||
:center="mapOptions.center" | ||
:zoom="mapOptions.zoom" | ||
:max-zoom="mapOptions.maxZoom" | ||
:cross-source-collisions="false" | ||
:fail-if-major-performance-caveat="false" | ||
:preserve-drawing-buffer="true" | ||
:hash="false" | ||
:min-pitch="0" | ||
:max-pitch="60" | ||
@load="onMapLoad" | ||
> | ||
<!-- TODO: Move into mapboxgl-control-container --> | ||
<div class="map-controls"> | ||
<ds-button | ||
v-for="style in styles.available" | ||
:key="style.title" | ||
filled | ||
size="small" | ||
:primary="mapOptions.style === style.url ? true : false" | ||
@click="setStyle(style.url)" | ||
> | ||
{{ style.title }} | ||
</ds-button> | ||
</div> | ||
</mgl-map> | ||
</client-only> | ||
</template> | ||
<script> | ||
import mapboxgl from "mapbox-gl"; | ||
export default { | ||
name: "Map", | ||
data() { | ||
return { | ||
mapboxgl, | ||
mapOptions: { | ||
accessToken: | ||
"pk.eyJ1IjoiYnVzZmFrdG9yIiwiYSI6ImNraDNiM3JxcDBhaWQydG1uczhpZWtpOW4ifQ.7TNRTO-o9aK1Y6MyW_Nd4g", // ocelot-token | ||
style: "mapbox://styles/mapbox/outdoors-v12?optimize=true", | ||
center: [10.452764, 51.165707], // center of Germany | ||
zoom: 4, | ||
maxZoom: 22, | ||
}, | ||
styles: { | ||
// https://docs.mapbox.com/api/maps/styles/ | ||
available: [ | ||
{ | ||
title: "Outdoors", | ||
url: "mapbox://styles/mapbox/outdoors-v12?optimize=true", | ||
}, | ||
{ | ||
title: "Streets", | ||
url: "mapbox://styles/mapbox/streets-v11?optimize=true", | ||
}, | ||
{ | ||
title: "Satellite", | ||
url: "mapbox://styles/mapbox/satellite-streets-v11?optimize=true", | ||
}, | ||
{ | ||
title: "Dark", | ||
url: "mapbox://styles/mapbox/dark-v10?optimize=true", | ||
}, | ||
], | ||
}, | ||
}; | ||
}, | ||
methods: { | ||
onMapLoad({ map }) { | ||
this.map = map; | ||
}, | ||
setStyle(url) { | ||
this.map.setStyle(url) | ||
this.mapOptions.style = url | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="scss"> | ||
.mapboxgl-canvas { | ||
height: 70vh; | ||
} | ||
.map-controls { | ||
position: absolute; | ||
left: 50px; | ||
top: 100px; | ||
} | ||
.map-controls button { | ||
margin-left: 5px; | ||
} | ||
.mapboxgl-control-container { | ||
margin-top: -45px; | ||
} | ||
.mapboxgl-control-container a { | ||
color: black; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Vue2 + Mapbox Reference: https://github.com/geospoc/v-mapbox/issues/702 | ||
import Vue from "vue"; | ||
import { | ||
MglGeojsonLayer, | ||
MglVectorLayer, | ||
MglMap, | ||
MglMarker, | ||
MglPopup, | ||
MglScaleControl, | ||
} from "v-mapbox"; | ||
|
||
// Map | ||
Vue.component("MglMap", MglMap); | ||
|
||
// Controls | ||
Vue.component("MglScaleControl", MglScaleControl); | ||
|
||
// Layers | ||
Vue.component("MglGeojsonLayer", MglGeojsonLayer); | ||
Vue.component("MglVectorLayer", MglVectorLayer); | ||
|
||
// Marker & Popup | ||
Vue.component("MglMarker", MglMarker); | ||
Vue.component("MglPopup", MglPopup); | ||
|
Oops, something went wrong.