Commit 3fec8dad authored by 黄奎's avatar 黄奎
parents c2d8576a d72cec04
...@@ -241,7 +241,7 @@ export default { ...@@ -241,7 +241,7 @@ export default {
this.TripMapList.push(JSON.parse(JSON.stringify(obj))); this.TripMapList.push(JSON.parse(JSON.stringify(obj)));
} }
console.log(this.TripMapList, "----TripMapList"); // console.log(this.TripMapList, "----TripMapList");
}, },
deep: true, deep: true,
immediate: true immediate: true
...@@ -249,6 +249,7 @@ export default { ...@@ -249,6 +249,7 @@ export default {
}, },
computed: {}, computed: {},
mounted() { mounted() {
// 日本随机背景色
this.setPaintRbBgList() this.setPaintRbBgList()
this.initMap(); this.initMap();
}, },
...@@ -309,6 +310,7 @@ export default { ...@@ -309,6 +310,7 @@ export default {
this.TripMapList.forEach(x => { this.TripMapList.forEach(x => {
let obj = { let obj = {
MName: x.MName, MName: x.MName,
name: x.MName,
MId: x.MId, MId: x.MId,
ColorStr: x.ColorStr, ColorStr: x.ColorStr,
Lng: x.Lng, Lng: x.Lng,
...@@ -366,7 +368,6 @@ export default { ...@@ -366,7 +368,6 @@ export default {
this.SearchCity(x.MId); this.SearchCity(x.MId);
} }
}); });
console.log(this.countriesData,'------=====')
}, },
// 清除已有源 // 清除已有源
ClearSource(Id,type){ ClearSource(Id,type){
...@@ -410,9 +411,11 @@ export default { ...@@ -410,9 +411,11 @@ export default {
bounds.extend([city.longitude, city.latitude]); bounds.extend([city.longitude, city.latitude]);
}); });
this.map.fitBounds(bounds,{ this.map.fitBounds(bounds,{
padding: 150, // 可选:在地图边界周围添加一些内边距 padding: 150, // 可选:在地图边界周围添加一些内边距
}); });
// this.map.setCenter(bounds.getCenter()); if(this.countriesData&&this.countriesData.length>0&&this.countriesData.length==1){
this.map.setCenter(bounds.getCenter());
}
this.addMarker(); //标记 this.addMarker(); //标记
this.createLineHandler(); //连线 this.createLineHandler(); //连线
await this.addCountriesMaker(); //标记国家 await this.addCountriesMaker(); //标记国家
...@@ -429,12 +432,12 @@ export default { ...@@ -429,12 +432,12 @@ export default {
} }
}); });
}); });
this.countriesData.forEach(y => { // this.countriesData.forEach(y => {
if (x.MName == y.name) { // if (x.MName == y.name) {
x.Lng = y.Lng; // x.Lng = y.Lng;
x.Lat = y.Lat; // x.Lat = y.Lat;
} // }
}); // });
}); });
this.dataAll.TripMapList = JSON.parse(JSON.stringify(this.TripMapList)); this.dataAll.TripMapList = JSON.parse(JSON.stringify(this.TripMapList));
}, },
...@@ -625,8 +628,8 @@ export default { ...@@ -625,8 +628,8 @@ export default {
addCountryFillRange() { addCountryFillRange() {
let that = this let that = this
this.countriesData.forEach((x, i) => { this.countriesData.forEach((x, i) => {
if (x.MName == "中国") x.MName = "中华人民共和国"; if (x.MName == "中国") x.name = "中华人民共和国";
if (x.MName == "韩国") x.MName = "大韩民国"; if (x.MName == "韩国") x.name = "大韩民国";
x.CityListAll.forEach(y=>{ x.CityListAll.forEach(y=>{
}) })
...@@ -653,7 +656,7 @@ export default { ...@@ -653,7 +656,7 @@ export default {
id: "world-layer-" + x.MId, id: "world-layer-" + x.MId,
type: "fill", type: "fill",
source: source, source: source,
filter: ["==", "NAME_ZH", x.MName] filter: ["==", "NAME_ZH", x.name]
}); });
if(x.MId!=651&&x.MId!=891) { if(x.MId!=651&&x.MId!=891) {
that.ClearSource("mapLayer-" + x.MId,1) that.ClearSource("mapLayer-" + x.MId,1)
...@@ -661,7 +664,7 @@ export default { ...@@ -661,7 +664,7 @@ export default {
this.map.setPaintProperty("world-layer-" + x.MId, "fill-color",[ this.map.setPaintProperty("world-layer-" + x.MId, "fill-color",[
"match", "match",
["get", "NAME_ZH"], ["get", "NAME_ZH"],
x.MName, x.name,
x.ColorStr, // 选定的国家颜色 x.ColorStr, // 选定的国家颜色
["rgba", 0, 122, 255, 0] ["rgba", 0, 122, 255, 0]
]); ]);
...@@ -671,7 +674,7 @@ export default { ...@@ -671,7 +674,7 @@ export default {
id: "mapLayer-"+ x.MId, id: "mapLayer-"+ x.MId,
type: "fill", type: "fill",
source: source, source: source,
filter: ["==", "NAME_ZH", x.MName], filter: ["==", "NAME_ZH", x.name],
}); });
this.map.addLayer({ this.map.addLayer({
id: "mapLayerId-"+ x.MId, id: "mapLayerId-"+ x.MId,
...@@ -890,37 +893,36 @@ export default { ...@@ -890,37 +893,36 @@ export default {
} }
}, },
async addCountriesMaker() { async addCountriesMaker() {
console.log(this.countriesData,'-----------1111')
let that = this; let that = this;
await Promise.all( await Promise.all(
this.countriesData.map(async (x, i) => { this.countriesData.map(async (x, i) => {
let result; let result;
if (x.Lng && x.Lat) { if (x.Lng && x.Lat) {
// console.log(x.Lng, "====");
result = [x.Lng, x.Lat]; result = [x.Lng, x.Lat];
} else { } else {
// console.log(x.Lng, "22222===="); result = await this.getCountryCoordinates(x.name);
result = await this.getCountryCoordinates(x.MName);
} }
if (result && result.length == 2) { if (result && result.length == 2) {
let el = document.createElement("div"); let el = document.createElement("div");
el.style.fontSize = "30px"; el.style.fontSize = "30px";
el.style.fontWeight = "bold"; el.style.fontWeight = "bold";
el.style.color = "rgba(0,0,0,0.4)"; el.style.color = "rgba(0,0,0,0.4)";
el.innerHTML = x.MName; el.innerHTML = x.name;
var marker = new mapboxgl.Marker(el, { var marker = new mapboxgl.Marker(el, {
offset: [0, 0], offset: [0, 0],
draggable: true draggable: true
}); });
marker.setLngLat(result); marker.setLngLat(result);
marker.addTo(this.map); marker.addTo(this.map);
let currentMarkerLngLat = marker.getLngLat();
let TripMapList = that.TripMapList.filter(y=> y.MName==x.MName)
TripMapList[0].Lng = currentMarkerLngLat.lng;
TripMapList[0].Lat = currentMarkerLngLat.lat;
marker.on("dragend", function() { marker.on("dragend", function() {
let currentMarkerLngLat = marker.getLngLat(); currentMarkerLngLat = marker.getLngLat();
x.Lng = currentMarkerLngLat.lng; TripMapList = that.TripMapList.filter(y=> y.MName==x.MName)
x.Lat = currentMarkerLngLat.lat; TripMapList[0].Lng = currentMarkerLngLat.lng;
console.log(x.MName,'=====') TripMapList[0].Lat = currentMarkerLngLat.lat;
let TripMapList = that.TripMapList.filter(y=>y.MName==x.MName)
console.log(TripMapList,'--------')
}); });
this.countriesMarkers.push(marker); this.countriesMarkers.push(marker);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment