1.添加mapbox-gl 2.添加地图组件 3. 修改从vue引入插件提示错误的问题 4. 安装了mapbox-gl插件和@types/node插件
parent
8fb5c55450
commit
71797a2bb9
@ -0,0 +1,7 @@
|
||||
{
|
||||
"i18n-ally.localesPaths": [
|
||||
"src/locales",
|
||||
"src/locales/lang",
|
||||
"public/resource/tinymce/langs"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<div id="mapContainer" class="map-container"></div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, onUnmounted, defineProps } from 'vue';
|
||||
import mapboxgl from 'mapbox-gl';
|
||||
import 'mapbox-gl/dist/mapbox-gl.css';
|
||||
import './src/index.less';
|
||||
|
||||
interface MapboxOptions {
|
||||
mapOptions: mapboxgl.MapboxOptions;
|
||||
}
|
||||
const props = defineProps<MapboxOptions>();
|
||||
let map;
|
||||
const emit = defineEmits(['mapOnLoad']);
|
||||
onMounted(() => {
|
||||
mapboxgl.accessToken =
|
||||
'pk.eyJ1Ijoic2hpY2hhbzEyMyIsImEiOiJja3FobnI1aDEwNGF6Mm9vOXVhNnBzZmFhIn0.2fZKiMqCQHxVY74QShMEGQ';
|
||||
map = initMap();
|
||||
map.on('load', () => {
|
||||
emit('mapOnLoad', map);
|
||||
});
|
||||
});
|
||||
onUnmounted(() => {
|
||||
map ? map.remove() : null;
|
||||
});
|
||||
const initMap = () => {
|
||||
return new mapboxgl.Map({
|
||||
container: 'mapContainer',
|
||||
style: {
|
||||
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
|
||||
version: 8,
|
||||
sources: {
|
||||
'raster-tiles': {
|
||||
type: 'raster',
|
||||
tiles: [
|
||||
'https://t0.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=b6585bc41ee16251dbe6b1af64f375d9',
|
||||
],
|
||||
tileSize: 256,
|
||||
},
|
||||
},
|
||||
layers: [
|
||||
{
|
||||
id: 'tdt-img-tiles',
|
||||
type: 'raster',
|
||||
source: 'raster-tiles',
|
||||
minzoom: 0,
|
||||
maxzoom: 22,
|
||||
},
|
||||
],
|
||||
},
|
||||
...props.mapOptions,
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.map-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,3 @@
|
||||
.mapboxgl-ctrl-logo{
|
||||
display: none !important;
|
||||
}
|
||||
@ -1,17 +1,16 @@
|
||||
<template>
|
||||
<div class="p-4">
|
||||
<div class="md:flex enter-y">
|
||||
<VisitSource class="md:w-1/3 !md:mx-4 !md:my-0 !my-4 w-full" :loading="loading" />
|
||||
</div>
|
||||
<div class="w-full" style="height: 100%">
|
||||
<MapboxMaps :mapOptions="mapOptions" @map-on-load="mapOnLoad" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import VisitSource from './components/VisitSource.vue';
|
||||
import MapboxMaps from '@/components/MapboxMaps/index.vue';
|
||||
|
||||
const loading = ref(true);
|
||||
|
||||
setTimeout(() => {
|
||||
loading.value = false;
|
||||
}, 1500);
|
||||
const mapOptions = {
|
||||
center: [116.404, 39.905],
|
||||
zoom: 8,
|
||||
};
|
||||
const mapOnLoad = (map) => {
|
||||
console.log('map::: ', map);
|
||||
};
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue