|
import _GLOBAL from '@/assets/GLOBAL2'
|
import gcj02Mecator from '@/utils/transform'
|
import { ceil } from 'lodash';
|
//清除
|
export function clearAll() {
|
if (_GLOBAL.ImageLayer) {
|
window.mapapi.removeLayer(_GLOBAL.ImageLayer);
|
}
|
if (_GLOBAL.annotation) {
|
window.mapapi.removeLayer(_GLOBAL.annotation);
|
}
|
if (_GLOBAL.hexin) {
|
window.mapapi.removeLayer(_GLOBAL.hexin);
|
}
|
if (_GLOBAL.yzxcgh) {
|
window.mapapi.removeLayer(_GLOBAL.yzxcgh);
|
}
|
if (_GLOBAL.baseMap) {
|
window.mapapi.removeLayer(_GLOBAL.baseMap);
|
}
|
if (_GLOBAL.geoMap) {
|
window.mapapi.removeLayer(_GLOBAL.geoMap);
|
|
}
|
}
|
|
//加载航拍影像
|
export function addImageLayer() {
|
_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}`,
|
}),
|
});
|
window.mapapi.addLayer(_GLOBAL.ImageLayer);
|
}
|
|
//加载白色地图
|
export function loadBaseMap() {
|
_GLOBAL.baseMap = new ol.layer.Tile({
|
source: new ol.source.TileWMS({
|
ratio: 3,
|
url: "https://skyzt.bda.gov.cn/gisserver/wmsserver/shiliangditu_baisexi_wms", //图层地址
|
params: {
|
VERSION: "1.1.1",
|
SRS: "EPSG:4326",
|
FORMAT: "image/png",
|
TILED: true,
|
LAYERS: "",
|
},
|
}),
|
});
|
window.mapapi.addLayer(_GLOBAL.baseMap)
|
|
}
|
|
//加载高德地图
|
export function loadGeoMap() {
|
_GLOBAL.geoMap = new ol.layer.Tile({
|
source: new ol.source.XYZ({
|
wrapX: false,
|
projection: gcj02Mecator,
|
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);
|
|
}
|
|
|
//加载高德标注
|
export function addAnnotationLayer() {
|
_GLOBAL.annotation = new ol.layer.Tile({
|
source: new ol.source.XYZ({
|
wrapX: false,
|
projection: gcj02Mecator,
|
url: `https://webst02.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}`,
|
}),
|
});
|
window.mapapi.addLayer(_GLOBAL.annotation);
|
}
|
|
// 核心区规划范围
|
export function addHxLayer() {
|
_GLOBAL.hexin = new ol.layer.Tile({
|
source: new ol.source.TileWMS({
|
ratio: 3,
|
url: 'https://skyzt.bda.gov.cn/gisserver/wmsserver/YZ_BJ60',
|
params: {
|
'VERSION': '1.1.1',
|
'SRS': 'EPSG:4326',
|
'FORMAT': 'image/png',
|
'TILED': true,
|
"LAYERS": ''
|
}
|
})
|
})
|
window.mapapi.addLayer(_GLOBAL.hexin)
|
}
|
|
//亦庄新城规划范围
|
export function addYzLayer() {
|
_GLOBAL.yzxcgh = new ol.layer.Tile({
|
source: new ol.source.TileWMS({
|
ratio: 3,
|
url: 'https://skyzt.bda.gov.cn/gisserver/wmsserver/YZ_BJ',//图层地址
|
params: {
|
'VERSION': '1.1.1',
|
'SRS': 'EPSG:4326',
|
'FORMAT': 'image/png',
|
'TILED': true,
|
"LAYERS": ''
|
}
|
})
|
})
|
window.mapapi.addLayer(_GLOBAL.yzxcgh)
|
}
|
|
//加载历史影像
|
export function addHistoryLayer(name) {
|
const layerName = name;
|
_GLOBAL.historyLayer = new ol.layer.Tile({
|
source: new ol.source.XYZ({
|
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);
|
}
|
|
|
//获取当前定位
|
var _rotate = 90;
|
var _marker = null;
|
var points = [];
|
|
export function randomPoint() {
|
let t = 116.505348;
|
let e = 39.795592;
|
t += .01 * Math.random();
|
e += .01 * Math.random();
|
points.push([t, e]);
|
}
|
|
|
export function getCurrentPosition() {
|
// setInterval(() => {
|
// randomPoint();
|
// }, 1000)
|
|
// console.log(points, '点位测试')
|
// _marker = createGPSMarker(points, _rotate);
|
// window.mapapi.addLayer(_marker)
|
|
if (navigator.geolocation) {
|
navigator.geolocation.watchPosition((res) => {
|
let lat = res.coords.latitude;
|
let lon = res.coords.longitude;
|
_marker = createGPSMarker([lon, lat], _rotate);
|
window.mapapi.addLayer(_marker)
|
});
|
}
|
|
}
|
|
|
export function createGPSMarker(position, rotate) {
|
const GPSMarkerLayer = new ol.layer.Vector({
|
id: 'LocationPoint',
|
name: '定位点',
|
source: new ol.source.Vector({
|
features: [new ol.Feature({
|
geometry: new ol.geom.Point(position),
|
})]
|
}),
|
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 (_marker) {
|
_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: _rotate,
|
anchorXUnits: "fraction",
|
anchorYUnits: "fraction",
|
scale: 0.5,
|
opacity: 1
|
})
|
})
|
)
|
}
|
}, false);
|
};
|