Commit da8d9593 by 胡悦

切换高德地图为百度地图-工单

1 parent dae2597d
......@@ -10,7 +10,6 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1",
"axios": "^0.20.0",
"core-js": "^3.6.5",
"echarts": "^5.2.2",
......
......@@ -383,6 +383,7 @@
padding: 2px 8px;
border: 1px solid #094;
border-radius: 4px 0 0 4px;
line-height: 16px;
& + .locate-btn{
border-radius: 0 4px 4px 0;
border-left: none;
......
<template>
<div id="mapContainer" class="map-container"></div>
<div>
<div id="mapContainer" class="map-container"></div>
</div>
</template>
<script>
import { CONSTANT } from "@/amap/map";
import mapService from "@/amap/mapService";
import AMapLoader from "@amap/amap-jsapi-loader";
// import mapService from "@/amap/mapService";
import "@/assets/spritesmith-generated/sprite.css";
import "@/assets/styles/monitor.scss";
import GLMapSdk from "@/utils/glsk-mapapi-sdk";
/**
* address: gps地址
* bsAddress:基站地址
......@@ -59,87 +60,172 @@ export default {
},
},
},
data() {
return {
mapObj: "",
zoom: 10,
mapapi: "",
};
},
mounted() {
console.log(mapService);
created() {
this.initMap();
},
methods: {
// 初始化地图
initMap() {
let _this = this;
if (window.AMap) {
_this.init(window.AMap);
return false;
}
AMapLoader.reset();
AMapLoader.load({
key: CONSTANT.MAP_KEY, // 申请好的Web端开发者Key,首次调用 load 时必填
version: "1.4.2", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
plugins: CONSTANT.MAP_PLUGINS, // 需要使用的的插件列表,如比例尺'AMap.Scale'等
}).then((AMap) => {
_this.init(AMap);
// let _amap = new AMap.Map("mapContainer", {
// //设置地图容器id
// viewMode: "3D", //是否为3D地图模式
// });
// _amap.on("complete", function () {
// console.log(_this.info);
// if (_this.info && (_this.info.bsLng || _this.info.gpsLng)) {
// _this.drawMaker();
// }
// });
// _this.mapObj = _amap;
async initMap() {
new GLMapSdk(1, async (mapapi) => {
this.mapapi = mapapi;
const map = await mapapi.invoke("Map", "mapContainer");
const { lng, lat } = this.info;
mapapi.invoke("centerAndZoom", mapapi.invoke("Point", lng, lat), this.zoom);
//向地图中添加缩放控件
var ctrlNav = new window.BMap.NavigationControl({
anchor: BMAP_ANCHOR_TOP_LEFT,
type: BMAP_NAVIGATION_CONTROL_LARGE,
});
//地图缩放控件
map.addControl(ctrlNav);
// mapapi.invoke('enableScrollWheelZoom')
this.drawMaker(mapapi, map);
});
},
// 初始化方法
init(AMap) {
let _this = this;
let _amap = new AMap.Map("mapContainer", {
//设置地图容器id
viewMode: "3D", //是否为3D地图模式
});
_amap.on("complete", function () {
console.log(_this.info);
if (_this.info && (_this.info.bsLng || _this.info.gpsLng)) {
_this.drawMaker();
}
// 激活位置
drawMaker(mapapi, map) {
let data = this.info;
const lng = parseFloat(data.lng || data.bsLng);
const lat = parseFloat(data.lat || data.bsLat);
var marker = mapapi.invoke("Marker", mapapi.invoke("Point", lng, lat), {
icon: mapapi.invoke(
"Icon",
require("@/assets/images/icon_car.png"),
mapapi.invoke("Size", 60, 60),
{
anchor: mapapi.invoke("Size", 10, 15),
infoWindowAnchor: mapapi.invoke("Size", 10, 0),
}
),
});
_this.mapObj = _amap;
this.bindActiveLocationInfoWindow(marker, map, data);
mapapi.invoke("addOverlay", marker);
},
// 创建位置点弹框
createActiveInfo(info) {
let msg = "报警";
// 激活
if (info.type == 1) {
msg = "激活";
}
// 激活位置
drawMaker() {
let data = this.info;
const MAP = this.mapObj;
const marker = mapService.createCarMarker(
[
parseFloat(data.lng || data.bsLng),
parseFloat(data.lat || data.bsLat),
],
MAP
);
const infoWindow = mapService.bindActiveLocationInfoWindow(
marker,
MAP,
data,
true
);
// 定位
if (info.type == 2) {
msg = "定位";
}
let _html = `<h3 class="map-infowindow-title">${info.name}/${info.standNo}</h3>
<div class="map-infowindow-ct">
<p><i class="icon icon-info_device"></i> 设备号: <span class="des">${
info.sn
} (${info.source == 1 ? "有线" : "无线"})</span></p>`;
// 设置图标
mapService.setDefaultIcon(marker, data.vehicleIcon);
// 是否包含断电、光感报警
if (info.alarmTypeSet && info.alarmTypeSet.length > 0) {
let tg = "";
let cHmtl = "";
let typeList = {
1: "断电",
99: "光感",
};
info.alarmTypeSet.forEach((alarmType) => {
tg += `<a class="btn_danger">${typeList[alarmType]}</a>`;
});
cHmtl =
'<p><i class="icon icon-info_device_alarm"></i><span>报警状态:</span>' +
tg +
"</p>";
_html += cHmtl;
}
_html += `<p><i class="icon icon-info_time"></i>${msg}时间: <span class="des"data-time>${
info.time
}</span></p>
<p style="display:${
info.bsLng ? "flex" : "none"
}"><i class="icon icon-info_type"></i>定位类型: <a class="locate-btn active" id="locateTypeGps">GPS</a><a class="locate-btn" id="locateTypeBase">基站</a></p>
<p class="long_p"><i class="icon icon-info_location"></i><span>${msg}地址:</span><span class="des" data-transferAddress>${
info.address
}</span></p>
</div>`;
return _html;
},
// 位置点弹框
bindActiveLocationInfoWindow(marker, map, info) {
var self = this;
var infoDiv = document.createElement("div");
infoDiv.innerHTML = self.createActiveInfo(info);
//if (autoOpenLastInfoWindow) {
// /EventBus.$emit("uiMap.monitor.openInfoWindow");
mapService.openActiveInfoWindow(MAP, marker, infoWindow);
//}
// gps位置信息
function fillGPS() {
infoDiv.querySelector("[data-time]").textContent = info.time;
infoDiv.querySelector("[data-transferAddress]").textContent = info.address;
infoDiv.querySelector("#locateTypeGps").classList.add("active");
infoDiv.querySelector("#locateTypeBase").classList.remove("active");
marker.setPosition(self.mapapi.invoke("Point", info.lng, info.lat));
map.openInfoWindow(marker.infoWindow, marker.getPosition());
}
// 基站位置信息
function fillBase() {
infoDiv.querySelector("[data-time]").textContent = info.bsTime;
infoDiv.querySelector("[data-transferAddress]").textContent = info.bsAddress;
infoDiv.querySelector("#locateTypeGps").classList.remove("active");
infoDiv.querySelector("#locateTypeBase").classList.add("active");
console.log(self.mapapi.invoke("Point", info.bsLng, info.bsLat), "基站点位置", map);
marker.setPosition(self.mapapi.invoke("Point", info.bsLng, info.bsLat));
map.openInfoWindow(marker.infoWindow, marker.getPosition());
}
infoDiv.querySelector("#locateTypeGps").onclick = function (e) {
fillGPS();
};
infoDiv.querySelector("#locateTypeBase").onclick = function (e) {
fillBase();
};
if (info.lng) {
fillGPS();
}
if (!info.lng && info.bsLng) {
fillBase();
}
return this.createActiveInfoWindow(marker, map, infoDiv);
},
// 创建位置点弹框
createActiveInfoWindow(marker, map, div, isInfoOpen, isInfoAutoMove) {
let opts = {
width: 380, // 信息窗口宽度
height: 170, // 信息窗口高度
};
let infoWindow = this.mapapi.invoke("InfoWindow", div, opts);
marker.infoWindow = infoWindow;
map.openInfoWindow(infoWindow, marker.getPosition());
//给Marker绑定单击事件
marker.addEventListener("click", markerClick);
function markerClick(e) {
map.openInfoWindow(infoWindow, marker.getPosition());
}
return infoWindow;
},
//EventBus.$emit("uiMap.monitor.drawDone");
// 打开激活位置点弹框
openActiveInfoWindow(map, makers, infoWindow) {
const MAP = map;
const lnglat = makers.getPosition();
infoWindow.open(MAP, lnglat);
MAP.setZoomAndCenter(MAP.getZoom(), lnglat);
},
},
};
......@@ -155,4 +241,4 @@ p {
height: 400px;
font-size: 13px;
}
</style>
\ No newline at end of file
</style>
!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 S(n||[]);return i(a,"_invoke",{value:k(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 x={};l(x,c,(function(){return this}));var L=Object.getPrototypeOf,E=L&&L(L(T([])));E&&E!==e&&o.call(E,c)&&(x=E);var j=b.prototype=g.prototype=Object.create(x);function O(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function _(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 k(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=A(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 A(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,A(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 P(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 G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,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}},O(_.prototype),l(_.prototype,u,(function(){return this})),r.AsyncIterator=_,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new _(s(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(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,S.prototype={constructor:S,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(G),!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),G(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;G(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+""}var a={1:"develop",2:"test",3:"production",4:"beta"},c=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=1,i=arguments[0];if(arguments.length>1&&(o=arguments[0],i=arguments[1]),"undefined"!=typeof window){var c=function(){var t,c=(t=n().mark((function t(){var r,c,u,f;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(a[o]));case 3:return r=t.sent,t.next=6,r.json();case 6:c=t.sent,u=Array.from(document.head.getElementsByTagName("script")).some((function(t){return t.src===c.apiUrl})),u?i&&"function"==typeof i&&i(e):((f=document.createElement("script")).src=c.apiUrl,document.head.appendChild(f),f.onload=function(){e.GLMap=new window.$GlMapApi((function(){i&&"function"==typeof i&&i(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 c.apply(this,arguments)}}();c()}}),[{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}}])}();return c}));
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!