Commit 018410ed by chenwq

高德地图切换成百度地图

1 parent e322c4d6
......@@ -27,34 +27,11 @@
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~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-loader": "^10.0.3",
"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": [
"> 1%",
"last 2 versions",
......
......@@ -25,6 +25,7 @@
import { onMounted, ref } from "vue";
import { Toast } from "vant";
import "vant/es/toast/style";
import GLMap from "@/utils/glsk-mapapi-sdk.js";
export default {
name: "mapContent",
props: {},
......@@ -36,58 +37,116 @@ export default {
const roadActive = ref(null);
const isGetLocation = ref(false);
onMounted(() => {});
const initMap = (id) => {
let check = () => {
checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId);
let AMap = window.AMap;
if (AMap && typeof AMap.Map == "function") {
window.AMap = AMap;
init(id);
} else {
checkLoadedTimeoutId = check();
}
};
checkLoadedTimeoutId = check();
const initMap = (id, version = 3) => {
return new Promise((resolve) => {
let check = () => {
checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId);
if(GLMap) {
new GLMap({ version }, mapapi => {
// new GLMap(mapapi => {
window.mapapi = mapapi;
init(id);
resolve()
})
} else {
checkLoadedTimeoutId = check();
}
};
checkLoadedTimeoutId = check();
});
};
const init = (id) => {
map = new window.AMap.Map(id);
isUploaded.value = true;
context.emit("isUploaded", true);
context.emit("getData", map);
return map;
map = window.mapapi.invoke('Map', id);
var point = mapapi.invoke('Point', 116.2317, 39.5427)
window.mapapi.invoke('LocalCity', (data) => {
if(data) {
point = data.center
}
mapapi.invoke('centerAndZoom', point, 10);
isUploaded.value = true;
context.emit("isUploaded", true);
context.emit("getData", map);
return map;
})
};
let currMarker = null;
// 获取定位
const getLocation = () => {
isGetLocation.value = true;
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);
window.mapapi.invoke('Geolocation', (data) => {
if(data) {
if (currMarker) {
// currMarker.setMap(null);
window.mapapi.invoke('removeOverlay', currMarker)
}
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", () => {
currMarker = window.mapapi.invoke('Marker', data.point, {
icon: window.mapapi.invoke('Icon', require("@/assets/images/curr-marker.gif"), window.mapapi.invoke('Size', 24, 24)),
// offset: window.mapapi.invoke('Pixel', -12, -12),
})
window.mapapi.invoke('addOverlay', currMarker)
window.mapapi.invoke('panTo', data.point)
// 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();
} else {
Toast("获取定位失败");
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 = () => {
......@@ -100,6 +159,8 @@ export default {
getLocation,
satelActive,
roadActive,
getLngLat,
mapMarker,
refresh,
isUploaded,
isGetLocation,
......
const MAPGEO = {
geocoder: null,
getGeocoder: function () {
let AMap = window.AMap;
// let AMap = window.AMap;
return new Promise((resolve) => {
AMap.service("AMap.Geocoder", function () {
//回调函数
var geocoder = new AMap.Geocoder({
batch: true,
});
MAPGEO.geocoder = geocoder;
resolve(geocoder);
});
MAPGEO.geocoder = window.mapapi.invoke('Geocoder')
resolve(MAPGEO.geocoder)
// AMap.service("AMap.Geocoder", function () {
// //回调函数
// var geocoder = new AMap.Geocoder({
// batch: true,
// });
// MAPGEO.geocoder = geocoder;
// resolve(geocoder);
// });
});
},
transferAddressByGroup(obj, cb) {
......@@ -52,22 +54,34 @@ const MAPGEO = {
function geocoderGetAdr(arr, initIdx) {
const timeoutId = window.setTimeout(() => {
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++;
});
arr.forEach((item, idx) => {
window.mapapi.invoke('getLocation', window.mapapi.invoke('Point', item[0], item[1]), res => {
data[initIdx + idx].transferAddress = res.address;
obj.totalNum++;
if (obj.totalNum === obj.realNum) {
cb && cb(data);
//ifPlay && obj.init(data)
//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);
......
......@@ -110,7 +110,7 @@ export default defineComponent({
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
mapContentRefs.value.initMap("fenceContainer");
mapContentRefs.value.initMap("fenceContainer", 1);
geocoderValue.value = new AMap.Geocoder({
radius: 1000,
extensions: "all",
......@@ -128,7 +128,8 @@ export default defineComponent({
if (hasProviceCityFence.value && adcodeItemName.value) {
coverArea(adcodeItemName.value, map);
}
map.setFitView();
// map.setFitView();
window.mapapi.invoke("setViewport", { center: currLnglat.value });
};
// 切换围栏类型
const changeFenceType = (index) => {
......@@ -145,10 +146,14 @@ export default defineComponent({
if (res.code === 200) {
if (res.data.length > 0) {
res.data.forEach((val) => {
currLnglat.value = new window.AMap.LngLat(
currLnglat.value = mapContentRefs.value.getLngLat(
val["gpsLocation"].elng,
val["gpsLocation"].elat
);
// currLnglat.value = new window.AMap.LngLat(
// val["gpsLocation"].elng,
// val["gpsLocation"].elat
// );
drawMarker(currLnglat.value);
});
} else {
......@@ -180,7 +185,8 @@ export default defineComponent({
currentMap = currentMap
? currentMap
: mapContentRefs.value.init("fenceContainer");
currentMap.setFitView();
// currentMap.setFitView();
window.mapapi.invoke("setViewport", { center: currLnglat.value, zoom: 12 });
showSettingDialog.value = false;
hasRadiusFence.value = true;
}
......@@ -203,7 +209,8 @@ export default defineComponent({
);
adcodeItemName.value = obj.adName;
coverArea(obj.adName, currentMap);
currentMap.setFitView();
// currentMap.setFitView();
window.mapapi.invoke("setViewport", { center: currLnglat.value });
hasProviceCityFence.value = true;
}
});
......@@ -211,39 +218,56 @@ export default defineComponent({
}
};
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 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(); //地图自适应
showSettingDialog.value = false;
}
});
var dist = window.mapapi.invoke("DistrictLayer", {
name: `(${areaName})`,
fillOpacity: 0.7,
fillColor: "#CCF3FF",
strokeColor: "#CC66CC",
viewport: true,
});
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
const getAdcodeByLatlng = (currLnglat, cb) => {
......@@ -277,48 +301,77 @@ export default defineComponent({
};
// 添加标记
const drawMarker = (currLnglat) => {
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),
mapContentRefs.value.mapMarker({
point: currLnglat,
icon: require("@/assets/images/car.png"),
sizeW: 17,
sizeH: 26,
imgW: 17,
imgH: 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) => {
currentMap = currentMap
? currentMap
: mapContentRefs.value.init("fenceContainer");
return new window.AMap.Circle({
map: currentMap,
center: lnglat,
radius: radius,
var circle = window.mapapi.invoke("Circle", lnglat, radius, {
strokeColor: "#0077FF",
fillColor: "#0077FF",
strokeWeight: 1,
strokeOpacity: 0.5,
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) => {
currentMap = currentMap
? currentMap
: mapContentRefs.value.init("fenceContainer");
return new window.AMap.Circle({
map: currentMap,
center: lnglat,
radius: 3,
var circle = window.mapapi.invoke("Circle", lnglat, 3, {
strokeColor: "#094",
fillColor: "#094",
strokeWeight: 3,
strokeOpacity: 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 {
getData,
......
......@@ -156,7 +156,7 @@
import { ref, defineComponent, onMounted, watch, computed } from "vue";
import { useStore } from "vuex";
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 MAPGEO from "@/utils/mapgeo";
import wx from "wx";
......@@ -199,7 +199,8 @@ export default defineComponent({
let map = undefined;
const refreshCb = () => {
if (map && carItem.value) {
map && map.clearMap();
// map && map.clearMap();
window.mapapi.invoke("clearOverlays");
if (Object.keys(carItem.value).length > 0) {
getCarInfo(carItem.value);
}
......@@ -324,14 +325,18 @@ export default defineComponent({
// }
// });
onMounted(() => {
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
mapContentRefs.value.initMap("container");
});
mapContentRefs.value.initMap("container");
// mapContentRefs.value.initMap("container").then(res => {
// mapContentRefs.value.getLocation();
// })
// AMapLoader.load({
// key: CONSTANT.MAP_KEY,
// version: "1.4.8",
// plugins: CONSTANT.MAP_PLUGINS,
// }).then((AMap) => {
// window.AMap = AMap;
// mapContentRefs.value.initMap("container");
// });
initViewport(window.innerHeight);
});
const initViewport = (height) => {
......@@ -359,11 +364,12 @@ export default defineComponent({
});
localStorage.setItem("carInfo", JSON.stringify(it));
map = map ? map : mapContentRefs.value.init("container");
map.clearMap();
// map.clearMap();
window.mapapi.invoke("clearOverlays");
GET_CAR_LOCATION_INFO({ sns: it.sns }).then((res) => {
if (res.code === 200) {
if (res.data.length > 0) {
const markers = [];
const points = [];
let locates = [];
res.data.forEach((item) => {
item.locationType = "gpsLocation";
......@@ -401,7 +407,7 @@ export default defineComponent({
locates.push(item.wifiLocation);
item.wifiLocation.transferAddress = "";
}
markers.push(drawMarker(item, map, locates));
points.push(drawMarker(item, map, locates));
});
if (locates.length <= 0) {
return Toast("暂无有效定位点信息");
......@@ -409,8 +415,9 @@ export default defineComponent({
MAPGEO.transferAddressByGroup(
{ data: locates, timeoutIds: [] },
() => {
console.log(markers);
map.setFitView(markers);
if (points.every((item) => item !== undefined)) {
window.mapapi.invoke("setViewport", points);
}
}
);
} else {
......@@ -420,6 +427,7 @@ export default defineComponent({
});
};
const drawMarker = (item, map, locates) => {
console.log(window.mapapi);
//item.locationType = "gpsLocation";
if (!item[item.locationType]) return;
//修改数据格式方便获取
......@@ -431,19 +439,43 @@ export default defineComponent({
item[item.locationType].transferAddress = val.transferAddress;
}
});
var lnglat = new window.AMap.LngLat(
var lnglat = mapContentRefs.value.getLngLat(
item[item.locationType].elng,
item[item.locationType].elat
);
var marker = new window.AMap.Marker({
position: lnglat,
content:
var marker = mapContentRefs.value.mapMarker({
point: lnglat,
icon:
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),
? require("@/assets/icon/off-car.png")
: require("@/assets/icon/on-car.png"),
Animation: "BMAP_ANIMATION_BOUNCE",
});
// 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">`;
carInfoWindowTpl += `<div class="main-info">`;
carInfoWindowTpl += `<h4 class="info-title"><div>${
......@@ -503,18 +535,35 @@ export default defineComponent({
</div>`;
let infoDiv = document.createElement("div");
infoDiv.innerHTML = carInfoWindowTpl;
let infoWindow = new window.AMap.InfoWindow({
isCustom: true,
autoMove: false,
position: lnglat,
content: infoDiv,
offset: new window.AMap.Pixel(24, -20),
var infoWindow = "";
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)
}
);
});
// 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) => {
marker.setPosition(newLnglat);
infoWindow.setPosition(newLnglat);
map.setCenter(newLnglat);
map.panBy(0, 70);
window.mapapi.invoke("markerSetPosition", marker, newLnglat);
window.mapapi.invoke("openInfoWindow", infoWindow, newLnglat);
// marker.setPosition(newLnglat);
// infoWindow.setPosition(newLnglat);
// map.setCenter(newLnglat);
// map.panBy(0, 70);
window.mapapi.invoke("panTo", newLnglat);
};
//信息窗体内容更新
let GPSBtn = infoDiv.querySelector("[data-GPS]");
......@@ -567,7 +616,10 @@ export default defineComponent({
check(() => {
let gpsObj = item["gpsLocation"];
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");
GPRSIcon && GPRSIcon.classList.remove("active");
WIFIIcon && WIFIIcon.classList.remove("active");
......@@ -590,7 +642,7 @@ export default defineComponent({
GPSIcon && GPSIcon.classList.remove("active");
WIFIIcon && WIFIIcon.classList.remove("active");
item.locationType = "bsLocation";
var newLnglat = new window.AMap.LngLat(
var newLnglat = mapContentRefs.value.getLngLat(
gprsObj.elng,
gprsObj.elat
);
......@@ -608,7 +660,11 @@ export default defineComponent({
check(() => {
let wifiObj = item["wifiLocation"];
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.elat
);
......@@ -692,18 +748,18 @@ export default defineComponent({
showOverlay.value = true;
};
//点击车辆打开信息窗体
marker.on("click", () => {
map.setCenter(infoWindow.getPosition());
map.panBy(0, 70);
if (infoWindow.getIsOpen()) {
infoWindow.close();
} else {
infoWindow.open(map);
}
setAddress();
setOnlineTime();
});
return marker;
// marker.on("click", () => {
// map.setCenter(infoWindow.getPosition());
// map.panBy(0, 70);
// if (infoWindow.getIsOpen()) {
// infoWindow.close();
// } else {
// infoWindow.open(map);
// }
// setAddress();
// setOnlineTime();
// });
return lnglat;
};
const check = (cb) => {
if (isShareDead.value) {
......@@ -990,8 +1046,9 @@ export default defineComponent({
.car-info-window {
width: 100%;
.car-info-content {
margin-right: 48px;
// margin-right: 48px;
background-color: #fff;
// background-color: #961010;
border-radius: 10px;
border: 1px solid #ececec;
color: #111111;
......
......@@ -67,6 +67,7 @@ export default {
const timeoutId = ref(null);
const listScroll = ref(0);
const changey = ref(null);
// var iii = ref(1)
const refreshCb = (map) => {
map.clearMap();
getData();
......@@ -157,46 +158,78 @@ export default {
},
() => {
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);
locationList.value.push(val);
if (!carMarker) {
firstPosLng = val.elng;
firstPosLat = val.elat;
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),
carMarker = mapContentRefs.value.mapMarker({
point: lnglat,
icon: require("@/assets/images/car.png"),
sizeW: 17,
sizeH: 26,
imgW: 17,
imgH: 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,
beginMarker = mapContentRefs.value.mapMarker({
point: lnglat,
isAdd: false,
icon: require("@/assets/icon/begin.png"),
sizeW: 26,
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 {
carMarker.setPosition(lnglat);
// carMarker.setPosition(lnglat);
window.mapapi.invoke("markerSetPosition", carMarker, lnglat);
if (firstPosLng !== val.elng || firstPosLat !== val.elat) {
beginMarker.show();
// beginMarker.show();
window.mapapi.invoke("addOverlay", beginMarker);
}
if (!polyLine) {
polyLine = new window.AMap.Polyline({
map: currentMap,
polyLine = mapapi.invoke("Polyline", polyLineArr, {
strokeWeight: 2,
strokeColor: "#0b94db",
strokeStyle: "solid",
strokeDasharray: [10, 10],
strokeColor: "#009944",
});
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 () {
getData();
}, 10 * 1000);
......
......@@ -169,7 +169,8 @@ export default defineComponent({
});
const refreshCb = (map) => {
map.clearMap();
// map.clearMap();
window.mapapi.invoke("clearOverlays");
getData();
};
const formatter = (type, val) => {
......@@ -248,7 +249,8 @@ export default defineComponent({
if (res.data.length > 0) {
init(currentMap, res.data);
} else {
currentMap.clearMap();
// currentMap.clearMap();
window.mapapi.invoke("clearOverlays");
residentList.value = [];
Dialog({ message: "暂无数据" });
}
......@@ -263,36 +265,66 @@ export default defineComponent({
timeoutIds: [],
},
() => {
var points = [];
for (var i = 0, len = data.length; i < len; i++) {
var item = data[i];
(function (item) {
var lnglat = new window.AMap.LngLat(item.elng, item.elat);
var marker = new window.AMap.Marker({
position: lnglat,
content: '<span class="icon icon-resident"></span>',
map: currentMap,
offset: new window.AMap.Pixel(-8.5, -13),
var lnglat = mapContentRefs.value.getLngLat(item.elng, item.elat);
points.push(lnglat);
// var lnglat = new window.AMap.LngLat(item.elng, item.elat);
var marker = mapContentRefs.value.mapMarker({
point: lnglat,
icon: require("@/assets/icon/resident.png"),
sizeW: 26,
sizeH: 36,
imgW: 26,
imgH: 36,
});
var infoWindow = new window.AMap.InfoWindow({
isCustom: true,
autoMove: false,
position: lnglat,
content: `<div class="marker-info-window"><p>${item.transferAddress}</p></div>`,
offset: new window.AMap.Pixel(0, -20),
});
marker.on("click", function () {
currentMap.setCenter(infoWindow.getPosition());
if (infoWindow.getIsOpen()) {
infoWindow.close();
} else {
infoWindow.open(currentMap);
// var marker = new window.AMap.Marker({
// position: lnglat,
// content: '<span class="icon icon-resident"></span>',
// map: currentMap,
// offset: new window.AMap.Pixel(-8.5, -13),
// });
// var infoWindow = new window.AMap.InfoWindow({
// isCustom: true,
// autoMove: false,
// position: lnglat,
// content: `<div class="marker-info-window"><p>${item.transferAddress}</p></div>`,
// offset: new window.AMap.Pixel(0, -20),
// });
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);
})(item);
}
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!