Commit 7612f389 by 前端

Merge branch 'change_map' into 'master'

上线合并

See merge request !10
2 parents e322c4d6 988641f4
...@@ -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) => {
return new Promise((resolve) => {
let check = () => { let check = () => {
checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId); checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId);
let AMap = window.AMap; if(GLMap) {
if (AMap && typeof AMap.Map == "function") { new GLMap({ version }, mapapi => {
window.AMap = AMap; // new GLMap(mapapi => {
window.mapapi = mapapi;
init(id); init(id);
resolve()
})
} else { } else {
checkLoadedTimeoutId = check(); checkLoadedTimeoutId = check();
} }
}; };
checkLoadedTimeoutId = check(); checkLoadedTimeoutId = check();
});
}; };
const init = (id) => { const init = (id) => {
map = new window.AMap.Map(id); 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; isUploaded.value = true;
context.emit("isUploaded", true); context.emit("isUploaded", true);
context.emit("getData", map); context.emit("getData", map);
return 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,
timeout: 10000,
buttonOffset: new window.AMap.Pixel(10, 20),
zoomToAccuracy: true,
buttonPosition: "RB",
});
geolocation.getCurrentPosition();
window.AMap.event.addListener(geolocation, "complete", (data) => {
if (currMarker) { if (currMarker) {
currMarker.setMap(null); // currMarker.setMap(null);
window.mapapi.invoke('removeOverlay', currMarker)
} }
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) {
...@@ -33,16 +35,16 @@ const MAPGEO = { ...@@ -33,16 +35,16 @@ const MAPGEO = {
let initIdx = i * 20; let initIdx = i * 20;
let maxIdx = i === obj.times - 1 ? obj.len : (i + 1) * 20; let maxIdx = i === obj.times - 1 ? obj.len : (i + 1) * 20;
for (let idx = initIdx; idx < maxIdx; idx++) { for (let idx = initIdx; idx < maxIdx; idx++) {
let _lng = data[idx].lastlng || data[idx].elng; let _lng = data[idx].lastlng || data[idx].blng;
let _lat = data[idx].lastlat || data[idx].elat; let _lat = data[idx].lastlat || data[idx].blat;
// 防止出现gps点:.00000的错误 // 防止出现gps点:.00000的错误
if (Number(_lng) > 0 && Number(_lat) > 0) { if (Number(_lng) > 0 && Number(_lat) > 0) {
lnglatArr.push([_lng, _lat]); lnglatArr.push([_lng, _lat]);
obj.realNum++; obj.realNum++;
} }
// lnglatArr.push([ // lnglatArr.push([
// data[idx].lastlng || data[idx].elng, // data[idx].lastlng || data[idx].blng,
// data[idx].lastlat || data[idx].elat, // data[idx].lastlat || data[idx].blat,
// ]); // ]);
} }
(function (initIdx) { (function (initIdx) {
...@@ -52,22 +54,35 @@ const MAPGEO = { ...@@ -52,22 +54,35 @@ 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 => {
//获取地址成功 const {content: {poi_desc, address_detail: {province, city, district, town, street}}} = res
result.regeocodes.forEach((item, idx) => { data[initIdx + idx].transferAddress = province + city + district + town + street + poi_desc;
data[initIdx + idx].transferAddress = item.formattedAddress;
obj.totalNum++; 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);
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
import { defineComponent, onMounted, ref } from "vue"; import { defineComponent, onMounted, ref } from "vue";
import mapContent from "@/components/mapContent.vue"; import mapContent from "@/components/mapContent.vue";
import popup from "@/components/popup.vue"; import popup from "@/components/popup.vue";
import AMapLoader from "@amap/amap-jsapi-loader"; // import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "../constant"; import { CONSTANT } from "../constant";
import { Toast, Dialog } from "vant"; import { Toast, Dialog } from "vant";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
...@@ -104,18 +104,18 @@ export default defineComponent({ ...@@ -104,18 +104,18 @@ export default defineComponent({
const adcodeItemName = ref(null); const adcodeItemName = ref(null);
let district = null; let district = null;
onMounted(() => { onMounted(() => {
AMapLoader.load({ mapContentRefs.value.initMap("fenceContainer", 1);
key: CONSTANT.MAP_KEY, // AMapLoader.load({
version: "1.4.8", // key: CONSTANT.MAP_KEY,
plugins: CONSTANT.MAP_PLUGINS, // version: "1.4.8",
}).then((AMap) => { // plugins: CONSTANT.MAP_PLUGINS,
window.AMap = AMap; // }).then((AMap) => {
mapContentRefs.value.initMap("fenceContainer"); // window.AMap = AMap;
geocoderValue.value = new AMap.Geocoder({ // geocoderValue.value = new AMap.Geocoder({
radius: 1000, // radius: 1000,
extensions: "all", // extensions: "all",
}); // });
}); // });
}); });
// 地图刷新 // 地图刷新
const refreshCb = (map) => { const refreshCb = (map) => {
...@@ -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"].blng,
val["gpsLocation"].elat val["gpsLocation"].blat
); );
// currLnglat.value = new window.AMap.LngLat(
// val["gpsLocation"].blng,
// val["gpsLocation"].blat
// );
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---");
window.AMap.service("AMap.DistrictSearch", function () { // areaPolygons.length && window.mapapi.invoke("removeDistrictLayer", areaPolygons);
var opts = { console.log(areaName, "areaName---");
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 = []; areaPolygons = [];
if (bounds) { //加载行政区划插件
for (var i = 0, l = bounds.length; i < l; i++) { var dist = window.mapapi.invoke("DistrictLayer", {
//生成行政区划polygon name: `(${areaName})`,
var polygon = new window.AMap.Polygon({
map: currentMap,
strokeWeight: 1,
path: bounds[i],
fillOpacity: 0.7, fillOpacity: 0.7,
fillColor: "#CCF3FF", fillColor: "#CCF3FF",
strokeColor: "#CC66CC", strokeColor: "#CC66CC",
viewport: true,
}); });
areaPolygons.push(polygon); areaPolygons.push(dist);
} window.mapapi.invoke("addDistrictLayer", dist);
currentMap.setFitView(); //地图自适应
showSettingDialog.value = false; 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,
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<script> <script>
import { onMounted, ref, nextTick, watch } from "vue"; import { onMounted, ref, nextTick, watch } from "vue";
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 { GET_CAR_LOCATION_INFO } from "@/api/index"; import { GET_CAR_LOCATION_INFO } from "@/api/index";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
...@@ -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();
...@@ -80,14 +81,14 @@ export default { ...@@ -80,14 +81,14 @@ export default {
timeoutId.value && clearTimeout(timeoutId.value); timeoutId.value && clearTimeout(timeoutId.value);
}; };
onMounted(() => { onMounted(() => {
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
mapContentRefs.value.initMap("monitorContainer"); mapContentRefs.value.initMap("monitorContainer");
}); // AMapLoader.load({
// key: CONSTANT.MAP_KEY,
// version: "1.4.8",
// plugins: CONSTANT.MAP_PLUGINS,
// }).then((AMap) => {
// window.AMap = AMap;
// });
}); });
watch(changey, (newVal) => { watch(changey, (newVal) => {
let listNode = document.querySelector(".list-content-monitor"); let listNode = document.querySelector(".list-content-monitor");
...@@ -143,10 +144,10 @@ export default { ...@@ -143,10 +144,10 @@ export default {
// marker渲染 // marker渲染
const init = (currentMap, data) => { const init = (currentMap, data) => {
data.forEach((val) => { data.forEach((val) => {
(val.elat = (val.blat =
val[routeQuery.locationType] && val[routeQuery.locationType].elat), val[routeQuery.locationType] && val[routeQuery.locationType].blat),
(val.elng = (val.blng =
val[routeQuery.locationType] && val[routeQuery.locationType].elng); val[routeQuery.locationType] && val[routeQuery.locationType].blng);
val.time = val.time =
val[routeQuery.locationType] && val[routeQuery.locationType].dateTime; val[routeQuery.locationType] && val[routeQuery.locationType].dateTime;
}); });
...@@ -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.blng = +val.blng + Math.random(0,9) * 0.0001 * iii.value
// val.blat = +val.blat + Math.random(0,9) * 0.0001 * iii.value
// iii.value = iii.value + 1
// var lnglat = new window.AMap.LngLat(val.blng, val.blat);
var lnglat = mapContentRefs.value.getLngLat(val.blng, val.blat);
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.blng;
firstPosLat = val.elat; firstPosLat = val.blat;
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);
if (firstPosLng !== val.elng || firstPosLat !== val.elat) { window.mapapi.invoke("markerSetPosition", carMarker, lnglat);
beginMarker.show(); if (firstPosLng !== val.blng || firstPosLat !== val.blat) {
// 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);
......
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
import { defineComponent, nextTick, onMounted, ref, watch } from "vue"; import { defineComponent, nextTick, onMounted, ref, watch } from "vue";
import mapContent from "@/components/mapContent.vue"; import mapContent from "@/components/mapContent.vue";
import popup from "@/components/popup.vue"; import popup from "@/components/popup.vue";
import AMapLoader from "@amap/amap-jsapi-loader"; // import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "../constant"; import { CONSTANT } from "../constant";
import moment from "@/utils/moment"; import moment from "@/utils/moment";
import { GET_RESIDENT_DATA } from "@/api/index"; import { GET_RESIDENT_DATA } from "@/api/index";
...@@ -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) => {
...@@ -190,14 +191,14 @@ export default defineComponent({ ...@@ -190,14 +191,14 @@ export default defineComponent({
}); });
}; };
onMounted(() => { onMounted(() => {
AMapLoader.load({ mapContentRefs.value.initMap("residentContainer", 1);
key: CONSTANT.MAP_KEY, // AMapLoader.load({
version: "1.4.8", // key: CONSTANT.MAP_KEY,
plugins: CONSTANT.MAP_PLUGINS, // version: "1.4.8",
}).then((AMap) => { // plugins: CONSTANT.MAP_PLUGINS,
window.AMap = AMap; // }).then((AMap) => {
mapContentRefs.value.initMap("residentContainer"); // window.AMap = AMap;
}); // });
}); });
// 快捷选择时间 // 快捷选择时间
const selectTime = (e) => { const selectTime = (e) => {
...@@ -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.blng, item.blat);
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,
var infoWindow = new window.AMap.InfoWindow({ sizeH: 36,
isCustom: true, imgW: 26,
autoMove: false, imgH: 36,
position: lnglat,
content: `<div class="marker-info-window"><p>${item.transferAddress}</p></div>`,
offset: new window.AMap.Pixel(0, -20),
}); });
marker.on("click", function () { // var marker = new window.AMap.Marker({
currentMap.setCenter(infoWindow.getPosition()); // position: lnglat,
if (infoWindow.getIsOpen()) { // content: '<span class="icon icon-resident"></span>',
infoWindow.close(); // map: currentMap,
} else { // offset: new window.AMap.Pixel(-8.5, -13),
infoWindow.open(currentMap); // });
// 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); markerArr.push(marker);
})(item); })(item);
} }
residentList.value = data; residentList.value = data;
currentMap.setFitView(); // currentMap.setFitView();
window.mapapi.invoke("setViewport", points);
} }
); );
}; };
...@@ -503,11 +535,29 @@ export default defineComponent({ ...@@ -503,11 +535,29 @@ export default defineComponent({
} }
</style> </style>
<style lang="scss"> <style lang="scss">
.BMap_bubble_pop{
img{
top:52px !important;
}
}
.BMap_bubble_top{
// display: none;
height: 7px !important;
}
.BMap_bubble_title{
height: 7px !important;
}
.BMap_bubble_center{
height:44px!important;
}
.marker-info-window { .marker-info-window {
background-color: rgba(0, 0, 0, 0.7); color: #111111;
color: #fff; font-size:12px;
border-radius: 4px; // color: #fff;
padding: 10px; // border-radius: 4px;
padding: 5px 10px;
} }
.van-picker__toolbar { .van-picker__toolbar {
display: none; display: none;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<script> <script>
import { ref, defineComponent, onMounted } from "vue"; import { ref, defineComponent, onMounted } from "vue";
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";
export default defineComponent({ export default defineComponent({
name: "SharePage", name: "SharePage",
...@@ -22,14 +22,14 @@ export default defineComponent({ ...@@ -22,14 +22,14 @@ export default defineComponent({
setup() { setup() {
const mapContentRefs = ref(null); const mapContentRefs = ref(null);
onMounted(() => { onMounted(() => {
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
mapContentRefs.value.initMap("shareContainer"); mapContentRefs.value.initMap("shareContainer");
}); // AMapLoader.load({
// key: CONSTANT.MAP_KEY,
// version: "1.4.8",
// plugins: CONSTANT.MAP_PLUGINS,
// }).then((AMap) => {
// window.AMap = AMap;
// });
}); });
return { return {
mapContentRefs, mapContentRefs,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!