北京经济技术开发区经开区虚拟城市项目-【前端】-移动端Web
ZhAkps
2024-02-06 26385d2c91d763259eb1ef55c3255e5ca01717a5
src/utils/map2.js
@@ -2203,6 +2203,7 @@
//openlayer 创建点位
window.pointArr = [];
export function createPointMarker(position, obj) {
    let startFeature = new ol.Feature({
        geometry: new ol.geom.Point(position),
@@ -2210,6 +2211,12 @@
    startFeature.setProperties({
        desc: obj,
    });
    if (window.pointArr && window.pointArr.length > 0) {
        window.pointArr.forEach(item => {
            window.map.removeLayer(item)
        })
        window.pointArr = []
    }
    let MarkerLayer = new ol.layer.Vector({
        id: 'LocationPoint',
        name: '标记点',
@@ -2229,24 +2236,12 @@
        }),
        zIndex: 1099,
    })
    window.pointArr.push(MarkerLayer)
    return MarkerLayer;
}
//openlayer 地图点击事件
export function setClick(state) {
    console.log('setClick');
    let ponitPanel = document.getElementById('ponitPanel');
    let overlay = new ol.Overlay({
        element: ponitPanel,
        autoPan: {
            animation: {
                duration: 250,
            },
        },
    });
    window.map.addOverlay(overlay);
    // let _clickCallback = callback;
    function handleClick(e) {
        console.log(e.coordinate);
        // 土地管理
@@ -2351,7 +2346,7 @@
                                        rjl,
                                        jzxg,
                                        jzmd,
                                        lon:e.coordinate[0],
                                        lon: e.coordinate[0],
                                        lat: e.coordinate[1],
                                    }
                                }
@@ -2367,12 +2362,8 @@
            return;
        }
        window.map.forEachFeatureAtPixel(e.pixel, function (feature) {
            // console.log(feature, '111111')
            if (feature && feature.values_.desc) {
                ponitPanel.style.display = 'block'
                let obj = feature.values_.desc
                objdata = {
                    POITYPE: "POINT",
@@ -2381,24 +2372,9 @@
                    lon: obj.lng,
                    lat: obj.lat
                }
                ponitPanel.innerHTML = `
                       <div class="ponitPanel-name">
                         <span>名称:</span>
                         <span>${objdata.name}</span>
                       </div>
                     <div class="ponitPanel-value">
                        <span>地址:</span>
                       <span>${objdata.address}</span>
                    </div>`
                setTimeout(() => {
                    overlay.setPosition(e.coordinate);
                }, 0)
                // store.setPoplayerShowAction(true);
                // store.setPoplayerListAction(objdata);
                overlay.setPosition(e.coordinate);
                store.setPoplayerShowAction(true);
                store.setPoplayerListAction(objdata);
                // if (window.instance) {
                //     window.instance.$destroy();
                // }
@@ -2421,26 +2397,9 @@
export function flyToPoint(posisitons) {
    // let zoom = window.map.getView().getZoom();
    // if (zoom >= 16) {
    //     zoom = 12
    // }
    // let duration = 2000;
    window.map.getView().animate({
        center: posisitons,
        zoom: 12,
        zoom: 15,
        duration: 1500
    })
    // window.map.getView().animate(
    //     //动画开始时
    //     {
    //         zoom: zoom > 16 ? zoom - 0.01 : zoom + 0.01,
    //         duration: duration / 2,
    //     },
    //     //动画结束时
    //     {
    //         zoom: zoom >= 16 ? 16 : zoom + 4,
    //         duration: duration / 2,
    //     }
    // );
}