地图点位名隐藏

pull/123/head
lukeyan 1 year ago
parent 36815f029a
commit a990224694

@ -1,202 +1,222 @@
<template> <template>
<div> <div>
<div class="bmap" id="container" ref="container"></div> <div class="bmap" id="container" ref="container"></div>
<el-button class="fanhui" @click="goBack" v-if="isGoBack"></el-button> <el-button class="fanhui" @click="goBack" v-if="isGoBack"></el-button>
</div> </div>
</template> </template>
<script> <script>
import MapLine from "../../../public/zhenhaiLine.json" import MapLine from "../../../public/zhenhaiLine.json";
import MapPoint from "../../../public/zhenhaiPoint.json" import MapPoint from "../../../public/zhenhaiPoint.json";
import styleJson from "../../../public/custom_map_config.json" import styleJson from "../../../public/custom_map_config.json";
import { topMap, topMapOne } from '@/api/offLineMap' import { topMap, topMapOne } from "@/api/offLineMap";
export default { export default {
name: 'zhenhaimap', name: "zhenhaimap",
data() { data() {
return { return {
dongtaiPoint: [121.604192, 29.971189], dongtaiPoint: [121.604192, 29.971189],
isGoBack: false, isGoBack: false,
villageList: [], villageList: [],
villageSumList: [], villageSumList: [],
flag: true, flag: true,
companyList: [], companyList: [],
label1: {} label1: {},
} };
}, },
mounted() { mounted() {
topMap({ scoreType: 'season' }).then(res => { topMap({ scoreType: "season" }).then((res) => {
this.companyList = res.data this.companyList = res.data;
this.initMap() this.initMap();
}) });
},
methods: {
goBack() {
this.initMap();
this.isGoBack = false;
this.$emit("goBack");
}, },
methods: { initMap() {
goBack() { var BMap = window.BMap;
this.initMap() // console.log(BMap, 'BMap');
this.isGoBack = false var map = new BMap.Map("container", {
this.$emit('goBack') style: {
styleJson,
}, },
initMap() { });
var BMap = window.BMap let that = this;
// console.log(BMap, 'BMap'); map.centerAndZoom(
var map = new BMap.Map('container', { new BMap.Point(this.dongtaiPoint[0], this.dongtaiPoint[1]),
style: { 12
styleJson );
} map.setMinZoom(12);
}); map.setMaxZoom(19);
let that = this map.enableScrollWheelZoom(true);
map.centerAndZoom(new BMap.Point(this.dongtaiPoint[0], this.dongtaiPoint[1]), 12); // hjrequest({
map.setMinZoom(12) // url: '/yc/dt/statistical/village',
map.setMaxZoom(19) // method: 'get',
map.enableScrollWheelZoom(true); // params: { areaCode: that.areaCode }
// hjrequest({ // }).then((res) => {
// url: '/yc/dt/statistical/village', // that.villageSumList = res.data
// method: 'get', // })
// params: { areaCode: that.areaCode } // console.log(MapLine, 'MapLine');
// }).then((res) => { for (var i = 0, n = MapLine.features.length; i < n; i++) {
// that.villageSumList = res.data showBoundaryEx(MapLine.features[i]);
// }) }
// console.log(MapLine, 'MapLine'); var label = new BMap.Label();
for (var i = 0, n = MapLine.features.length; i < n; i++) { showPoint();
showBoundaryEx(MapLine.features[i]); function showBoundaryEx(city) {
var paths = [];
var list = city.geometry.coordinates;
// console.log(list.length, 'list[0].length')
//console.log(list[1], 'list[1].length')
var polygon = {};
if (list.length > 1) {
for (let a = 0; a < list.length; a++) {
paths = [];
for (let i = 0; i < list[a][0].length; i++) {
let lat = list[a][0][i][1],
lng = list[a][0][i][0];
paths.push(new BMap.Point(lng, lat));
} }
var label = new BMap.Label(); polygon = new BMap.Polygon(paths, {
showPoint() fillColor: "#3b4c44",
function showBoundaryEx(city) { strokeColor: "#0f1423",
var paths = [] fillOpacity: 0.6,
var list = city.geometry.coordinates strokeWeight: 1,
// console.log(list.length, 'list[0].length') }); //
//console.log(list[1], 'list[1].length') map.addOverlay(polygon); //
var polygon = {} }
if (list.length > 1) { // // console.log(list, 'length');
for (let a = 0; a < list.length; a++) { } else {
paths = [] // console.log(list[0], ' list[0]');
for (let i = 0; i < list[a][0].length; i++) { for (let i = 0; i < list[0].length; i++) {
let lat = list[a][0][i][1], let lat = list[0][i][1],
lng = list[a][0][i][0]; lng = list[0][i][0];
paths.push(new BMap.Point(lng, lat)); paths.push(new BMap.Point(lng, lat));
} }
polygon = new BMap.Polygon(paths, { // console.log(list, 'length');
fillColor: '#3b4c44', polygon = new BMap.Polygon(paths, {
strokeColor: "#0f1423", fillColor: "#3b4c44",
fillOpacity: 0.6, strokeColor: "#0f1423",
strokeWeight: 1 fillOpacity: 0.6,
}); // strokeWeight: 1,
map.addOverlay(polygon); // }); //
} map.addOverlay(polygon); //
// // console.log(list, 'length'); }
} else { polygon.infowindow = new BMap.InfoWindow();
// console.log(list[0], ' list[0]'); polygon.infowindow.name = city.properties.name;
for (let i = 0; i < list[0].length; i++) { polygon.addEventListener("mouseover", function () {
let lat = list[0][i][1], polygon.setFillColor("#ffa500");
lng = list[0][i][0]; });
paths.push(new BMap.Point(lng, lat)); polygon.addEventListener("mouseout", function () {
} map.removeOverlay(label);
// console.log(list, 'length'); polygon.setFillColor("#3b4c44");
polygon = new BMap.Polygon(paths, { });
fillColor: '#3b4c44', //"mouseover","mouseout",,. click
strokeColor: "#0f1423", polygon.addEventListener("click", function () {
fillOpacity: 0.6, console.log(city.properties.name, "city.properties.name");
strokeWeight: 1 if (city.properties.name == "骆驼街道") {
}); // map.centerAndZoom(new BMap.Point(121.58887, 29.986122), 15);
map.addOverlay(polygon); // that.isGoBack = true;
} } else if (city.properties.name == "招宝山街道") {
polygon.infowindow = new BMap.InfoWindow(); map.centerAndZoom(new BMap.Point(121.713707, 29.95656), 15);
polygon.infowindow.name = city.properties.name; that.isGoBack = true;
polygon.addEventListener("mouseover", function () { } else if (city.properties.name == "蛟川街道") {
polygon.setFillColor("#ffa500"); map.centerAndZoom(new BMap.Point(121.686105, 29.947339), 15);
}); that.isGoBack = true;
polygon.addEventListener("mouseout", function () { } else if (city.properties.name == "庄市街道") {
map.removeOverlay(label); map.centerAndZoom(new BMap.Point(121.627037, 29.925579), 15);
polygon.setFillColor('#3b4c44'); that.isGoBack = true;
}); } else if (city.properties.name == "贵驷街道") {
map.centerAndZoom(new BMap.Point(121.624142, 29.985606), 15);
that.isGoBack = true;
//"mouseover","mouseout",,. click } else if (city.properties.name == "澥浦镇") {
polygon.addEventListener("click", function () { map.centerAndZoom(new BMap.Point(121.607133, 30.037162), 15);
console.log(city.properties.name, 'city.properties.name'); that.isGoBack = true;
if (city.properties.name == '骆驼街道') { } else if (city.properties.name == "九龙湖镇") {
map.centerAndZoom(new BMap.Point(121.58887, 29.986122), 15); map.centerAndZoom(new BMap.Point(121.558532, 30.039457), 15);
that.isGoBack = true that.isGoBack = true;
} else if (city.properties.name == '招宝山街道') { }
map.centerAndZoom(new BMap.Point(121.713707, 29.95656), 15); // let streetCode = that.streetCodeList.filter((item) => {
that.isGoBack = true // if (item.areaName == city.properties.name) {
} else if (city.properties.name == '蛟川街道') { // return item.areaCode
map.centerAndZoom(new BMap.Point(121.686105, 29.947339), 15); // }
that.isGoBack = true // });
} else if (city.properties.name == '庄市街道') { // let goStreetData = { areaCode: that.areaCode, streetCode: streetCode[0].areaCode }
map.centerAndZoom(new BMap.Point(121.627037, 29.925579), 15); // that.$emit('goStreet', streetCode[0].areaCode)
that.isGoBack = true // hjrequest({
} else if (city.properties.name == '贵驷街道') { // url: '/yc/dt/statistical/villages',
map.centerAndZoom(new BMap.Point(121.624142, 29.985606), 15); // method: 'get',
that.isGoBack = true // params: goStreetData
} else if (city.properties.name == '澥浦镇') { // }).then((res) => {
map.centerAndZoom(new BMap.Point(121.607133, 30.037162), 15); // that.villageList = res.data
that.isGoBack = true // that.villageList.forEach((item) => {
} else if (city.properties.name == '九龙湖镇') { // var point = new BMap.Point(item.longitude, item.latitude);
map.centerAndZoom(new BMap.Point(121.558532, 30.039457), 15); // var marker = new BMap.Marker(point); //
that.isGoBack = true // map.addOverlay(marker);
} // var content = item.villageName;
// let streetCode = that.streetCodeList.filter((item) => { // var label = new BMap.Label(content, { //
// if (item.areaName == city.properties.name) { // position: point, //
// return item.areaCode // offset: new BMap.Size(-10, -50) //
// } // })
// }); // label.setStyle({ backgroundColor: ' rgba(0, 0, 0, 0)', border: '0', color: 'yellow', fontSize: '20px' })
// let goStreetData = { areaCode: that.areaCode, streetCode: streetCode[0].areaCode } // map.addOverlay(label);
// that.$emit('goStreet', streetCode[0].areaCode) // marker.addEventListener("click", function () {
// hjrequest({ // // Cookies.set('village_current', item.villageCode)
// url: '/yc/dt/statistical/villages', // window.open(window.location.origin + '/#/communityShow', '_blank');
// method: 'get', // });
// params: goStreetData // })
// }).then((res) => { // })
// that.villageList = res.data
// that.villageList.forEach((item) => {
// var point = new BMap.Point(item.longitude, item.latitude);
// var marker = new BMap.Marker(point); //
// map.addOverlay(marker);
// var content = item.villageName;
// var label = new BMap.Label(content, { //
// position: point, //
// offset: new BMap.Size(-10, -50) //
// })
// label.setStyle({ backgroundColor: ' rgba(0, 0, 0, 0)', border: '0', color: 'yellow', fontSize: '20px' })
// map.addOverlay(label);
// marker.addEventListener("click", function () {
// // Cookies.set('village_current', item.villageCode)
// window.open(window.location.origin + '/#/communityShow', '_blank');
// });
// })
// })
that.companyList.forEach((item) => { that.companyList.forEach((item) => {
var point = new BMap.Point(item.longitude, item.latitude); var point = new BMap.Point(item.longitude, item.latitude);
console.log(point, 'point123'); console.log(point, "point123");
var marker = new BMap.Marker(point); // var marker = new BMap.Marker(point); //
map.addOverlay(marker); map.addOverlay(marker);
var content = item.companyName; var content = item.companyName;
var label = new BMap.Label(content, { // var label = new BMap.Label(content, {
position: point, // //
offset: new BMap.Size(-10, -50) // position: point, //
}) offset: new BMap.Size(-10, -50), //
label.setStyle({ backgroundColor: ' rgba(0, 0, 0, 0)', border: '0', color: '#0060ce', fontSize: '16px' }) });
map.addOverlay(label); label.setStyle({
label.addEventListener("click", function () { backgroundColor: " rgba(0, 0, 0, 0)",
map.removeOverlay(that.label1); border: "0",
topMapOne({ companyId: item.companyId, companyName: item.companyName }).then(res => { color: "rgba(0, 0, 0, 0)",
that.label1 = new BMap.Label(); fontSize: "16px",
that.label1.setStyle({ });
color: 'blue', map.addOverlay(label);
borderRadius: '5px', label.addEventListener("click", function () {
borderColor: '#ccc', map.removeOverlay(that.label1);
padding: '10px', topMapOne({
fontSize: '16px', companyId: item.companyId,
fontFamily: '微软雅黑', companyName: item.companyName,
transform: 'translateX(-50%) translateY(calc(-100% - 10px))' }).then((res) => {
}); that.label1 = new BMap.Label();
that.label1.setStyle({
color: "blue",
borderRadius: "5px",
borderColor: "#ccc",
padding: "10px",
fontSize: "16px",
fontFamily: "微软雅黑",
transform: "translateX(-50%) translateY(calc(-100% - 10px))",
});
that.label1.setPosition(new BMap.Point(item.longitude, item.latitude)); that.label1.setPosition(
that.label1.setOffset(new BMap.Size(130, -10)) new BMap.Point(item.longitude, item.latitude)
that.label1.setStyle({ width: '372px', height: '242px', background: 'url(pbImg/bz49.png) no-repeat', backgroundSize: '100% 100%', border: '0', color: '#fff', padding: '13px 20px' }) );
that.label1.setContent(` that.label1.setOffset(new BMap.Size(130, -10));
that.label1.setStyle({
width: "372px",
height: "242px",
background: "url(pbImg/bz49.png) no-repeat",
backgroundSize: "100% 100%",
border: "0",
color: "#fff",
padding: "13px 20px",
});
that.label1.setContent(`
<div style='width:100%;display:flex;justify-content: space-between;align-items: center;border-bottom:1px solid #657E83;'> <h4 style='margin:12px;font-size: 14px;color: #EBFFF4;letter-spacing: 1px;line-height: 24px;text-shadow: 0 0 9px rgba(21,255,195,0.77);overflow: hidden;text-overflow: ellipsis;white-space: nowrap;'>${res.data.companyName}</h4><div class='closeBtn' style='font-size: 14px;color: #30C4FF;letter-spacing: 1px;font-weight: 400;'>企业看板<i style='display:inline-block; background: url(pbImg/跳转.png) no-repeat;width:16px;height:14px;background-size: 100% 100%;"'></i></div><div class='closeBtn1' style='background: url(pbImg/.png) no-repeat;width:20px;height:20px;background-size: 100% 100%;position:relative;z-index:200000000; <div style='width:100%;display:flex;justify-content: space-between;align-items: center;border-bottom:1px solid #657E83;'> <h4 style='margin:12px;font-size: 14px;color: #EBFFF4;letter-spacing: 1px;line-height: 24px;text-shadow: 0 0 9px rgba(21,255,195,0.77);overflow: hidden;text-overflow: ellipsis;white-space: nowrap;'>${res.data.companyName}</h4><div class='closeBtn' style='font-size: 14px;color: #30C4FF;letter-spacing: 1px;font-weight: 400;'>企业看板<i style='display:inline-block; background: url(pbImg/跳转.png) no-repeat;width:16px;height:14px;background-size: 100% 100%;"'></i></div><div class='closeBtn1' style='background: url(pbImg/.png) no-repeat;width:20px;height:20px;background-size: 100% 100%;position:relative;z-index:200000000;
margin-top:-15px;"'></div></div> margin-top:-15px;"'></div></div>
<div style='height:70px;width:100%;margin-top:15px;background: url(pbImg/编组.png);display:flex;justify-content: space-around;align-items: center;'> <div style='height:70px;width:100%;margin-top:15px;background: url(pbImg/编组.png);display:flex;justify-content: space-around;align-items: center;'>
@ -244,78 +264,75 @@ export default {
</div> </div>
</div> </div>
`); `);
map.addOverlay(that.label1); map.addOverlay(that.label1);
let closebtn = document.querySelector('.closeBtn') let closebtn = document.querySelector(".closeBtn");
let closeBtn1 = document.querySelector('.closeBtn1') let closeBtn1 = document.querySelector(".closeBtn1");
closeBtn1.addEventListener('click', () => { closeBtn1.addEventListener("click", () => {
map.removeOverlay(that.label1);
map.removeOverlay(that.label1);
})
//console.log(btn, 'btn');
closebtn.addEventListener('click', () => {
that.$emit('toArchives', item)
map.removeOverlay(that.label1);
})
})
});
})
polygon.removeEventListener('mousemove')
}); });
//console.log(btn, 'btn');
} closebtn.addEventListener("click", () => {
function showPoint() { that.$emit("toArchives", item);
console.log(MapPoint, 'MapPoint'); map.removeOverlay(that.label1);
});
for (let i = 0; i < MapPoint.features.length; i++) { });
var opts = { });
position: new BMap.Point(MapPoint.features[i].geometry.coordinates[0], MapPoint.features[i].geometry.coordinates[1]), // });
offset: new BMap.Size(-30, -30) // polygon.removeEventListener("mousemove");
}; });
}
// function showPoint() {
var label1 = new BMap.Label(MapPoint.features[i].properties.name, opts); console.log(MapPoint, "MapPoint");
// for (let i = 0; i < MapPoint.features.length; i++) {
label1.setStyle({ var opts = {
color: 'orange', position: new BMap.Point(
borderRadius: '5px', MapPoint.features[i].geometry.coordinates[0],
borderColor: '#ccc', MapPoint.features[i].geometry.coordinates[1]
padding: '10px', ), //
fontSize: '16px', offset: new BMap.Size(-30, -30), //
height: '20px', };
lineHeight: '20px', //
backgroundColor: 'rgba(0,0,0,0)', var label1 = new BMap.Label(
border: '0', MapPoint.features[i].properties.name,
fontFamily: '微软雅黑' opts
}); );
map.addOverlay(label1); //
} label1.setStyle({
} color: "orange",
borderRadius: "5px",
}, borderColor: "#ccc",
} padding: "10px",
} fontSize: "16px",
height: "20px",
lineHeight: "20px",
backgroundColor: "rgba(0,0,0,0)",
border: "0",
fontFamily: "微软雅黑",
});
map.addOverlay(label1);
}
}
},
},
};
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.bmap { .bmap {
width: 100%; width: 100%;
height: 100%; height: 100%;
border: 1px solid #000000; border: 1px solid #000000;
} }
.fanhui { .fanhui {
display: inline-block; display: inline-block;
width: 50px; width: 50px;
height: 20px; height: 20px;
position: absolute; position: absolute;
left: 49%; left: 49%;
bottom: 30px; bottom: 30px;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
z-index: 50; z-index: 50;
} }
</style> </style>

@ -165,7 +165,7 @@ export default {
label.setStyle({ label.setStyle({
backgroundColor: " rgba(0, 0, 0, 0)", backgroundColor: " rgba(0, 0, 0, 0)",
border: "0", border: "0",
color: "#0060ce", color: "rgba(0, 0, 0, 0)",
fontSize: "16px", fontSize: "16px",
}); });
map.addOverlay(label); map.addOverlay(label);

@ -149,7 +149,7 @@ export default {
label.setStyle({ label.setStyle({
backgroundColor: " rgba(0, 0, 0, 0)", backgroundColor: " rgba(0, 0, 0, 0)",
border: "0", border: "0",
color: "#0060ce", color: "rgba(0, 0, 0, 0)",
fontSize: "16px", fontSize: "16px",
}); });
map.addOverlay(label); map.addOverlay(label);

Loading…
Cancel
Save