gpt4 book ai didi

javascript - Vue.js 单文件组件中的 Mapbox-gl (Quasar-Framework)

转载 作者:搜寻专家 更新时间:2023-10-30 22:19:00 24 4
gpt4 key购买 nike

我想在 Quasar Framework (Vue) 单文件组件中实现一个 Mapbox-gl-js map ,但我没有让它工作。我用 Vue 在 Googlemaps 上找到了一些代码,用 React 在 Mapbox 上找到了一些东西,并尝试将它们组合在一起。使用下面的 map 初始化参数,我可以让 map 在 index.html(使用 mapzen tiles)中正常显示,但希望它在组件中。

我尝试遵循这个 [ https://laracasts.com/discuss/channels/vue/google-maps-and-vue-js](link url) 然后为 Mapbox 调整它:proj/src/components/mapplayout.vue :

<template>
<quasar-layout>
<h3>Map</h3>
<div id='map'></div>
</quasar-layout>
</template>

<script>
import mapboxgl from '../app'

export default {
data () {
return {}
},
create () {
this.createMap()
},
methods: {
createMap: function () {
mapboxgl.accessToken = '{{yourmapboxaccestokenkey}}'
var simple = {
'version': 8,
'sources': {
'osm': {
'type': 'vector',
'tiles': ['https://vector.mapzen.com/osm/all/{z}/{x}/{y}.mvt?api_key=vector-tiles-{{yourmapzenapikey}}']
}
},
'layers': [{
'id': 'background',
'type': 'background',
'paint': {
'background-color': '#adddd2'
}
}, {
'id': 'majorroad',
'source': 'osm',
'source-layer': 'roads',
'type': 'line'
}, {
'id': 'buildings',
'type': 'fill',
'source': 'osm',
'source-layer': 'buildings'
}]
}

// initialize the map
this.map = new mapboxgl.Map({
container: 'map',
style: simple,
center: [-1.83, -78.183],
zoom: 5.5
})
}
}
}
</script>

<style>
</style>

顺便说一句,对于带有 webpack 的 mapbox,你需要特定的加载器,请参阅:[ https://mikewilliamson.wordpress.com/2016/02/24/using-mapbox-gl-and-webpack-together/](link网址)但是当我之前让 Mapbox 与 Webpack 一起工作时(没有 vue),我想我没问题。实际上我在浏览器控制台中没有收到任何错误(但显然没有 map 出现)。

在 app.js 文件中,我不知道如何处理建议(可能没有必要,因为 googlemaps 需要回调,不知道 mapbox/mapzen?!):

var App = window.App = new Vue ({
//code
})

在 Quasar 中,初始化是这样完成的:

Quasar.start(() => {
Router.start(Vue.extend({}), '#quasar-app')
})

我真的不明白...

欢迎提出任何如何实现此功能的建议!

最佳答案

我很接近。这实际上有效:

<template>
<quasar-layout>
<h3>Map</h3>
<div id='map'></div>
</quasar-layout>
</template>

<script>
import mapboxgl from 'mapbox-gl'
console.dir(mapboxgl)

export default {
data () {
return {}
},
ready () {
this.createMap()
},
methods: {
createMap: function () {
mapboxgl.accessToken = '{{yourmapboxaccestokenkey}}'
var simple = {
'version': 8,
'sources': {
'osm': {
'type': 'vector',
'tiles': ['https://vector.mapzen.com/osm/all/{z}/{x}/{y}.mvt?api_key=vector-tiles-{{yourmapzenapikey}}']
}
},
'layers': [{
'id': 'background',
'type': 'background',
'paint': {
'background-color': '#bbccd2'
}
},
{
'id': 'majorroad',
'source': 'osm',
'source-layer': 'roads',
'type': 'line'
},
{
'id': 'buildings',
'type': 'fill',
'source': 'osm',
'source-layer': 'buildings'
}]
}

// init the map
this.map = new mapboxgl.Map({
container: 'map',
style: simple,
minzoom: 1.3,
center: [-74.0073, 40.7124], // Manhattan
zoom: 16
})

this.map.addControl(new mapboxgl.Navigation())
}
}
}
</script>

<style>
</style>

我没有更改我的 Vue 初始化。

关于javascript - Vue.js 单文件组件中的 Mapbox-gl (Quasar-Framework),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39664953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com