优化 mapbox 初始化逻辑
This commit is contained in:
parent
434fe7dc5a
commit
acf1ef664a
|
|
@ -1,4 +1,5 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
|
import { loadVectorLayer } from '@/utils/vector-layer-utils'
|
||||||
|
|
||||||
export function initMapbox(mapId, options = {}) {
|
export function initMapbox(mapId, options = {}) {
|
||||||
const map = new window.mapboxgl.Map({
|
const map = new window.mapboxgl.Map({
|
||||||
|
|
@ -51,10 +52,10 @@ export function initMapbox(mapId, options = {}) {
|
||||||
localIdeographFontFamily: "Microsoft YoHei, 'Noto Sans', 'Noto Sans CJK SC', sans-serif",
|
localIdeographFontFamily: "Microsoft YoHei, 'Noto Sans', 'Noto Sans CJK SC', sans-serif",
|
||||||
pitch: 0,
|
pitch: 0,
|
||||||
bearing: 0,
|
bearing: 0,
|
||||||
// // 禁用所有旋转和俯仰角控制
|
// 旋转和俯仰角控制
|
||||||
// dragRotate: false,
|
dragRotate: options.dragRotate || false,
|
||||||
// touchZoomRotate: false,
|
touchZoomRotate: options.touchZoomRotate || false,
|
||||||
// pitchWithRotate: false,
|
pitchWithRotate: options.pitchWithRotate || false,
|
||||||
// maxBounds: [[-180, -90], [180, 90]],// Set the map's geographical boundaries.
|
// maxBounds: [[-180, -90], [180, 90]],// Set the map's geographical boundaries.
|
||||||
antialias: true,
|
antialias: true,
|
||||||
attributionControl: false,
|
attributionControl: false,
|
||||||
|
|
@ -84,10 +85,13 @@ export function initMapbox(mapId, options = {}) {
|
||||||
|
|
||||||
map.on('load', () => {
|
map.on('load', () => {
|
||||||
// 加载海岸线
|
// 加载海岸线
|
||||||
// loadVectorLayer("GSHHS_f_L1", ["line"], ["#5c71c3"], "visible", "workUnitMap_ship", 'ougp');
|
if (options.coastlineOn || false)
|
||||||
|
loadVectorLayer("GSHHS_f_L1", ["line"], ["#5c71c3"], "visible", mapId, 'ougp');
|
||||||
// 加载等深线
|
// 加载等深线
|
||||||
// loadVectorLayer("contour-4500m", ["line"], ["#FEFEFE"], "visible", "workUnitMap_ship", 'ougp');
|
if (options.contourOn || false) {
|
||||||
// loadVectorLayer("contour-6000m", ["line"], ["#FEFEFE"], "visible", "workUnitMap_ship", 'ougp');
|
loadVectorLayer("contour-4500m", ["line"], ["#FEFEFE"], "visible", mapId, 'ougp');
|
||||||
|
loadVectorLayer("contour-6000m", ["line"], ["#FEFEFE"], "visible", mapId, 'ougp');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +132,7 @@ export function safeSetPaintProperty(map, layerId, property, value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleWheel(mapId = "home") {
|
export function handleWheel(mapId = "homeMap") {
|
||||||
document.addEventListener("keydown", () => {
|
document.addEventListener("keydown", () => {
|
||||||
// 允许鼠标滚轮缩放
|
// 允许鼠标滚轮缩放
|
||||||
Vue.config.maps[mapId].scrollZoom.enable();
|
Vue.config.maps[mapId].scrollZoom.enable();
|
||||||
|
|
@ -139,7 +143,7 @@ export function handleWheel(mapId = "home") {
|
||||||
}, { once: false, passive: false });
|
}, { once: false, passive: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initSprites(mapId = "home") {//../../../static/images/logo.png
|
export function initSprites(mapId = "homeMap") {//../../../static/images/logo.png
|
||||||
for (const sprite of Vue.config.sprites) {
|
for (const sprite of Vue.config.sprites) {
|
||||||
// Vue.config.maps[mapId].loadImage(`${Vue.config.baseUrl}/oe/${Vue.config.wwwrootBaseUrl}/sprites/${sprite}`, function (error, image) {
|
// Vue.config.maps[mapId].loadImage(`${Vue.config.baseUrl}/oe/${Vue.config.wwwrootBaseUrl}/sprites/${sprite}`, function (error, image) {
|
||||||
Vue.config.maps[mapId].loadImage(`./static/sprites/${sprite}`, function (error, image) {
|
Vue.config.maps[mapId].loadImage(`./static/sprites/${sprite}`, function (error, image) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue