Commit 7612f389 by 前端

Merge branch 'change_map' into 'master'

上线合并

See merge request !10
2 parents e322c4d6 988641f4
......@@ -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) {
......@@ -33,16 +35,16 @@ const MAPGEO = {
let initIdx = i * 20;
let maxIdx = i === obj.times - 1 ? obj.len : (i + 1) * 20;
for (let idx = initIdx; idx < maxIdx; idx++) {
let _lng = data[idx].lastlng || data[idx].elng;
let _lat = data[idx].lastlat || data[idx].elat;
let _lng = data[idx].lastlng || data[idx].blng;
let _lat = data[idx].lastlat || data[idx].blat;
// 防止出现gps点:.00000的错误
if (Number(_lng) > 0 && Number(_lat) > 0) {
lnglatArr.push([_lng, _lat]);
obj.realNum++;
}
// lnglatArr.push([
// data[idx].lastlng || data[idx].elng,
// data[idx].lastlat || data[idx].elat,
// data[idx].lastlng || data[idx].blng,
// data[idx].lastlat || data[idx].blat,
// ]);
}
(function (initIdx) {
......@@ -52,22 +54,35 @@ 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 => {
const {content: {poi_desc, address_detail: {province, city, district, town, street}}} = res
data[initIdx + idx].transferAddress = province + city + district + town + street + poi_desc;
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);
......
......@@ -74,7 +74,7 @@
import { defineComponent, onMounted, ref } from "vue";
import mapContent from "@/components/mapContent.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 { Toast, Dialog } from "vant";
import { useRoute } from "vue-router";
......@@ -104,18 +104,18 @@ export default defineComponent({
const adcodeItemName = ref(null);
let district = null;
onMounted(() => {
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
mapContentRefs.value.initMap("fenceContainer");
geocoderValue.value = new AMap.Geocoder({
radius: 1000,
extensions: "all",
});
});
mapContentRefs.value.initMap("fenceContainer", 1);
// AMapLoader.load({
// key: CONSTANT.MAP_KEY,
// version: "1.4.8",
// plugins: CONSTANT.MAP_PLUGINS,
// }).then((AMap) => {
// window.AMap = AMap;
// geocoderValue.value = new AMap.Geocoder({
// radius: 1000,
// extensions: "all",
// });
// });
});
// 地图刷新
const refreshCb = (map) => {
......@@ -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(
val["gpsLocation"].elng,
val["gpsLocation"].elat
currLnglat.value = mapContentRefs.value.getLngLat(
val["gpsLocation"].blng,
val["gpsLocation"].blat
);
// currLnglat.value = new window.AMap.LngLat(
// val["gpsLocation"].blng,
// val["gpsLocation"].blat
// );
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,
......
......@@ -38,7 +38,7 @@
<script>
import { onMounted, ref, nextTick, watch } from "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 { GET_CAR_LOCATION_INFO } from "@/api/index";
import { useRoute } from "vue-router";
......@@ -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();
......@@ -80,14 +81,14 @@ export default {
timeoutId.value && clearTimeout(timeoutId.value);
};
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) => {
let listNode = document.querySelector(".list-content-monitor");
......@@ -143,10 +144,10 @@ export default {
// marker渲染
const init = (currentMap, data) => {
data.forEach((val) => {
(val.elat =
val[routeQuery.locationType] && val[routeQuery.locationType].elat),
(val.elng =
val[routeQuery.locationType] && val[routeQuery.locationType].elng);
(val.blat =
val[routeQuery.locationType] && val[routeQuery.locationType].blat),
(val.blng =
val[routeQuery.locationType] && val[routeQuery.locationType].blng);
val.time =
val[routeQuery.locationType] && val[routeQuery.locationType].dateTime;
});
......@@ -157,46 +158,78 @@ export default {
},
() => {
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);
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),
firstPosLng = val.blng;
firstPosLat = val.blat;
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);
if (firstPosLng !== val.elng || firstPosLat !== val.elat) {
beginMarker.show();
// carMarker.setPosition(lnglat);
window.mapapi.invoke("markerSetPosition", carMarker, lnglat);
if (firstPosLng !== val.blng || firstPosLat !== val.blat) {
// 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);
......
......@@ -92,7 +92,7 @@
import { defineComponent, nextTick, onMounted, ref, watch } from "vue";
import mapContent from "@/components/mapContent.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 moment from "@/utils/moment";
import { GET_RESIDENT_DATA } from "@/api/index";
......@@ -169,7 +169,8 @@ export default defineComponent({
});
const refreshCb = (map) => {
map.clearMap();
// map.clearMap();
window.mapapi.invoke("clearOverlays");
getData();
};
const formatter = (type, val) => {
......@@ -190,14 +191,14 @@ 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("residentContainer");
});
mapContentRefs.value.initMap("residentContainer", 1);
// AMapLoader.load({
// key: CONSTANT.MAP_KEY,
// version: "1.4.8",
// plugins: CONSTANT.MAP_PLUGINS,
// }).then((AMap) => {
// window.AMap = AMap;
// });
});
// 快捷选择时间
const selectTime = (e) => {
......@@ -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 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 lnglat = mapContentRefs.value.getLngLat(item.blng, item.blat);
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,
});
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);
}
);
};
......@@ -503,11 +535,29 @@ export default defineComponent({
}
</style>
<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 {
background-color: rgba(0, 0, 0, 0.7);
color: #fff;
border-radius: 4px;
padding: 10px;
color: #111111;
font-size:12px;
// color: #fff;
// border-radius: 4px;
padding: 5px 10px;
}
.van-picker__toolbar {
display: none;
......
......@@ -12,7 +12,7 @@
<script>
import { ref, defineComponent, onMounted } from "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";
export default defineComponent({
name: "SharePage",
......@@ -22,14 +22,14 @@ export default defineComponent({
setup() {
const mapContentRefs = ref(null);
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 {
mapContentRefs,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!