diff --git a/src/utils/mapbox-utils.js b/src/utils/mapbox-utils.js index 6195d69..0a9b773 100644 --- a/src/utils/mapbox-utils.js +++ b/src/utils/mapbox-utils.js @@ -1,4 +1,5 @@ import Vue from 'vue' +import { loadVectorLayer } from '@/utils/vector-layer-utils' export function initMapbox(mapId, options = {}) { 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", pitch: 0, bearing: 0, - // // 禁用所有旋转和俯仰角控制 - // dragRotate: false, - // touchZoomRotate: false, - // pitchWithRotate: false, + // 旋转和俯仰角控制 + dragRotate: options.dragRotate || false, + touchZoomRotate: options.touchZoomRotate || false, + pitchWithRotate: options.pitchWithRotate || false, // maxBounds: [[-180, -90], [180, 90]],// Set the map's geographical boundaries. antialias: true, attributionControl: false, @@ -84,10 +85,13 @@ export function initMapbox(mapId, options = {}) { 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'); - // loadVectorLayer("contour-6000m", ["line"], ["#FEFEFE"], "visible", "workUnitMap_ship", 'ougp'); + if (options.contourOn || false) { + 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", () => { // 允许鼠标滚轮缩放 Vue.config.maps[mapId].scrollZoom.enable(); @@ -139,7 +143,7 @@ export function handleWheel(mapId = "home") { }, { 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) { // 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) {