北京经济技术开发区经开区虚拟城市项目-【前端】-移动端Web
lixuliang
2024-03-15 626003e9beb59cf711f59f3b48087300070f121e
src/utils/tool.js
@@ -1,7 +1,7 @@
import _GLOBAL from '@/assets/GLOBAL2'
import gcj02Mecator from '@/utils/transform'
import { ceil } from 'lodash';
//清除
export function clearAll() {
    if (_GLOBAL.ImageLayer) {
@@ -134,6 +134,40 @@
    });
    window.mapapi.addLayer(_GLOBAL.historyLayer);
}
var topResolution = 896.0859375;
var resolutions = [];
let matrixIds = [];
for (let zoom = 0; zoom < 13; zoom++) {
    resolutions.push(topResolution / Math.pow(2, zoom));
    matrixIds[zoom] = zoom;
}
//
// 加载历史影像路网
export function addHistoryLW(name) {
    const layerName = name;
    if (_GLOBAL.historyLW) {
        window.mapapi.removeLayer(_GLOBAL.historyLW)
    }
    _GLOBAL.historyLW = new ol.layer.Tile({
        source: new ol.source.WMTS({
            url: "https://skyzt.bda.gov.cn/service/ImageEngine/picdis/abc?",
            layer: "Shiliang_Lw_2019",
            style: "",
            format: "image/png",
            // 投影坐标系
            tileGrid: new ol.tilegrid.WMTS({
                extent: [371987.18334, 252920.58593, 624459.12036, 423400.07714],
                origin: [0, 688194],
                resolutions: resolutions,
                matrixIds: matrixIds,
                tileSize: 256,
            }),
        }),
    });
    window.mapapi.addLayer(_GLOBAL.historyLW);
}
//实时获取定位
export function getCurrentPosition() {
@@ -154,12 +188,15 @@
//创建当前定位点
export function createGPSMarker(position, rotate) {
    let GPSPOI_3857 = ol.proj.fromLonLat(position);
    // 记录当前位置(定位用)
    window.personalPoi = GPSPOI_3857;
    const GPSMarkerLayer = new ol.layer.Vector({
        id: 'LocationPoint',
        name: '定位点',
        source: new ol.source.Vector({
            features: [new ol.Feature({
                geometry: new ol.geom.Point(position),
                geometry: new ol.geom.Point(GPSPOI_3857),
            })]
        }),
        style: new ol.style.Style({