| | |
| | | |
| | | import _GLOBAL from '@/assets/GLOBAL2' |
| | | import gcj02Mecator from '@/utils/transform' |
| | | |
| | | //清除 |
| | | export function clearAll() { |
| | | if (_GLOBAL.ImageLayer) { |
| | |
| | | _GLOBAL.ImageLayer = new ol.layer.Tile({ |
| | | source: new ol.source.XYZ({ |
| | | url: `${'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'}/tile/{z}/{y}/{x}`, |
| | | projection: "EPSG:3857", |
| | | tileSize: 512 |
| | | }), |
| | | }); |
| | | window.mapapi.addLayer(_GLOBAL.ImageLayer); |
| | | // window.mapapi.addLayer(_GLOBAL.ImageLayer); |
| | | layersArray.insertAt(1, _GLOBAL.ImageLayer); |
| | | } |
| | | |
| | | //加载白色地图 |
| | |
| | | url: "https://skyzt.bda.gov.cn/gisserver/wmsserver/shiliangditu_baisexi_wms", //图层地址 |
| | | params: { |
| | | VERSION: "1.1.1", |
| | | SRS: "EPSG:4326", |
| | | SRS: "EPSG:3857", |
| | | FORMAT: "image/png", |
| | | TILED: true, |
| | | LAYERS: "", |
| | | }, |
| | | }), |
| | | }); |
| | | window.mapapi.addLayer(_GLOBAL.baseMap) |
| | | // window.mapapi.addLayer(_GLOBAL.baseMap) |
| | | layersArray.insertAt(1, _GLOBAL.baseMap); |
| | | |
| | | } |
| | | |
| | |
| | | url: ` https://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}`, |
| | | }), |
| | | }); |
| | | window.mapapi.addLayer(_GLOBAL.geoMap); |
| | | |
| | | // window.mapapi.addLayer(_GLOBAL.geoMap); |
| | | layersArray.insertAt(1, _GLOBAL.geoMap); |
| | | } |
| | | |
| | | |
| | |
| | | url: 'https://skyzt.bda.gov.cn/gisserver/wmsserver/YZ_BJ60', |
| | | params: { |
| | | 'VERSION': '1.1.1', |
| | | 'SRS': 'EPSG:4326', |
| | | 'SRS': 'EPSG:3857', |
| | | 'FORMAT': 'image/png', |
| | | 'TILED': true, |
| | | "LAYERS": '' |
| | |
| | | url: 'https://skyzt.bda.gov.cn/gisserver/wmsserver/YZ_BJ',//图层地址 |
| | | params: { |
| | | 'VERSION': '1.1.1', |
| | | 'SRS': 'EPSG:4326', |
| | | 'SRS': 'EPSG:3857', |
| | | 'FORMAT': 'image/png', |
| | | 'TILED': true, |
| | | "LAYERS": '' |
| | |
| | | //加载历史影像 |
| | | export function addHistoryLayer(name) { |
| | | const layerName = name; |
| | | if (_GLOBAL.historyLayer) { |
| | | window.mapapi.removeLayer(_GLOBAL.historyLayer) |
| | | } |
| | | _GLOBAL.historyLayer = new ol.layer.Tile({ |
| | | source: new ol.source.XYZ({ |
| | | projection: "EPSG:3857", |
| | | url: `https://skyzt.bda.gov.cn/yzAdapter/Vector/?request=1&year=${layerName}&type=Sate&level={z}&x={x}&y={y}`, |
| | | }) |
| | | }); |
| | | window.mapapi.addLayer(_GLOBAL.historyLayer); |
| | | // window.mapapi.addLayer(_GLOBAL.historyLayer); |
| | | layersArray.insertAt(1, _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() { |
| | | if (navigator.geolocation) { |
| | | navigator.geolocation.getCurrentPosition((res) => { |
| | | console.log(res);//这里会返回经纬度,然后还要通过经纬度转换地区名称 |
| | | navigator.geolocation.watchPosition((res) => { |
| | | let lat = res.coords.latitude; |
| | | let lon = res.coords.longitude; |
| | | if (_GLOBAL.GPSMarker) { |
| | | window.mapapi.removeLayer(_GLOBAL.GPSMarker) |
| | | } |
| | | _GLOBAL.GPSMarker = createGPSMarker([lon, lat], _GLOBAL.rotate); |
| | | window.mapapi.addLayer(_GLOBAL.GPSMarker) |
| | | |
| | | }); |
| | | } |
| | | |
| | | } |
| | | |
| | | //创建当前定位点 |
| | | 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(GPSPOI_3857), |
| | | })] |
| | | }), |
| | | style: new ol.style.Style({ |
| | | image: new ol.style.Icon({ |
| | | src: require('@/assets/img/collection/mark.png'), |
| | | anchorOrigin: "top-left", |
| | | anchorXUnits: "fraction", |
| | | anchorYUnits: "fraction", |
| | | offsetOrigin: "bottom-right", |
| | | scale: 0.6, |
| | | rotation: rotate, |
| | | opacity: 1, |
| | | }) |
| | | }), |
| | | zIndex: 9999, |
| | | }); |
| | | |
| | | return GPSMarkerLayer |
| | | }; |
| | | |
| | | |
| | | //监听定位点跟随旋转 |
| | | export function listenDirection() { |
| | | window.addEventListener('deviceorientation', function (e) { |
| | | if (_GLOBAL.GPSMarker) { |
| | | _GLOBAL.rotate = e.alpha * (Math.PI / -180); |
| | | _marker.setStyle( |
| | | new ol.style.Style({ |
| | | image: new ol.style.Icon({ |
| | | anchor: [0.5, 0.5], |
| | | anchorOrigin: 'top-left', |
| | | src: require('@/assets/img/collection/mark.png'), |
| | | rotation: _GLOBAL.rotate, |
| | | anchorXUnits: "fraction", |
| | | anchorYUnits: "fraction", |
| | | scale: 0.5, |
| | | opacity: 1 |
| | | }) |
| | | }) |
| | | ) |
| | | } |
| | | }, false); |
| | | }; |
| | | |
| | | |
| | | |
| | | |