Commit 018410ed by chenwq

高德地图切换成百度地图

1 parent e322c4d6
...@@ -27,34 +27,11 @@ ...@@ -27,34 +27,11 @@
"@babel/core": "^7.12.16", "@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16", "@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-service": "~5.0.0", "@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.0.3",
"prettier": "^2.4.1",
"sass": "1.26.8", "sass": "1.26.8",
"sass-loader": "^10.0.3", "sass-loader": "^10.0.3",
"webpack-spritesmith": "^0.5.2" "webpack-spritesmith": "^0.5.2"
}, },
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {
"indent": "off"
}
},
"browserslist": [ "browserslist": [
"> 1%", "> 1%",
"last 2 versions", "last 2 versions",
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
import { onMounted, ref } from "vue"; import { onMounted, ref } from "vue";
import { Toast } from "vant"; import { Toast } from "vant";
import "vant/es/toast/style"; import "vant/es/toast/style";
import GLMap from "@/utils/glsk-mapapi-sdk.js";
export default { export default {
name: "mapContent", name: "mapContent",
props: {}, props: {},
...@@ -36,58 +37,116 @@ export default { ...@@ -36,58 +37,116 @@ export default {
const roadActive = ref(null); const roadActive = ref(null);
const isGetLocation = ref(false); const isGetLocation = ref(false);
onMounted(() => {}); onMounted(() => {});
const initMap = (id) => { const initMap = (id, version = 3) => {
let check = () => { return new Promise((resolve) => {
checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId); let check = () => {
let AMap = window.AMap; checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId);
if (AMap && typeof AMap.Map == "function") { if(GLMap) {
window.AMap = AMap; new GLMap({ version }, mapapi => {
init(id); // new GLMap(mapapi => {
} else { window.mapapi = mapapi;
checkLoadedTimeoutId = check(); init(id);
} resolve()
}; })
checkLoadedTimeoutId = check(); } else {
checkLoadedTimeoutId = check();
}
};
checkLoadedTimeoutId = check();
});
}; };
const init = (id) => { const init = (id) => {
map = new window.AMap.Map(id); map = window.mapapi.invoke('Map', id);
isUploaded.value = true; var point = mapapi.invoke('Point', 116.2317, 39.5427)
context.emit("isUploaded", true); window.mapapi.invoke('LocalCity', (data) => {
context.emit("getData", map); if(data) {
return map; point = data.center
}
mapapi.invoke('centerAndZoom', point, 10);
isUploaded.value = true;
context.emit("isUploaded", true);
context.emit("getData", map);
return map;
})
}; };
let currMarker = null; let currMarker = null;
// 获取定位 // 获取定位
const getLocation = () => { const getLocation = () => {
isGetLocation.value = true; isGetLocation.value = true;
map.plugin("AMap.Geolocation", function () { window.mapapi.invoke('Geolocation', (data) => {
var geolocation = new window.AMap.Geolocation({ if(data) {
enableHighAccuracy: true, if (currMarker) {
timeout: 10000, // currMarker.setMap(null);
buttonOffset: new window.AMap.Pixel(10, 20), window.mapapi.invoke('removeOverlay', currMarker)
zoomToAccuracy: true,
buttonPosition: "RB",
});
geolocation.getCurrentPosition();
window.AMap.event.addListener(geolocation, "complete", (data) => {
if (currMarker) {
currMarker.setMap(null);
} }
isGetLocation.value = false; isGetLocation.value = false;
currMarker = new window.AMap.Marker({ currMarker = window.mapapi.invoke('Marker', data.point, {
position: data.position, icon: window.mapapi.invoke('Icon', require("@/assets/images/curr-marker.gif"), window.mapapi.invoke('Size', 24, 24)),
content: '<span class="curr-marker"></span>', // offset: window.mapapi.invoke('Pixel', -12, -12),
map: map, })
offset: new window.AMap.Pixel(-12, -12), window.mapapi.invoke('addOverlay', currMarker)
}); window.mapapi.invoke('panTo', data.point)
map.setFitView(); // currMarker = new window.AMap.Marker({
}); // position: data.position,
window.AMap.event.addListener(geolocation, "error", () => { // content: '<span class="curr-marker"></span>',
// map: map,
// offset: new window.AMap.Pixel(-12, -12),
// });
// map.setFitView();
} else {
Toast("获取定位失败"); Toast("获取定位失败");
isGetLocation.value = false; isGetLocation.value = false;
}); }
}); }, {
enableHighAccuracy: true,
timeout: 10000,
})
// map.plugin("AMap.Geolocation", function () {
// var geolocation = new window.AMap.Geolocation({
// enableHighAccuracy: true,
// timeout: 10000,
// buttonOffset: new window.AMap.Pixel(10, 20),
// zoomToAccuracy: true,
// buttonPosition: "RB",
// });
// geolocation.getCurrentPosition();
// window.AMap.event.addListener(geolocation, "complete", (data) => {
// if (currMarker) {
// currMarker.setMap(null);
// }
// isGetLocation.value = false;
// currMarker = new window.AMap.Marker({
// position: data.position,
// content: '<span class="curr-marker"></span>',
// map: map,
// offset: new window.AMap.Pixel(-12, -12),
// });
// map.setFitView();
// });
// window.AMap.event.addListener(geolocation, "error", () => {
// Toast("获取定位失败");
// isGetLocation.value = false;
// });
// });
};
const getLngLat = (lng, lat) => {
return window.mapapi.invoke('Point', lng, lat)
};
const mapMarker = ({point, Animation = null, isAdd = true, icon = require("@/assets/images/curr-marker.gif"), sizeW = 52, sizeH = 52, imgW = 52, imgH = 52 }) => {
var currMarker = window.mapapi.invoke('Marker', point, {
icon: window.mapapi.invoke('Icon', icon, window.mapapi.invoke('Size', sizeW, sizeH), {
imageSize: window.mapapi.invoke('Size', imgW, imgH)
}),
})
// console.log(Animation, 'Animation---')
// Animation && window.mapapi.invoke('markerSetAnimation', Animation)
if(isAdd) {
window.mapapi.invoke('addOverlay', currMarker)
window.mapapi.invoke('panTo', point)
}
return currMarker
}; };
// 刷新 // 刷新
const refresh = () => { const refresh = () => {
...@@ -100,6 +159,8 @@ export default { ...@@ -100,6 +159,8 @@ export default {
getLocation, getLocation,
satelActive, satelActive,
roadActive, roadActive,
getLngLat,
mapMarker,
refresh, refresh,
isUploaded, isUploaded,
isGetLocation, isGetLocation,
......
const MAPGEO = { const MAPGEO = {
geocoder: null, geocoder: null,
getGeocoder: function () { getGeocoder: function () {
let AMap = window.AMap; // let AMap = window.AMap;
return new Promise((resolve) => { return new Promise((resolve) => {
AMap.service("AMap.Geocoder", function () { MAPGEO.geocoder = window.mapapi.invoke('Geocoder')
//回调函数 resolve(MAPGEO.geocoder)
var geocoder = new AMap.Geocoder({ // AMap.service("AMap.Geocoder", function () {
batch: true, // //回调函数
}); // var geocoder = new AMap.Geocoder({
MAPGEO.geocoder = geocoder; // batch: true,
resolve(geocoder); // });
}); // MAPGEO.geocoder = geocoder;
// resolve(geocoder);
// });
}); });
}, },
transferAddressByGroup(obj, cb) { transferAddressByGroup(obj, cb) {
...@@ -52,22 +54,34 @@ const MAPGEO = { ...@@ -52,22 +54,34 @@ const MAPGEO = {
function geocoderGetAdr(arr, initIdx) { function geocoderGetAdr(arr, initIdx) {
const timeoutId = window.setTimeout(() => { const timeoutId = window.setTimeout(() => {
MAPGEO.geocoder.getAddress(arr, function (status, result) { arr.forEach((item, idx) => {
if (status === "complete" && result.info === "OK") { window.mapapi.invoke('getLocation', window.mapapi.invoke('Point', item[0], item[1]), res => {
//获取地址成功 data[initIdx + idx].transferAddress = res.address;
result.regeocodes.forEach((item, idx) => { obj.totalNum++;
data[initIdx + idx].transferAddress = item.formattedAddress;
obj.totalNum++;
});
if (obj.totalNum === obj.realNum) { if (obj.totalNum === obj.realNum) {
cb && cb(data); cb && cb(data);
//ifPlay && obj.init(data) //ifPlay && obj.init(data)
//EventBus.$emit('uiMap.replay.transferAdrDone'); //EventBus.$emit('uiMap.replay.transferAdrDone');
} }
} else { })
geocoderGetAdr(arr, initIdx);
}
}); });
// window.mapapi.invoke('getLocation', mapapi.invoke('Point', 116.404, 39.915))
// MAPGEO.geocoder.getAddress(arr, function (status, result) {
// if (status === "complete" && result.info === "OK") {
// //获取地址成功
// result.regeocodes.forEach((item, idx) => {
// data[initIdx + idx].transferAddress = item.formattedAddress;
// obj.totalNum++;
// });
// if (obj.totalNum === obj.realNum) {
// cb && cb(data);
// //ifPlay && obj.init(data)
// //EventBus.$emit('uiMap.replay.transferAdrDone');
// }
// } else {
// geocoderGetAdr(arr, initIdx);
// }
// });
}); });
obj.timeoutIds.push(timeoutId); obj.timeoutIds.push(timeoutId);
......
...@@ -110,7 +110,7 @@ export default defineComponent({ ...@@ -110,7 +110,7 @@ export default defineComponent({
plugins: CONSTANT.MAP_PLUGINS, plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => { }).then((AMap) => {
window.AMap = AMap; window.AMap = AMap;
mapContentRefs.value.initMap("fenceContainer"); mapContentRefs.value.initMap("fenceContainer", 1);
geocoderValue.value = new AMap.Geocoder({ geocoderValue.value = new AMap.Geocoder({
radius: 1000, radius: 1000,
extensions: "all", extensions: "all",
...@@ -128,7 +128,8 @@ export default defineComponent({ ...@@ -128,7 +128,8 @@ export default defineComponent({
if (hasProviceCityFence.value && adcodeItemName.value) { if (hasProviceCityFence.value && adcodeItemName.value) {
coverArea(adcodeItemName.value, map); coverArea(adcodeItemName.value, map);
} }
map.setFitView(); // map.setFitView();
window.mapapi.invoke("setViewport", { center: currLnglat.value });
}; };
// 切换围栏类型 // 切换围栏类型
const changeFenceType = (index) => { const changeFenceType = (index) => {
...@@ -145,10 +146,14 @@ export default defineComponent({ ...@@ -145,10 +146,14 @@ export default defineComponent({
if (res.code === 200) { if (res.code === 200) {
if (res.data.length > 0) { if (res.data.length > 0) {
res.data.forEach((val) => { res.data.forEach((val) => {
currLnglat.value = new window.AMap.LngLat( currLnglat.value = mapContentRefs.value.getLngLat(
val["gpsLocation"].elng, val["gpsLocation"].elng,
val["gpsLocation"].elat val["gpsLocation"].elat
); );
// currLnglat.value = new window.AMap.LngLat(
// val["gpsLocation"].elng,
// val["gpsLocation"].elat
// );
drawMarker(currLnglat.value); drawMarker(currLnglat.value);
}); });
} else { } else {
...@@ -180,7 +185,8 @@ export default defineComponent({ ...@@ -180,7 +185,8 @@ export default defineComponent({
currentMap = currentMap currentMap = currentMap
? currentMap ? currentMap
: mapContentRefs.value.init("fenceContainer"); : mapContentRefs.value.init("fenceContainer");
currentMap.setFitView(); // currentMap.setFitView();
window.mapapi.invoke("setViewport", { center: currLnglat.value, zoom: 12 });
showSettingDialog.value = false; showSettingDialog.value = false;
hasRadiusFence.value = true; hasRadiusFence.value = true;
} }
...@@ -203,7 +209,8 @@ export default defineComponent({ ...@@ -203,7 +209,8 @@ export default defineComponent({
); );
adcodeItemName.value = obj.adName; adcodeItemName.value = obj.adName;
coverArea(obj.adName, currentMap); coverArea(obj.adName, currentMap);
currentMap.setFitView(); // currentMap.setFitView();
window.mapapi.invoke("setViewport", { center: currLnglat.value });
hasProviceCityFence.value = true; hasProviceCityFence.value = true;
} }
}); });
...@@ -211,39 +218,56 @@ export default defineComponent({ ...@@ -211,39 +218,56 @@ export default defineComponent({
} }
}; };
const coverArea = (areaName, currentMap) => { const coverArea = (areaName, currentMap) => {
areaPolygons && currentMap.remove(areaPolygons); // areaPolygons && currentMap.remove(areaPolygons);
console.log(areaPolygons, "areaPolygons---");
// areaPolygons.length && window.mapapi.invoke("removeDistrictLayer", areaPolygons);
console.log(areaName, "areaName---");
areaPolygons = [];
//加载行政区划插件 //加载行政区划插件
window.AMap.service("AMap.DistrictSearch", function () { var dist = window.mapapi.invoke("DistrictLayer", {
var opts = { name: `(${areaName})`,
subdistrict: 1, //返回下一级行政区 fillOpacity: 0.7,
extensions: "all", //返回行政区边界坐标组等具体信息 fillColor: "#CCF3FF",
level: "city", //查询行政级别为 市 strokeColor: "#CC66CC",
}; viewport: true,
//实例化DistrictSearch
district = new window.AMap.DistrictSearch(opts);
district.setLevel("district");
//行政区查询
district.search(areaName, function (status, result) {
var bounds = result.districtList[0].boundaries;
areaPolygons = [];
if (bounds) {
for (var i = 0, l = bounds.length; i < l; i++) {
//生成行政区划polygon
var polygon = new window.AMap.Polygon({
map: currentMap,
strokeWeight: 1,
path: bounds[i],
fillOpacity: 0.7,
fillColor: "#CCF3FF",
strokeColor: "#CC66CC",
});
areaPolygons.push(polygon);
}
currentMap.setFitView(); //地图自适应
showSettingDialog.value = false;
}
});
}); });
areaPolygons.push(dist);
window.mapapi.invoke("addDistrictLayer", dist);
showSettingDialog.value = false;
// window.AMap.service("AMap.DistrictSearch", function () {
// var opts = {
// subdistrict: 1, //返回下一级行政区
// extensions: "all", //返回行政区边界坐标组等具体信息
// level: "city", //查询行政级别为 市
// };
// //实例化DistrictSearch
// district = new window.AMap.DistrictSearch(opts);
// district.setLevel("district");
// //行政区查询
// district.search(areaName, function (status, result) {
// var bounds = result.districtList[0].boundaries;
// areaPolygons = [];
// if (bounds) {
// for (var i = 0, l = bounds.length; i < l; i++) {
// //生成行政区划polygon
// var polygon = new window.AMap.Polygon({
// map: currentMap,
// strokeWeight: 1,
// path: bounds[i],
// fillOpacity: 0.7,
// fillColor: "#CCF3FF",
// strokeColor: "#CC66CC",
// });
// areaPolygons.push(polygon);
// }
// currentMap.setFitView(); //地图自适应
// // window.mapapi.invoke("setViewport", { center: currLnglat.value });
// showSettingDialog.value = false;
// }
// });
// });
}; };
// 获取省市code // 获取省市code
const getAdcodeByLatlng = (currLnglat, cb) => { const getAdcodeByLatlng = (currLnglat, cb) => {
...@@ -277,48 +301,77 @@ export default defineComponent({ ...@@ -277,48 +301,77 @@ export default defineComponent({
}; };
// 添加标记 // 添加标记
const drawMarker = (currLnglat) => { const drawMarker = (currLnglat) => {
new window.AMap.Marker({ mapContentRefs.value.mapMarker({
position: currLnglat, point: currLnglat,
content: icon: require("@/assets/images/car.png"),
'<img src=" ' + sizeW: 17,
require("@/assets/images/car.png") + sizeH: 26,
'" style="transform: scale(0.5);" />', imgW: 17,
map: currentMap, imgH: 26,
offset: new window.AMap.Pixel(-17, -26),
}); });
currentMap.setFitView(); // new window.AMap.Marker({
// position: currLnglat,
// content:
// '<img src=" ' +
// require("@/assets/images/car.png") +
// '" style="transform: scale(0.5);" />',
// map: currentMap,
// offset: new window.AMap.Pixel(-17, -26),
// });
// currentMap.setFitView();
window.mapapi.invoke("setViewport", { center: currLnglat, zoom: 14 });
}; };
// 地图添加圆 // 地图添加圆
const createCircle = (lnglat, radius) => { const createCircle = (lnglat, radius) => {
currentMap = currentMap currentMap = currentMap
? currentMap ? currentMap
: mapContentRefs.value.init("fenceContainer"); : mapContentRefs.value.init("fenceContainer");
return new window.AMap.Circle({ var circle = window.mapapi.invoke("Circle", lnglat, radius, {
map: currentMap,
center: lnglat,
radius: radius,
strokeColor: "#0077FF", strokeColor: "#0077FF",
fillColor: "#0077FF", fillColor: "#0077FF",
strokeWeight: 1, strokeWeight: 1,
strokeOpacity: 0.5, strokeOpacity: 0.5,
fillOpacity: 0.16, fillOpacity: 0.16,
}); });
// console.log(areaPolygons, "areaPolygons---");
// areaPolygons.length && window.mapapi.invoke("removeDistrictLayer", areaPolygons[0]);
window.mapapi.invoke("addOverlay", circle);
// return new window.AMap.Circle({
// map: currentMap,
// center: lnglat,
// radius: radius,
// strokeColor: "#0077FF",
// fillColor: "#0077FF",
// strokeWeight: 1,
// strokeOpacity: 0.5,
// fillOpacity: 0.16,
// });
return circle;
}; };
// 围栏中心点 // 围栏中心点
const createPoint = (lnglat) => { const createPoint = (lnglat) => {
currentMap = currentMap currentMap = currentMap
? currentMap ? currentMap
: mapContentRefs.value.init("fenceContainer"); : mapContentRefs.value.init("fenceContainer");
return new window.AMap.Circle({ var circle = window.mapapi.invoke("Circle", lnglat, 3, {
map: currentMap,
center: lnglat,
radius: 3,
strokeColor: "#094", strokeColor: "#094",
fillColor: "#094", fillColor: "#094",
strokeWeight: 3, strokeWeight: 3,
strokeOpacity: 1, strokeOpacity: 1,
fillOpacity: 1, fillOpacity: 1,
}); });
window.mapapi.invoke("addOverlay", circle);
// return new window.AMap.Circle({
// map: currentMap,
// center: lnglat,
// radius: 3,
// strokeColor: "#094",
// fillColor: "#094",
// strokeWeight: 3,
// strokeOpacity: 1,
// fillOpacity: 1,
// });
return circle;
}; };
return { return {
getData, getData,
......
...@@ -156,7 +156,7 @@ ...@@ -156,7 +156,7 @@
import { ref, defineComponent, onMounted, watch, computed } from "vue"; import { ref, defineComponent, onMounted, watch, computed } from "vue";
import { useStore } from "vuex"; import { useStore } from "vuex";
import mapContent from "@/components/mapContent.vue"; import mapContent from "@/components/mapContent.vue";
import AMapLoader from "@amap/amap-jsapi-loader"; // import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "../constant"; import { CONSTANT } from "../constant";
import MAPGEO from "@/utils/mapgeo"; import MAPGEO from "@/utils/mapgeo";
import wx from "wx"; import wx from "wx";
...@@ -199,7 +199,8 @@ export default defineComponent({ ...@@ -199,7 +199,8 @@ export default defineComponent({
let map = undefined; let map = undefined;
const refreshCb = () => { const refreshCb = () => {
if (map && carItem.value) { if (map && carItem.value) {
map && map.clearMap(); // map && map.clearMap();
window.mapapi.invoke("clearOverlays");
if (Object.keys(carItem.value).length > 0) { if (Object.keys(carItem.value).length > 0) {
getCarInfo(carItem.value); getCarInfo(carItem.value);
} }
...@@ -324,14 +325,18 @@ export default defineComponent({ ...@@ -324,14 +325,18 @@ export default defineComponent({
// } // }
// }); // });
onMounted(() => { onMounted(() => {
AMapLoader.load({ mapContentRefs.value.initMap("container");
key: CONSTANT.MAP_KEY, // mapContentRefs.value.initMap("container").then(res => {
version: "1.4.8", // mapContentRefs.value.getLocation();
plugins: CONSTANT.MAP_PLUGINS, // })
}).then((AMap) => { // AMapLoader.load({
window.AMap = AMap; // key: CONSTANT.MAP_KEY,
mapContentRefs.value.initMap("container"); // version: "1.4.8",
}); // plugins: CONSTANT.MAP_PLUGINS,
// }).then((AMap) => {
// window.AMap = AMap;
// mapContentRefs.value.initMap("container");
// });
initViewport(window.innerHeight); initViewport(window.innerHeight);
}); });
const initViewport = (height) => { const initViewport = (height) => {
...@@ -359,11 +364,12 @@ export default defineComponent({ ...@@ -359,11 +364,12 @@ export default defineComponent({
}); });
localStorage.setItem("carInfo", JSON.stringify(it)); localStorage.setItem("carInfo", JSON.stringify(it));
map = map ? map : mapContentRefs.value.init("container"); map = map ? map : mapContentRefs.value.init("container");
map.clearMap(); // map.clearMap();
window.mapapi.invoke("clearOverlays");
GET_CAR_LOCATION_INFO({ sns: it.sns }).then((res) => { GET_CAR_LOCATION_INFO({ sns: it.sns }).then((res) => {
if (res.code === 200) { if (res.code === 200) {
if (res.data.length > 0) { if (res.data.length > 0) {
const markers = []; const points = [];
let locates = []; let locates = [];
res.data.forEach((item) => { res.data.forEach((item) => {
item.locationType = "gpsLocation"; item.locationType = "gpsLocation";
...@@ -401,7 +407,7 @@ export default defineComponent({ ...@@ -401,7 +407,7 @@ export default defineComponent({
locates.push(item.wifiLocation); locates.push(item.wifiLocation);
item.wifiLocation.transferAddress = ""; item.wifiLocation.transferAddress = "";
} }
markers.push(drawMarker(item, map, locates)); points.push(drawMarker(item, map, locates));
}); });
if (locates.length <= 0) { if (locates.length <= 0) {
return Toast("暂无有效定位点信息"); return Toast("暂无有效定位点信息");
...@@ -409,8 +415,9 @@ export default defineComponent({ ...@@ -409,8 +415,9 @@ export default defineComponent({
MAPGEO.transferAddressByGroup( MAPGEO.transferAddressByGroup(
{ data: locates, timeoutIds: [] }, { data: locates, timeoutIds: [] },
() => { () => {
console.log(markers); if (points.every((item) => item !== undefined)) {
map.setFitView(markers); window.mapapi.invoke("setViewport", points);
}
} }
); );
} else { } else {
...@@ -420,6 +427,7 @@ export default defineComponent({ ...@@ -420,6 +427,7 @@ export default defineComponent({
}); });
}; };
const drawMarker = (item, map, locates) => { const drawMarker = (item, map, locates) => {
console.log(window.mapapi);
//item.locationType = "gpsLocation"; //item.locationType = "gpsLocation";
if (!item[item.locationType]) return; if (!item[item.locationType]) return;
//修改数据格式方便获取 //修改数据格式方便获取
...@@ -431,19 +439,43 @@ export default defineComponent({ ...@@ -431,19 +439,43 @@ export default defineComponent({
item[item.locationType].transferAddress = val.transferAddress; item[item.locationType].transferAddress = val.transferAddress;
} }
}); });
var lnglat = new window.AMap.LngLat( var lnglat = mapContentRefs.value.getLngLat(
item[item.locationType].elng, item[item.locationType].elng,
item[item.locationType].elat item[item.locationType].elat
); );
var marker = new window.AMap.Marker({ var marker = mapContentRefs.value.mapMarker({
position: lnglat, point: lnglat,
content: icon:
item.source == "0" item.source == "0"
? '<span class="marker-class"><span class="icon icon-off-car sn-marker"></span><span class="marker-bottom off-line"><span class="outside off-line"></span><span class="inside off-line"></span></span></span>' ? require("@/assets/icon/off-car.png")
: '<span class="marker-class"><span class="icon icon-on-car sn-marker"></span><span class="marker-bottom on-line"><span class="outside on-line"></span><span class="inside on-line"></span></span></span>', : require("@/assets/icon/on-car.png"),
map: map, Animation: "BMAP_ANIMATION_BOUNCE",
offset: new window.AMap.Pixel(-26, -18),
}); });
// mapContentRefs.value.mapMarker({point: lnglat, icon: item.source == "0" ? require("@/assets/images/curr-marker.gif") : require("@/assets/images/curr-marker.gif"), sizeW: 24, sizeH: 24, imgW: 24, imgH: 24})
// var lnglat = new window.AMap.LngLat(
// item[item.locationType].elng,
// item[item.locationType].elat
// );
// console.log(lnglat)
// var marker = window.mapapi.invoke('Marker', lnglat, {
// icon: window.mapapi.invoke('Icon', require("@/assets/images/curr-marker.gif"), window.mapapi.invoke('Size', 24, 24)),
// // icon: window.mapapi.invoke('Icon', require("@/assets/spritesmith-generated/sprite.png"), window.mapapi.invoke('Size', 24, 24))
// // position: lnglat,
// // content: item.source == "0"
// // ? '<span class="marker-class"><span class="icon icon-off-car sn-marker"></span><span class="marker-bottom off-line"><span class="outside off-line"></span><span class="inside off-line"></span></span></span>'
// // : '<span class="marker-class"><span class="icon icon-on-car sn-marker"></span><span class="/>'
// })
// console.log(marker)
// window.mapapi.invoke('addOverLay', marker)
// var marker = new window.AMap.Marker({
// position: lnglat,
// content:
// item.source == "0"
// ? '<span class="marker-class"><span class="icon icon-off-car sn-marker"></span><span class="marker-bottom off-line"><span class="outside off-line"></span><span class="inside off-line"></span></span></span>'
// : '<span class="marker-class"><span class="icon icon-on-car sn-marker"></span><span class="marker-bottom on-line"><span class="outside on-line"></span><span class="inside on-line"></span></span></span>',
// map: map,
// offset: new window.AMap.Pixel(-26, -18),
// });
var carInfoWindowTpl = `<div class="car-info-window"><div class="car-info-content">`; var carInfoWindowTpl = `<div class="car-info-window"><div class="car-info-content">`;
carInfoWindowTpl += `<div class="main-info">`; carInfoWindowTpl += `<div class="main-info">`;
carInfoWindowTpl += `<h4 class="info-title"><div>${ carInfoWindowTpl += `<h4 class="info-title"><div>${
...@@ -503,18 +535,35 @@ export default defineComponent({ ...@@ -503,18 +535,35 @@ export default defineComponent({
</div>`; </div>`;
let infoDiv = document.createElement("div"); let infoDiv = document.createElement("div");
infoDiv.innerHTML = carInfoWindowTpl; infoDiv.innerHTML = carInfoWindowTpl;
let infoWindow = new window.AMap.InfoWindow({
isCustom: true, var infoWindow = "";
autoMove: false, window.mapapi.invoke("markerAddEventListener", marker, "click", (e) => {
position: lnglat, infoWindow = window.mapapi.invoke("InfoWindow", infoDiv);
content: infoDiv, window.mapapi.invoke(
offset: new window.AMap.Pixel(24, -20), "mapOpenInfoWindow",
infoWindow,
window.mapapi.invoke("markerGetPosition", marker),
{
// offset: window.mapapi.invoke('Size', 22, 100)
}
);
}); });
// mapapi.invoke('mapOpenInfoWindow', infoWindow, mapapi.invoke('markerGetPosition', marker))
// let infoWindow = new window.AMap.InfoWindow({
// isCustom: true,
// autoMove: false,
// position: lnglat,
// content: infoDiv,
// offset: new window.AMap.Pixel(24, -20),
// });
const move = (newLnglat) => { const move = (newLnglat) => {
marker.setPosition(newLnglat); window.mapapi.invoke("markerSetPosition", marker, newLnglat);
infoWindow.setPosition(newLnglat); window.mapapi.invoke("openInfoWindow", infoWindow, newLnglat);
map.setCenter(newLnglat); // marker.setPosition(newLnglat);
map.panBy(0, 70); // infoWindow.setPosition(newLnglat);
// map.setCenter(newLnglat);
// map.panBy(0, 70);
window.mapapi.invoke("panTo", newLnglat);
}; };
//信息窗体内容更新 //信息窗体内容更新
let GPSBtn = infoDiv.querySelector("[data-GPS]"); let GPSBtn = infoDiv.querySelector("[data-GPS]");
...@@ -567,7 +616,10 @@ export default defineComponent({ ...@@ -567,7 +616,10 @@ export default defineComponent({
check(() => { check(() => {
let gpsObj = item["gpsLocation"]; let gpsObj = item["gpsLocation"];
if (gpsObj) { if (gpsObj) {
var newLnglat = new window.AMap.LngLat(gpsObj.elng, gpsObj.elat); var newLnglat = mapContentRefs.value.getLngLat(
gpsObj.elng,
gpsObj.elat
);
GPSIcon && GPSIcon.classList.add("active"); GPSIcon && GPSIcon.classList.add("active");
GPRSIcon && GPRSIcon.classList.remove("active"); GPRSIcon && GPRSIcon.classList.remove("active");
WIFIIcon && WIFIIcon.classList.remove("active"); WIFIIcon && WIFIIcon.classList.remove("active");
...@@ -590,7 +642,7 @@ export default defineComponent({ ...@@ -590,7 +642,7 @@ export default defineComponent({
GPSIcon && GPSIcon.classList.remove("active"); GPSIcon && GPSIcon.classList.remove("active");
WIFIIcon && WIFIIcon.classList.remove("active"); WIFIIcon && WIFIIcon.classList.remove("active");
item.locationType = "bsLocation"; item.locationType = "bsLocation";
var newLnglat = new window.AMap.LngLat( var newLnglat = mapContentRefs.value.getLngLat(
gprsObj.elng, gprsObj.elng,
gprsObj.elat gprsObj.elat
); );
...@@ -608,7 +660,11 @@ export default defineComponent({ ...@@ -608,7 +660,11 @@ export default defineComponent({
check(() => { check(() => {
let wifiObj = item["wifiLocation"]; let wifiObj = item["wifiLocation"];
if (wifiObj) { if (wifiObj) {
var newLnglat = new window.AMap.LngLat( // var newLnglat = new window.AMap.LngLat(
// wifiObj.elng,
// wifiObj.elat
// );
var newLnglat = mapContentRefs.value.getLngLat(
wifiObj.elng, wifiObj.elng,
wifiObj.elat wifiObj.elat
); );
...@@ -692,18 +748,18 @@ export default defineComponent({ ...@@ -692,18 +748,18 @@ export default defineComponent({
showOverlay.value = true; showOverlay.value = true;
}; };
//点击车辆打开信息窗体 //点击车辆打开信息窗体
marker.on("click", () => { // marker.on("click", () => {
map.setCenter(infoWindow.getPosition()); // map.setCenter(infoWindow.getPosition());
map.panBy(0, 70); // map.panBy(0, 70);
if (infoWindow.getIsOpen()) { // if (infoWindow.getIsOpen()) {
infoWindow.close(); // infoWindow.close();
} else { // } else {
infoWindow.open(map); // infoWindow.open(map);
} // }
setAddress(); // setAddress();
setOnlineTime(); // setOnlineTime();
}); // });
return marker; return lnglat;
}; };
const check = (cb) => { const check = (cb) => {
if (isShareDead.value) { if (isShareDead.value) {
...@@ -990,8 +1046,9 @@ export default defineComponent({ ...@@ -990,8 +1046,9 @@ export default defineComponent({
.car-info-window { .car-info-window {
width: 100%; width: 100%;
.car-info-content { .car-info-content {
margin-right: 48px; // margin-right: 48px;
background-color: #fff; background-color: #fff;
// background-color: #961010;
border-radius: 10px; border-radius: 10px;
border: 1px solid #ececec; border: 1px solid #ececec;
color: #111111; color: #111111;
......
...@@ -67,6 +67,7 @@ export default { ...@@ -67,6 +67,7 @@ export default {
const timeoutId = ref(null); const timeoutId = ref(null);
const listScroll = ref(0); const listScroll = ref(0);
const changey = ref(null); const changey = ref(null);
// var iii = ref(1)
const refreshCb = (map) => { const refreshCb = (map) => {
map.clearMap(); map.clearMap();
getData(); getData();
...@@ -157,46 +158,78 @@ export default { ...@@ -157,46 +158,78 @@ export default {
}, },
() => { () => {
data.forEach((val) => { data.forEach((val) => {
var lnglat = new window.AMap.LngLat(val.elng, val.elat); // val.elng = +val.elng + Math.random(0,9) * 0.0001 * iii.value
// val.elat = +val.elat + Math.random(0,9) * 0.0001 * iii.value
// iii.value = iii.value + 1
// var lnglat = new window.AMap.LngLat(val.elng, val.elat);
var lnglat = mapContentRefs.value.getLngLat(val.elng, val.elat);
polyLineArr.value.push(lnglat); polyLineArr.value.push(lnglat);
locationList.value.push(val); locationList.value.push(val);
if (!carMarker) { if (!carMarker) {
firstPosLng = val.elng; firstPosLng = val.elng;
firstPosLat = val.elat; firstPosLat = val.elat;
carMarker = new window.AMap.Marker({ carMarker = mapContentRefs.value.mapMarker({
position: lnglat, point: lnglat,
content: icon: require("@/assets/images/car.png"),
'<img src=" ' + sizeW: 17,
require("@/assets/images/car.png") + sizeH: 26,
'" style="transform: scale(0.5);" />', imgW: 17,
map: currentMap, imgH: 26,
offset: new window.AMap.Pixel(-17, -26),
}); });
beginMarker = new window.AMap.Marker({ beginMarker = mapContentRefs.value.mapMarker({
position: lnglat, point: lnglat,
content: '<span class="icon icon-begin" ></span>', isAdd: false,
map: currentMap, icon: require("@/assets/icon/begin.png"),
offset: new window.AMap.Pixel(-17, -26), sizeW: 26,
visible: false, sizeH: 36,
imgW: 26,
imgH: 36,
}); });
// carMarker = new window.AMap.Marker({
// position: lnglat,
// content:
// '<img src=" ' +
// require("@/assets/images/car.png") +
// '" style="transform: scale(0.5);" />',
// map: currentMap,
// offset: new window.AMap.Pixel(-17, -26),
// });
// beginMarker = new window.AMap.Marker({
// position: lnglat,
// content: '<span class="icon icon-begin" ></span>',
// map: currentMap,
// offset: new window.AMap.Pixel(-17, -26),
// visible: false,
// });
} else { } else {
carMarker.setPosition(lnglat); // carMarker.setPosition(lnglat);
window.mapapi.invoke("markerSetPosition", carMarker, lnglat);
if (firstPosLng !== val.elng || firstPosLat !== val.elat) { if (firstPosLng !== val.elng || firstPosLat !== val.elat) {
beginMarker.show(); // beginMarker.show();
window.mapapi.invoke("addOverlay", beginMarker);
} }
if (!polyLine) { if (!polyLine) {
polyLine = new window.AMap.Polyline({ polyLine = mapapi.invoke("Polyline", polyLineArr, {
map: currentMap,
strokeWeight: 2, strokeWeight: 2,
strokeColor: "#0b94db", strokeColor: "#009944",
strokeStyle: "solid",
strokeDasharray: [10, 10],
}); });
window.mapapi.invoke("addOverlay", polyLine);
// polyLine = new window.AMap.Polyline({
// map: currentMap,
// strokeWeight: 2,
// strokeColor: "#0b94db",
// strokeStyle: "solid",
// strokeDasharray: [10, 10],
// });
} }
polyLine.setPath(polyLineArr); // polyLine.setPath(polyLineArr);
window.mapapi.invoke("polylineSetPath", polyLineArr.value);
} }
}); });
currentMap.setFitView(); // currentMap.setFitView();
window.mapapi.invoke("setViewport", polyLineArr.value, {
// zoomFactor: -3
});
timeoutId.value = setTimeout(function () { timeoutId.value = setTimeout(function () {
getData(); getData();
}, 10 * 1000); }, 10 * 1000);
......
...@@ -169,7 +169,8 @@ export default defineComponent({ ...@@ -169,7 +169,8 @@ export default defineComponent({
}); });
const refreshCb = (map) => { const refreshCb = (map) => {
map.clearMap(); // map.clearMap();
window.mapapi.invoke("clearOverlays");
getData(); getData();
}; };
const formatter = (type, val) => { const formatter = (type, val) => {
...@@ -248,7 +249,8 @@ export default defineComponent({ ...@@ -248,7 +249,8 @@ export default defineComponent({
if (res.data.length > 0) { if (res.data.length > 0) {
init(currentMap, res.data); init(currentMap, res.data);
} else { } else {
currentMap.clearMap(); // currentMap.clearMap();
window.mapapi.invoke("clearOverlays");
residentList.value = []; residentList.value = [];
Dialog({ message: "暂无数据" }); Dialog({ message: "暂无数据" });
} }
...@@ -263,36 +265,66 @@ export default defineComponent({ ...@@ -263,36 +265,66 @@ export default defineComponent({
timeoutIds: [], timeoutIds: [],
}, },
() => { () => {
var points = [];
for (var i = 0, len = data.length; i < len; i++) { for (var i = 0, len = data.length; i < len; i++) {
var item = data[i]; var item = data[i];
(function (item) { (function (item) {
var lnglat = new window.AMap.LngLat(item.elng, item.elat); var lnglat = mapContentRefs.value.getLngLat(item.elng, item.elat);
var marker = new window.AMap.Marker({ points.push(lnglat);
position: lnglat, // var lnglat = new window.AMap.LngLat(item.elng, item.elat);
content: '<span class="icon icon-resident"></span>', var marker = mapContentRefs.value.mapMarker({
map: currentMap, point: lnglat,
offset: new window.AMap.Pixel(-8.5, -13), icon: require("@/assets/icon/resident.png"),
sizeW: 26,
sizeH: 36,
imgW: 26,
imgH: 36,
}); });
var infoWindow = new window.AMap.InfoWindow({ // var marker = new window.AMap.Marker({
isCustom: true, // position: lnglat,
autoMove: false, // content: '<span class="icon icon-resident"></span>',
position: lnglat, // map: currentMap,
content: `<div class="marker-info-window"><p>${item.transferAddress}</p></div>`, // offset: new window.AMap.Pixel(-8.5, -13),
offset: new window.AMap.Pixel(0, -20), // });
}); // var infoWindow = new window.AMap.InfoWindow({
marker.on("click", function () { // isCustom: true,
currentMap.setCenter(infoWindow.getPosition()); // autoMove: false,
if (infoWindow.getIsOpen()) { // position: lnglat,
infoWindow.close(); // content: `<div class="marker-info-window"><p>${item.transferAddress}</p></div>`,
} else { // offset: new window.AMap.Pixel(0, -20),
infoWindow.open(currentMap); // });
var infoWindow = "";
var infoDiv = `<div class="marker-info-window"><p>${item.transferAddress}</p></div>`;
window.mapapi.invoke(
"markerAddEventListener",
marker,
"click",
(e) => {
infoWindow = window.mapapi.invoke("InfoWindow", infoDiv);
window.mapapi.invoke(
"mapOpenInfoWindow",
infoWindow,
window.mapapi.invoke("markerGetPosition", marker),
{
// offset: window.mapapi.invoke('Size', 22, 100)
}
);
} }
}); );
// marker.on("click", function () {
// currentMap.setCenter(infoWindow.getPosition());
// if (infoWindow.getIsOpen()) {
// infoWindow.close();
// } else {
// infoWindow.open(currentMap);
// }
// });
markerArr.push(marker); markerArr.push(marker);
})(item); })(item);
} }
residentList.value = data; residentList.value = data;
currentMap.setFitView(); // currentMap.setFitView();
window.mapapi.invoke("setViewport", points);
} }
); );
}; };
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!