Commit 2917f8e2 by wangzhihui

高德地图切换成百度地图

1 parent 2df36f38
...@@ -10,8 +10,8 @@ function request (data = {} , url, method = 'GET') { ...@@ -10,8 +10,8 @@ function request (data = {} , url, method = 'GET') {
url: url, url: url,
data: data, data: data,
success(data) { success(data) {
console.log(data) // console.log(data)
console.log('结束请求:',new Date().getTime()) // console.log('结束请求:',new Date().getTime())
resolve(data) resolve(data)
}, },
error(error) { error(error) {
......
<!--
* @Author: 'wangzhihui' '1733904062@qq.com'
* @Date: 2024-11-28 16:37:15
* @LastEditors: 'wangzhihui' '1733904062@qq.com'
* @LastEditTime: 2024-12-09 22:18:27
* @FilePath: \oEshield\src\pages\monitor\MapControll.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template> <template>
<div> <div>
<div :class="isTreeToright ? 'map-controll toleft' : 'map-controll'"> <div :class="isTreeToright ? 'map-controll toleft' : 'map-controll'">
...@@ -19,7 +27,7 @@ ...@@ -19,7 +27,7 @@
</template> </template>
<script> <script>
import store from '../../vuex/store.js' import store from '../../vuex/store.js'
import mapService from 'utils/mapService.js' import mapService from 'utils/mapBService.js'
export default{ export default{
props: ['isShowFullsize', 'isTreeToright'], props: ['isShowFullsize', 'isTreeToright'],
data(){ data(){
...@@ -43,7 +51,7 @@ ...@@ -43,7 +51,7 @@
}, },
toggleMap(ifSetTypeIsMap){ toggleMap(ifSetTypeIsMap){
if(ifSetTypeIsMap != this.isMapType){ if(ifSetTypeIsMap != this.isMapType){
mapService.toggleMapType(); mapService.toggleMapType(ifSetTypeIsMap);
this.isMapType = !this.isMapType; this.isMapType = !this.isMapType;
} }
}, },
......
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
</v-full-layout> </v-full-layout>
</template> </template>
<script> <script>
import mapService from "@/utils/mapService.js"; // import mapService from "@/utils/mapService.js";
import mapService from "@/utils/mapBService.js";
import "@/utils/mapEvent.js"; import "@/utils/mapEvent.js";
import EventBus from "@/event-bus"; import EventBus from "@/event-bus";
import remoteLoad from "@/utils/remoteLoad.js"; import remoteLoad from "@/utils/remoteLoad.js";
...@@ -59,57 +60,41 @@ export default { ...@@ -59,57 +60,41 @@ export default {
}; };
}, },
created() { created() {
console.log(history.state); // let _this = this;
let _this = this; // _this.$mapInit({ }).then((AMap) => {
_this.$mapInit({ }).then((AMap) => { // _this.initMap();
_this.initMap(); // });
}); this.initBMap();
}, },
methods: { methods: {
// 初始化地图 async initBMap() {
initMap() { this.mapObj = await mapService.init("map");
let check = () => { window.AMap = this.mapObj;
if (this.checkLoadedTimeoutId) { this.isInitMap = true;
window.clearTimeout(this.checkLoadedTimeoutId); let query = this.$route.query;
} let o = history.state;
return setTimeout(() => {
if (
"AMap" in window &&
typeof AMap.Map == "function" &&
!this.mapObj
) {
window.AMap = AMap;
this.mapObj = mapService.init("map");
this.isInitMap = true;
let query = this.$route.query;
let o = history.state;
// 假性离线报警查看位置点 console.log(query);
if (query.sns) { // 假性离线报警查看位置点
this.getLocation(query.sns); if (query.sns) {
return false; this.getLocation(query.sns);
} return false;
}
// 兼容其他页面的跳转 // 兼容其他页面的跳转
if (query && query.sn) { if (query && query.sn) {
query.elat = query.lat; query.elat = query.lat;
query.elng = query.lng; query.elng = query.lng;
this.addLocation(query, true); this.addLocation(query, true);
return false; return false;
} }
console.log(o); console.log(o);
if (o.lng || o.bsLng) { if (o.lng || o.bsLng) {
o.elat = o.lat; o.elat = o.lat;
o.elng = o.lng; o.elng = o.lng;
this.addLocation(o, true); this.addLocation(o, true);
} }
} else {
this.checkLoadedTimeoutId = check();
}
}, 100);
};
this.checkLoadedTimeoutId = check();
}, },
// 添加位置点 // 添加位置点
...@@ -125,7 +110,6 @@ export default { ...@@ -125,7 +110,6 @@ export default {
oParams.deviceCode = "gps"; oParams.deviceCode = "gps";
GET_DEVICEINFO_BYSNS(oParams).then((res) => { GET_DEVICEINFO_BYSNS(oParams).then((res) => {
let list = res.data || []; let list = res.data || [];
// 循环标记车辆 // 循环标记车辆
list.map((k) => { list.map((k) => {
let o = this.getMapInfo(k); let o = this.getMapInfo(k);
......
...@@ -183,7 +183,8 @@ ...@@ -183,7 +183,8 @@
</template> </template>
<script> <script>
import "@/assets/spritesmith-generated/sprite.css"; import "@/assets/spritesmith-generated/sprite.css";
import mapService from "@/utils/mapService.js"; // import mapService from "@/utils/mapService.js";
import mapService from "@/utils/mapBService.js";
import "@/utils/mapEvent.js"; import "@/utils/mapEvent.js";
import EventBus from "@/event-bus"; import EventBus from "@/event-bus";
import { services } from "@/api"; import { services } from "@/api";
...@@ -326,7 +327,8 @@ export default { ...@@ -326,7 +327,8 @@ export default {
let _query = this.$route.query; let _query = this.$route.query;
this.$set(this.form, "source", _query.source || 0); this.$set(this.form, "source", _query.source || 0);
this.initMap(); // this.initMap();
this.initBMap();
}, },
mounted() { mounted() {
//store.dispatch("setFullsize", true); //store.dispatch("setFullsize", true);
...@@ -340,15 +342,11 @@ export default { ...@@ -340,15 +342,11 @@ export default {
}, },
}, },
methods: { methods: {
// 初始化地图 //初始化百度地图
initMap() { async initBMap(){
let _this = this; this.mapObj = await mapService.init("map");
_this.$mapInit().then((AMap) => { window.AMap = this.mapObj;
window.AMap = AMap; this.getDevinceInfo()
window.AMap = AMap;
_this.map = mapService.init("map");
_this.getDevinceInfo();
});
}, },
// 获取设备信息 // 获取设备信息
...@@ -478,20 +476,21 @@ export default { ...@@ -478,20 +476,21 @@ export default {
// 监听圆形围栏直径变化 // 监听圆形围栏直径变化
onFenceRadiusChange(e) { onFenceRadiusChange(e) {
console.log("圆形围栏:", e); if(e){
this.$set(this.form, "radius", e); this.$set(this.form, "radius", e);
}
}, },
// 监听围栏类型变化 // 监听围栏类型变化
changeShapeType(e) { changeShapeType(e) {
let _this = this; let _this = this;
let _info = this.deviceInfo; let _info = this.deviceInfo;
let areaCode = this.form.areaCode || []; let areaText = this.form.areaText || [];
// 1:圆形围栏 4:行政区域 3:多边形 // 1:圆形围栏 4:行政区域 3:多边形
console.log(_info);
switch (e) { switch (e) {
case 4: case 4:
_this.drawDistrict(areaCode); _this.drawDistrict(areaText);
break; break;
case 3: case 3:
_this.drawPolygon(); _this.drawPolygon();
...@@ -509,10 +508,9 @@ export default { ...@@ -509,10 +508,9 @@ export default {
// 监听行政区域 // 监听行政区域
changeArea(e) { changeArea(e) {
console.log(e);
this.form.areaCode = e.code; this.form.areaCode = e.code;
this.form.areaText = e.name; this.form.areaText = e.name;
this.drawDistrict(e.code); this.drawDistrict(e.name);
this.$refs.form.clearValidate(); this.$refs.form.clearValidate();
}, },
...@@ -521,7 +519,6 @@ export default { ...@@ -521,7 +519,6 @@ export default {
let _this = this; let _this = this;
let o = deepClone(_this.form); let o = deepClone(_this.form);
let query = this.$route.query; let query = this.$route.query;
console.log(o);
let oParams = {}; let oParams = {};
let deviceList = this.deviceList; let deviceList = this.deviceList;
...@@ -547,7 +544,10 @@ export default { ...@@ -547,7 +544,10 @@ export default {
// 多边形围栏 // 多边形围栏
if (o.shapeType == 3) { if (o.shapeType == 3) {
oParams.lnglat = this.polygonPath.join("|"); let lnglats = this.polygonPath.map((item) => {
return item.lng + "," + item.lat;
});
oParams.lnglat = lnglats.join("|");
} }
// 行政区域围栏 // 行政区域围栏
......
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
<script> <script>
import store from "../../vuex/store.js"; import store from "../../vuex/store.js";
import remoteLoad from "utils/remoteLoad.js"; import remoteLoad from "utils/remoteLoad.js";
import mapService from "utils/mapService.js"; import mapService from "utils/mapBService.js";
import "utils/mapEvent.js"; import "utils/mapEvent.js";
import EventBus from "../../event-bus"; import EventBus from "../../event-bus";
import { services } from "../../api"; import { services } from "../../api";
...@@ -246,13 +246,14 @@ export default { ...@@ -246,13 +246,14 @@ export default {
}, },
mounted() { mounted() {
// store.dispatch('setFullsize', true) // store.dispatch('setFullsize', true)
let _this = this; this.initBMap();
_this.$mapInit({version:'1.4.2'}).then(AMap => {
window.AMap = AMap;
_this.initMap();
})
}, },
methods: { methods: {
async initBMap() {
this.mapObj = await mapService.init("map");
window.AMap = this.mapObj;
this.isInitMap = true;
},
initMap() { initMap() {
let check = () => { let check = () => {
this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded); this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded);
......
...@@ -188,7 +188,8 @@ ...@@ -188,7 +188,8 @@
<script> <script>
import store from "../../vuex/store.js"; import store from "../../vuex/store.js";
import remoteLoad from "utils/remoteLoad.js"; import remoteLoad from "utils/remoteLoad.js";
import mapService from "utils/mapService.js"; // import mapService from "utils/mapService.js";
import mapService from "@/utils/mapBService.js";
import "utils/mapEvent.js"; import "utils/mapEvent.js";
import EventBus from "../../event-bus"; import EventBus from "../../event-bus";
import { services } from "../../api"; import { services } from "../../api";
...@@ -331,38 +332,17 @@ export default { ...@@ -331,38 +332,17 @@ export default {
}, },
}, },
methods: { methods: {
initMap() { async initBMap(){
let _this = this; this.mapObj = await mapService.init("map");
let check = () => { window.AMap = this.mapObj;
_this.checkMapLoaded && window.clearTimeout(_this.checkMapLoaded); this.isInitMap = true;
if (
return setTimeout(() => { this.isInitFence &&
if ( this.fenceId &&
"AMap" in window && this.fenceId != "undefined"
typeof AMap.Map == "function" &&
!_this.mapObj
) {
window.AMap = AMap;
_this.mapObj = mapService.init("map");
//this.bindEvent();
_this.isInitMap = true;
//_this.drawPoi();
console.log(_this.fenceId != "undefined");
if (
_this.isInitFence &&
_this.fenceId &&
_this.fenceId != "undefined"
) { ) {
//_this.drawFence(); this.getFence();
_this.getFence();
} }
} else {
_this.checkMapLoaded = check();
}
}, 100);
};
_this.checkMapLoaded = check();
}, },
pickDate(recentHoursOrDays) { pickDate(recentHoursOrDays) {
let unit = "days"; let unit = "days";
...@@ -668,8 +648,6 @@ export default { ...@@ -668,8 +648,6 @@ export default {
drawPoi() { drawPoi() {
let _this = this; let _this = this;
BUSINESS_SERVICE.getPOI({ sn: _this.sn }).then((res) => { BUSINESS_SERVICE.getPOI({ sn: _this.sn }).then((res) => {
console.log("666666666666");
console.log(res);
if (res.returnCode === "0") { if (res.returnCode === "0") {
if (res.data && res.data.length) { if (res.data && res.data.length) {
res.data.forEach((item) => { res.data.forEach((item) => {
...@@ -687,48 +665,18 @@ export default { ...@@ -687,48 +665,18 @@ export default {
} }
}); });
}, },
drawFence() {
MONITOR_SERVICE.getSingleFence({
sn: this.sn,
fenceId: parseInt(this.fenceId),
}).then((res) => {
if (res.returnCode == 0) {
const data = res.data;
if (data) {
if (data.shapeType === 2) {
EventBus.$emit("uiMap.fence.createFenceCircle", {
lng: data.lng,
lat: data.lat,
radius: data.radius,
isEdit: false,
});
} else if (data.shapeType === 3) {
this.drawDistrict(data.areaCode);
} else if (data.shapeType === 5) {
if (data.lnglat) {
let polygonPath = data.lnglat.split("|").map((item) => {
return [item.split(",")[0], item.split(",")[1]];
});
this.drawPolygon(polygonPath);
}
}
}
}
});
},
// 行政区域围栏 // 行政区域围栏
drawDistrict(areaCode) { drawDistrict(areaText) {
this._drawDistrictTimeoutId && clearTimeout(this._drawDistrictTimeoutId); this._drawDistrictTimeoutId && clearTimeout(this._drawDistrictTimeoutId);
this._drawDistrictTimeoutId = setTimeout(() => { this._drawDistrictTimeoutId = setTimeout(() => {
EventBus.$emit("uiMap.fence.drawDistrict", areaCode); EventBus.$emit("uiMap.fence.drawDistrict", areaText);
}, 500); }, 500);
}, },
// 多边形围栏 // 多边形围栏
drawPolygon(path) { drawPolygon(path) {
console.log("path");
EventBus.$emit("uiMap.fence.drawPolygon", { EventBus.$emit("uiMap.fence.drawPolygon", {
path, path,
isEdit: false, isEdit: false,
...@@ -741,7 +689,6 @@ export default { ...@@ -741,7 +689,6 @@ export default {
//sn: this.sn, //sn: this.sn,
fenceId: this.fenceId, fenceId: this.fenceId,
}).then((res) => { }).then((res) => {
console.log(res);
let list = res.data || []; let list = res.data || [];
if (res.code != 200) { if (res.code != 200) {
return false; return false;
...@@ -767,31 +714,23 @@ export default { ...@@ -767,31 +714,23 @@ export default {
// 行政区域围栏 // 行政区域围栏
if (obj.shapeType == 4) { if (obj.shapeType == 4) {
this.drawDistrict([obj.areaCode]); this.drawDistrict([obj.areaText]);
} }
}); });
}, },
}, },
created() { created() {
let _this = this; // let _this = this;
let _config = { version: "1.4.2" }; // let _config = { version: "1.4.2" };
_config.AMapUI = { // _config.AMapUI = {
version: "1.1", // version: "1.1",
plugins: ["/misc/PathSimplifier"], // plugins: ["/misc/PathSimplifier"],
}; // };
_this.$mapInit(_config).then((AMap) => { // _this.$mapInit(_config).then((AMap) => {
console.log(window.AMap); // _this.initMap();
_this.initMap(); // });
// if (AMap) { this.initBMap();
// remoteLoad(`https://webapi.amap.com/ui/1.0/main.js?v=1.0.11`).then(
// () => {
// _this.initMap();
// }
// );
// }
});
//轨迹播放当前位置地址显示 //轨迹播放当前位置地址显示
EventBus.$on("uiMap.replay.currAddress", (adr) => { EventBus.$on("uiMap.replay.currAddress", (adr) => {
this.replayAddr = adr; this.replayAddr = adr;
...@@ -845,4 +784,5 @@ export default { ...@@ -845,4 +784,5 @@ export default {
.clearMargin { .clearMargin {
margin-left: 0px; margin-left: 0px;
} }
</style>
\ No newline at end of file \ No newline at end of file
</style>
...@@ -101,7 +101,8 @@ ...@@ -101,7 +101,8 @@
<script> <script>
import store from "../../vuex/store.js"; import store from "../../vuex/store.js";
import remoteLoad from "utils/remoteLoad.js"; import remoteLoad from "utils/remoteLoad.js";
import mapService from "utils/mapService.js"; // import mapService from "utils/mapService.js";
import mapService from "@/utils/mapBService.js";
import "utils/mapEvent.js"; import "utils/mapEvent.js";
import EventBus from "../../event-bus"; import EventBus from "../../event-bus";
import { services } from "../../api"; import { services } from "../../api";
...@@ -142,36 +143,13 @@ export default { ...@@ -142,36 +143,13 @@ export default {
}; };
}, },
mounted() { mounted() {
// store.dispatch('setFullsize', true) this.initBMap();
let _this = this;
_this.$mapInit({ version: "1.4.2" }).then((AMap) => {
window.AMap = AMap;
_this.initMap();
});
}, },
methods: { methods: {
initMap() { async initBMap() {
let check = () => { this.mapObj = await mapService.init("map");
this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded); window.AMap = this.mapObj;
this.isInitMap = true;
return setTimeout(() => {
if (
"AMap" in window &&
typeof AMap.Map == "function" &&
!this.mapObj
) {
window.AMap = AMap;
this.mapObj = mapService.init("map");
//this.bindEvent();
this.isInitMap = true;
// this.drawPoi()
} else {
this.checkMapLoaded = check();
}
}, 100);
};
this.checkMapLoaded = check();
}, },
pickDate(beforeDays) { pickDate(beforeDays) {
this.form.dateRange = [ this.form.dateRange = [
...@@ -279,35 +257,6 @@ export default { ...@@ -279,35 +257,6 @@ export default {
exportExcel() { exportExcel() {
if (this.exporting) return; if (this.exporting) return;
if (this.resultList.length) { if (this.resultList.length) {
// let paramArr = [];
// this.resultList.forEach((dataItem)=>{
// let paramItem = {};
// for(let key in dataItem){
// switch(key){
// case 'name':
// case 'shopName':
// case 'sn':
// case 'sqbh':
// case 'standNo':
// case 'totalDurationString':
// case 'transferAddress':
// paramItem[key] = dataItem[key]?dataItem[key]:'';
// break;
// case 'totalTimes':
// paramItem[key] = dataItem[key]?(dataItem[key]+'次'):'';
// break;
// /*case 'transferAddress':
// paramItem.address = dataItem.transferAddress?dataItem.transferAddress:'';
// break;*/
// }
// }
// paramArr.push(paramItem);
// });
// exportExcel('track/exportVMData', {
// jsonStr: encodeURI(JSON.stringify(paramArr)),
// vmExportType: 4
// }, 'post');
exportExcel( exportExcel(
"/trialdrive/monitor/exportResident", "/trialdrive/monitor/exportResident",
{ ...this.params }, { ...this.params },
...@@ -349,7 +298,6 @@ export default { ...@@ -349,7 +298,6 @@ export default {
}, },
}, },
async created() { async created() {
EventBus.$on("uiMap.historyLocation.transferSuccess", (data) => { EventBus.$on("uiMap.historyLocation.transferSuccess", (data) => {
this.resultList = [].concat(data); this.resultList = [].concat(data);
}); });
......
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).GlMap=r()}(this,(function(){"use strict";function t(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function r(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function e(t,r,e){return r&&function(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,i(n.key),n)}}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(){n=function(){return r};var t,r={},e=Object.prototype,o=e.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof g?r:g,a=Object.create(o.prototype),c=new P(n||[]);return i(a,"_invoke",{value:O(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",d="completed",m={};function g(){}function w(){}function b(){}var L={};l(L,c,(function(){return this}));var x=Object.getPrototypeOf,E=x&&x(x(T([])));E&&E!==e&&o.call(E,c)&&(L=E);var j=b.prototype=g.prototype=Object.create(L);function G(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function S(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function O(r,e,n){var o=p;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===m)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?d:y,f.arg===m)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=d,n.method="throw",n.arg=f.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,m;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,m):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,m)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function A(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return w.prototype=b,i(j,"constructor",{value:b,configurable:!0}),i(b,"constructor",{value:w,configurable:!0}),w.displayName=l(b,f,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,l(t,f,"GeneratorFunction")),t.prototype=Object.create(j),t},r.awrap=function(t){return{__await:t}},G(S.prototype),l(S.prototype,u,(function(){return this})),r.AsyncIterator=S,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new S(s(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},G(j),l(j,f,"Generator"),l(j,c,(function(){return this})),l(j,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=T,P.prototype={constructor:P,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(A),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),m},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),A(e),m}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;A(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),m}},r}function o(r){return function(r){if(Array.isArray(r))return t(r)}(r)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(r)||function(r,e){if(r){if("string"==typeof r)return t(r,e);var n={}.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(r,e):void 0}}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof r?r:r+""}function a(t){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a(t)}var c={1:"develop",2:"test",3:"production",4:"beta"},u=function(){return e((function t(){var e=this;!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t);var o,i,u={env:3,version:3},f=arguments[0];if(arguments.length>1&&(u="object"==a(arguments[0])?arguments[0]:u,f=arguments[1],null!==(o=u)&&void 0!==o&&o.env||(u.env=3),null!==(i=u)&&void 0!==i&&i.version||(u.version=3)),"undefined"!=typeof window){var l=function(){var t,o=(t=n().mark((function t(){var r,o,i,a;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,fetch("https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=map-api-js&env=".concat(c[u.env]));case 3:return r=t.sent,t.next=6,r.json();case 6:o=t.sent,i=Array.from(document.head.getElementsByTagName("script")).some((function(t){return t.src===o.apiUrl})),i?f&&"function"==typeof f&&(e.GLMap=new window.$GlMapApi(u,(function(){f&&"function"==typeof f&&f(e)}))):((a=document.createElement("script")).src=o.apiUrl,document.head.appendChild(a),a.onload=function(){e.GLMap=new window.$GlMapApi(u,(function(){f&&"function"==typeof f&&f(e)}))}),t.next=14;break;case 11:t.prev=11,t.t0=t.catch(0),console.error("Failed to fetch configuration:",t.t0);case 14:case"end":return t.stop()}}),t,null,[[0,11]])})),function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function c(t){r(a,o,i,c,u,"next",t)}function u(t){r(a,o,i,c,u,"throw",t)}c(void 0)}))});return function(){return o.apply(this,arguments)}}();l()}}),[{key:"invoke",value:function(t){var r,e=Array.prototype.slice.call(arguments,1);return(r=this.GLMap)[t].apply(r,o(e))}},{key:"map",get:function(){return this.GLMap._BMAP}},{key:"mapGL",get:function(){return this.GLMap._BMapGL}}])}();return u}));
import EventBus from '../event-bus' import EventBus from '../event-bus'
import mapService from './mapService.js' import mapService from './mapBService.js'
import MAPGEO from './mapgeo' import MAPGEO from './mapgeo'
//历史停留 //历史停留
const historyLocation = { const historyLocation = {
data: [], data: [],
points:[],
cluster:'',
markers: {}, markers: {},
infowins: {}, infowins: {},
bindEvent(){ bindEvent(){
EventBus.$on('uiMap.historyLocation.draw', (data)=>{ EventBus.$on('uiMap.historyLocation.draw', (data)=>{
console.log(data, '--------');
this.destroy(); this.destroy();
const MAP = mapService.map;
this.data = data; this.data = data;
let markers=[]
// MAPGEO.transferAddressByGroup(this, ()=>{
// EventBus.$emit('uiMap.historyLocation.transferSuccess', data);
// this.data.forEach((item)=>{
// let marker = mapService.createHistoryLocationMarker([item.elng, item.elat], MAP);
// let infoWindow = mapService.bindLocationInfoWindow(marker, MAP, item);
// this.markers[item.idx] = marker;
// this.infowins[item.idx] = infoWindow;
// });
// console.log(this.markers)
// mapService.setFitView(MAP);
// this.createClusterer();
// });
// v1.7.0历史停留为保证地址信息显示与导出一致 取后端返回的address 不需高德逆地址解析 // v1.7.0历史停留为保证地址信息显示与导出一致 取后端返回的address 不需高德逆地址解析
EventBus.$emit('uiMap.historyLocation.transferSuccess', data); EventBus.$emit('uiMap.historyLocation.transferSuccess', data);
this.data.forEach((item)=>{ this.data.forEach((item)=>{
let marker = mapService.createHistoryLocationMarker([item.elng, item.elat], MAP); let lnglatXY=mapService.getLngLat(item.elng, item.elat);
let infoWindow = mapService.bindLocationInfoWindow(marker, MAP, item); markers.push(lnglatXY)
let marker = mapService.createHistoryLocationMarker(lnglatXY, AMap);
let infoWindow = mapService.bindLocationInfoWindow(marker, AMap, item);
this.markers[item.idx] = marker; this.markers[item.idx] = marker;
this.infowins[item.idx] = infoWindow; this.infowins[item.idx] = infoWindow;
// AMap.invoke('addOverlay',this.markers[item.idx])
}); });
console.log(this.markers)
mapService.setFitView(MAP); AMap.invoke('setViewport',markers)
this.points=markers
this.createClusterer(); this.createClusterer();
}); });
...@@ -47,105 +39,51 @@ const historyLocation = { ...@@ -47,105 +39,51 @@ const historyLocation = {
if(this.markers[idx]){ if(this.markers[idx]){
const MAP = mapService.map; const MAP = mapService.map;
const lnglat = this.markers[idx].getPosition(); const lnglat = this.markers[idx].getPosition();
this.infowins[idx].open(MAP, lnglat); // this.infowins[idx].open(MAP, lnglat);
MAP.setZoomAndCenter(MAP.getZoom(), lnglat); MAP.invoke("mapOpenInfoWindow", this.infowins[idx],lnglat)
MAP.invoke('centerAndZoom',lnglat,10)
} }
}); });
}, },
createClusterer(){ createClusterer(){
let map=mapService.mapInstance;
var cluster, markers = []; var cluster, markers = [];
for(let idx in this.markers){ for(let idx in this.markers){
markers.push(this.markers[idx]); markers.push(this.markers[idx]);
} }
this.cluster = AMap.invoke('Cluster', markers, data => {
var self = this; return {
var map = mapService.map; point: [data.latLng.lng, data.latLng.lat],
properties: {
marker: data
var count = markers.length; }
var _renderClusterMarker = function (context) {
var factor = Math.pow(context.count / count, 1 / 18);
var div = document.createElement('div');
var Hue = 180 - factor * 180;
var bgColor = 'hsla(' + Hue + ',100%,50%,0.7)';
var fontColor = 'hsla(' + Hue + ',100%,20%,1)';
var borderColor = 'hsla(' + Hue + ',100%,40%,1)';
var shadowColor = 'hsla(' + Hue + ',100%,50%,1)';
div.style.backgroundColor = bgColor;
var size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20);
div.style.width = div.style.height = size + 'px';
div.style.border = 'solid 1px ' + borderColor;
div.style.borderRadius = size / 2 + 'px';
div.style.boxShadow = '0 0 1px ' + shadowColor;
div.innerHTML = context.count;
div.style.lineHeight = size + 'px';
div.style.color = fontColor;
div.style.fontSize = '14px';
div.style.textAlign = 'center';
context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));
context.marker.setContent(div)
};
addCluster(2);
function addCluster(tag) {
if (self.cluster) {
self.cluster.setMap(null);
}
if (tag == 2) {//完全自定义
self.cluster = new AMap.MarkerClusterer(map, markers, {
gridSize: 80,
maxZoom: 16,
renderClusterMarker: _renderClusterMarker
});
} else if (tag == 1) {//自定义图标
var sts = [{
url: "https://a.amap.com/jsapi_demos/static/images/blue.png",
size: new AMap.Size(32, 32),
offset: new AMap.Pixel(-16, -16)
}, {
url: "https://a.amap.com/jsapi_demos/static/images/green.png",
size: new AMap.Size(32, 32),
offset: new AMap.Pixel(-16, -16)
}, {
url: "https://a.amap.com/jsapi_demos/static/images/orange.png",
size: new AMap.Size(36, 36),
offset: new AMap.Pixel(-18, -18)
}, {
url: "https://a.amap.com/jsapi_demos/static/images/red.png",
size: new AMap.Size(48, 48),
offset: new AMap.Pixel(-24, -24)
}, {
url: "https://a.amap.com/jsapi_demos/static/images/darkRed.png",
size: new AMap.Size(48, 48),
offset: new AMap.Pixel(-24, -24)
}];
self.cluster = new AMap.MarkerClusterer(map, markers, {
styles: sts,
gridSize: 80
});
} else {//默认样式
self.cluster = new AMap.MarkerClusterer(map, markers, {gridSize: 80});
} }
} })
AMap.invoke('clusterSetData', this.cluster)
AMap.invoke('clusterAddEventListener', 'click', (e) => {
AMap.invoke('infoWindowDisableCloseOnClick', e.properties.marker.openInfoWindow)
AMap.invoke("mapOpenInfoWindow", e.properties.marker.openInfoWindow,e.properties.marker.getPosition() )
})
}, },
destroy: function(){ destroy: function(){
const MAP = mapService.map; const MAP = mapService.map;
//MAP.clearMap();
this.data = []; this.data = [];
for(let idx in this.markers){ for(let idx in this.markers){
MAP.remove(this.markers[idx]) AMap.invoke('removeOverlay',this.markers[idx])
} }
for(let idx in this.infowins){ for(let idx in this.infowins){
MAP.remove(this.infowins[idx]) AMap.invoke('mapCloseInfoWindow')
} }
this.markers = {}; this.markers = {};
this.infowins = {}; this.infowins = {};
if (this.cluster) { if (this.cluster) {
this.cluster.setMap(null); AMap.invoke('clusterDestroy')
self.cluster = null; this.cluster = null;
} }
this.clearTimeoutIds(); this.clearTimeoutIds();
}, },
......
/*
* @Author: 'wangzhihui' '1733904062@qq.com'
* @Date: 2024-11-28 16:37:15
* @LastEditors: 'wangzhihui' '1733904062@qq.com'
* @LastEditTime: 2024-12-12 14:23:37
* @FilePath: \oEshield\src\utils\mapgeo.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
const MAPGEO = {
geocoder: null,
getGeocoder: function () {
return new Promise((resolve) => {
console.log(window)
var geocoder= AMap.invoke('Geocoder');
// AMap.plugin('AMap.Geocoder', function () {//回调函数
// var geocoder = new AMap.Geocoder({
// batch: true
// });
MAPGEO.geocoder = geocoder;
resolve(geocoder);
});
// })
},
transferAddressByGroup(obj, cb) {
if (!this.geocoder) {
this.getGeocoder().then(() => {
this.transfer(obj, cb)
})
} else {
this.transfer(obj, cb)
}
},
transfer(obj, cb) {
const data = obj.data;
obj.len = data.length;
obj.times = obj.len > 20 ? Math.ceil(obj.len / 20) : 1;
obj.totalNum = 0;
obj.realNum = 0; //为了剔除脏数据,脏数据导致解析不回调
for (let i = 0; i < obj.times; i++) {
let lnglatArr = [];
let initIdx = i * 20;
let maxIdx = i === obj.times - 1 ? obj.len : (i + 1) * 20;
for (let idx = initIdx; idx < maxIdx; idx++) {
// 防止出现gps点:.00000的错误
if (Number(data[idx].elng) > 0 && Number(data[idx].elat) > 0) {
lnglatArr.push([data[idx].elng, data[idx].elat])
obj.realNum++;
}
}
(function (initIdx) {
geocoderGetAdr(lnglatArr, initIdx)
})(initIdx)
}
function fixed6(num) {
return Number(num).toFixed(6);
}
// 循环设置地址,修复数组中相同经纬度只设置第一个的bug jack 20230720
function setAddress(row, item) {
let _list = data.filter(
(k) =>
fixed6(k.elng) == fixed6(row.lng) && fixed6(k.elat) == fixed6(row.lat)
);
_list.map((k) => {
k.transferAddress = item.address;
});
}
function geocoderGetAdr(arr, initIdx) {
if (!arr || arr.length <= 0) {
return false;
}
const timeoutId = window.setTimeout(() => {
arr.forEach(item=>{
let o=AMap.invoke('Point',...item)
MAPGEO.geocoder.getLocation( o,function(res){
console.log(res,'res')
setAddress(o, res);
obj.totalNum++;
if (obj.totalNum === obj.realNum) {
console.log('geocoderGetAdr', data)
cb && cb(data)
}
})
})
// MAPGEO.geocoder.getAddress(arr, function (status, result) {
// if (status === 'complete' && result.info === 'OK') {//获取地址成功
// result.regeocodes.forEach((item, idx) => {
// let o = arr[idx]
// setAddress(o, item);
// obj.totalNum++;
// });
// if (obj.totalNum === obj.realNum) {
// cb && cb(data)
// }
// } else {
// // geocoderGetAdr(arr, initIdx)
// }
// });
});
if (!obj.timeoutIds) {
obj.timeoutIds = []
}
obj.timeoutIds.push(timeoutId)
}
}
}
export default MAPGEO
\ No newline at end of file \ No newline at end of file
...@@ -22,6 +22,7 @@ function MapService() { ...@@ -22,6 +22,7 @@ function MapService() {
var zhongliType = sessionStorage.getItem('zhongliType');//获取是否仲利账号状态,从本地内存中拿取数据 var zhongliType = sessionStorage.getItem('zhongliType');//获取是否仲利账号状态,从本地内存中拿取数据
MapService.prototype = { MapService.prototype = {
init: function(id, options) { init: function(id, options) {
console.log('init map',id, options)
var self = this; var self = this;
let params = options || {} let params = options || {}
if (self.map) { if (self.map) {
......
...@@ -68,6 +68,7 @@ const MAPGEO = { ...@@ -68,6 +68,7 @@ const MAPGEO = {
// 循环设置地址,修复数组中相同经纬度只设置第一个的bug jack 20230720 // 循环设置地址,修复数组中相同经纬度只设置第一个的bug jack 20230720
function setAddress(row, item) { function setAddress(row, item) {
console.log('setAddress', row, item)
let _list = data.filter( let _list = data.filter(
(k) => (k) =>
fixed6(k.elng) == fixed6(row.lng) && fixed6(k.elat) == fixed6(row.lat) fixed6(k.elng) == fixed6(row.lng) && fixed6(k.elat) == fixed6(row.lat)
...@@ -85,6 +86,7 @@ const MAPGEO = { ...@@ -85,6 +86,7 @@ const MAPGEO = {
MAPGEO.geocoder.getAddress(arr, function (status, result) { MAPGEO.geocoder.getAddress(arr, function (status, result) {
if (status === 'complete' && result.info === 'OK') {//获取地址成功 if (status === 'complete' && result.info === 'OK') {//获取地址成功
console.log('geocoderGetAdr', result)
result.regeocodes.forEach((item, idx) => { result.regeocodes.forEach((item, idx) => {
let o = arr[idx] let o = arr[idx]
// let _idx = data.findIndex(k => k.elng == o.lng && k.elat == o.lat); // let _idx = data.findIndex(k => k.elng == o.lng && k.elat == o.lat);
......
/*
* @Author: 'wangzhihui' '1733904062@qq.com'
* @Date: 2024-11-28 16:37:15
* @LastEditors: 'wangzhihui' '1733904062@qq.com'
* @LastEditTime: 2024-12-20 10:11:12
* @FilePath: \oEshield\src\utils\resident.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import EventBus from '../event-bus' import EventBus from '../event-bus'
import mapService from './mapService.js' import mapService from './mapBService.js'
import MAPGEO from './mapgeo' import MAPGEO from './mapgeo'
//常驻地 //常驻地
...@@ -19,56 +27,42 @@ const resident = { ...@@ -19,56 +27,42 @@ const resident = {
EventBus.$on('uiMap.resident.openInfoWindow', (idx)=>{ EventBus.$on('uiMap.resident.openInfoWindow', (idx)=>{
if(this.markers[idx]){ if(this.markers[idx]){
const MAP = mapService.map;
const lnglat = this.markers[idx].getPosition(); const lnglat = this.markers[idx].getPosition();
this.infowins[idx].open(MAP, lnglat); AMap.invoke("mapOpenInfoWindow", this.infowins[idx],lnglat)
MAP.setZoomAndCenter(MAP.getZoom(), lnglat); AMap.invoke('centerAndZoom',lnglat,13)
} }
}); });
}, },
draw(data){ draw(data){
const MAP = mapService.map; const MAP = mapService.map;
this.data = data; this.data = data;
let paths=[]
// MAPGEO.transferAddressByGroup(this, ()=>{
// EventBus.$emit('uiMap.historyLocation.transferSuccess', data);
// this.data.forEach((item)=>{
// if(parseFloat(item.elng) === 0 && parseFloat(item.elat) === 0) return;
// let marker = mapService.createConstantMarker([parseFloat(item.elng), parseFloat(item.elat)], MAP);
// let infoWindow = mapService.bindResidentInfoWindow(marker, MAP, item);
// this.markers[item.idx] = marker;
// this.infowins[item.idx] = infoWindow;
// });
// mapService.setFitView(MAP);
// });
// v1.7.0常驻地为保证导出内容与显示一致 取后端返回的address 不需高德逆地址解析 // v1.7.0常驻地为保证导出内容与显示一致 取后端返回的address 不需高德逆地址解析
EventBus.$emit('uiMap.historyLocation.transferSuccess', data); EventBus.$emit('uiMap.historyLocation.transferSuccess', data);
this.data.forEach((item)=>{ this.data.forEach((item)=>{
if(parseFloat(item.elng) === 0 && parseFloat(item.elat) === 0) return; if(parseFloat(item.elng) === 0 && parseFloat(item.elat) === 0) return;
let lnglatXY=mapService.getLngLat(parseFloat(item.elng), parseFloat(item.elat));
let marker = mapService.createConstantMarker([parseFloat(item.elng), parseFloat(item.elat)], MAP); paths.push(lnglatXY)
let marker = mapService.createConstantMarker(lnglatXY, MAP);
let infoWindow = mapService.bindResidentInfoWindow(marker, MAP, item); let infoWindow = mapService.bindResidentInfoWindow(marker, MAP, item);
this.markers[item.idx] = marker; this.markers[item.idx] = marker;
this.infowins[item.idx] = infoWindow; this.infowins[item.idx] = infoWindow;
MAP.invoke('addOverlay',this.markers[item.idx])
}); });
AMap.invoke('setViewport',paths)
mapService.setFitView(MAP); // mapService.invoke('panTo', MAP.getCenter())
}, },
intervalDraw(){ intervalDraw(){
}, },
destroy: function(){ destroy: function(){
const MAP = mapService.map;
for(let idx in this.markers){ for(let idx in this.markers){
MAP.remove(this.markers[idx]) AMap.invoke('removeOverlay',this.markers[idx])
} }
for(let idx in this.infowins){ for(let idx in this.infowins){
MAP.remove(this.infowins[idx]) AMap.invoke('mapCloseInfoWindow')
} }
this.markers = {}; this.markers = {};
this.infowins = {}; this.infowins = {};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!