Commit 72a73d40 authored by youjie's avatar youjie

no message

parent 07d9efe7
......@@ -74,7 +74,7 @@
<div style="margin-left: 20px;">
<span
class="MapImgButtom setMapImg"
@click="(setLoading = true), getResultImg"
@click="(setLoading = true), getResultImg()"
>生成图片</span
>
</div>
......@@ -283,6 +283,107 @@ export default {
}
});
},
// 更新数据
async AssemblyData() {
this.ClearSource()//清除源
this.UpdateDatas()//组装数据
if (
this.TripMapList &&
this.TripMapList.length > 0 &&
this.TripMapList[0].MName &&
this.TripMapList[0].CityList.length > 0
) {
this.drawMap(2);
}
},
// 清除已有源
ClearSource(){
this.listCity.forEach((p, i) => {
if (this.map.getLayer("curve-layer-" + p.MId)) {
this.map.removeLayer("curve-layer-" + p.MId);
this.map.removeSource("curve-source-" + p.MId);
}
});
this.countriesData.forEach((x, i) => {
if (this.map && this.map.getLayer("world-layer-" + x.MId)) {
this.map.removeLayer("world-layer-" + x.MId);
}
if (this.map && this.map.getLayer("mapLayer-" + x.MId)) {
this.map.removeLayer("mapLayer-" + x.MId);
}
if (this.map && this.map.getLayer("mapLayerId-" + x.MId)) {
this.map.removeLayer("mapLayerId-" + x.MId);
}
});
},
// 组装数据
UpdateDatas(){
let listCity = [];
let listCountries = [];
this.listCity = [];
// this.countriesData = [];
this.pois = "";
this.TripMapList.forEach(x => {
let obj = {
MName: x.MName,
MId: x.MId,
ColorStr: x.ColorStr,
Lng: x.Lng,
Lat: x.Lat
};
listCountries.push(x.MName);
let tempI = this.countriesData.findIndex(y=>y.MName==x.MName)
if(tempI==-1)this.countriesData.push(obj);
x.CityList.forEach(y => {
listCity.push(y.MName);
this.listCity.push({
MName: y.MName,
MId: y.MId
});
});
});
this.pois = listCity.join(",");
this.citys = [...new Set(this.pois.split(","))];
this.clearCitiesMarkersHandler();
this.citiesData = this.citiesData.filter(
x => this.citys.indexOf(x.name) != -1
);
this.citys = this.citys.filter(
x => this.citiesData.findIndex(y => y.name == x) == -1
);
this.countries = [...new Set(listCountries)];
this.clearCountriesMaker();
this.countriesData = this.countriesData.filter(
x => this.countries.indexOf(x.MName) != -1
);
// this.countries = this.countries.filter(
// x => this.countriesData.findIndex(y => y.MName == x) == -1
// );
this.TripMapList.forEach(x => {
x.CityList.forEach(y => {
this.citiesData.forEach(z => {
if (y.MName == z.name && y.Lng) {
z.Lng = y.Lng;
z.Lat = y.Lat;
}
});
});
this.countriesData.forEach(y=>{
if(x.MName==y.MName){
y.Lng = x.Lng
y.Lat = x.Lat
}
})
if (x.MId) {
this.SearchCity(x.MId);
}
});
console.log(this.countriesData,'------=====')
},
// 绘制地图
async drawMap(type) {
console.log(type, "1初始化---- 2数据更新");
......@@ -359,91 +460,6 @@ export default {
Cancel() {
this.$emit("Cancel");
},
// 更新数据
async AssemblyData() {
this.listCity.forEach((p, i) => {
if (this.map.getLayer("curve-layer-" + p.MId)) {
this.map.removeLayer("curve-layer-" + p.MId);
this.map.removeSource("curve-source-" + p.MId);
}
});
this.countriesData.forEach((x, i) => {
if (this.map && this.map.getLayer("world-layer-" + x.MId)) {
this.map.removeLayer("world-layer-" + x.MId);
}
if (this.map && this.map.getLayer("mapLayer-" + x.MId)) {
this.map.removeLayer("mapLayer-" + x.MId);
}
if (this.map && this.map.getLayer("mapLayerId-" + x.MId)) {
this.map.removeLayer("mapLayerId-" + x.MId);
}
});
let listCity = [];
let listCountries = [];
this.listCity = [];
// this.countriesData = [];
this.pois = "";
this.TripMapList.forEach(x => {
let obj = {
MName: x.MName,
MId: x.MId,
ColorStr: x.ColorStr,
Lng: x.Lng,
Lat: x.Lat
};
listCountries.push(x.MName);
let tempI = this.countriesData.findIndex(y=>y.MName==x.MName)
if(tempI==-1)this.countriesData.push(obj);
x.CityList.forEach(y => {
listCity.push(y.MName);
this.listCity.push({
MName: y.MName,
MId: y.MId
});
});
});
this.pois = listCity.join(",");
this.citys = [...new Set(this.pois.split(","))];
this.clearCitiesMarkersHandler();
this.citiesData = this.citiesData.filter(
x => this.citys.indexOf(x.name) != -1
);
this.citys = this.citys.filter(
x => this.citiesData.findIndex(y => y.name == x) == -1
);
this.countries = [...new Set(listCountries)];
this.clearCountriesMaker();
this.countriesData = this.countriesData.filter(
x => this.countries.indexOf(x.MName) != -1
);
this.countries = this.countries.filter(
x => this.countriesData.findIndex(y => y.MName == x) == -1
);
this.TripMapList.forEach(x => {
x.CityList.forEach(y => {
this.citiesData.forEach(z => {
if (y.MName == z.name && y.Lng) {
z.Lng = y.Lng;
z.Lat = y.Lat;
}
});
});
if (x.MId) {
this.SearchCity(x.MId);
}
});
if (
this.TripMapList &&
this.TripMapList.length > 0 &&
this.TripMapList[0].MName &&
this.TripMapList[0].CityList.length > 0
) {
this.drawMap(2);
}
},
// 获取国家
async getAddress(Type) {
this.loading = true;
......@@ -854,18 +870,18 @@ export default {
}
},
async addCountriesMaker() {
console.log(this.countriesData,'-----------1111')
let that = this;
await Promise.all(
this.countriesData.map(async (x, i) => {
let result;
if (x.Lng && x.Lat) {
console.log(x, "====");
// console.log(x.Lng, "====");
result = [x.Lng, x.Lat];
} else {
console.log(x, "22222====");
// console.log(x.Lng, "22222====");
result = await this.getCountryCoordinates(x.MName);
}
console.log(result, "----------result");
if (result && result.length == 2) {
let el = document.createElement("div");
el.style.fontSize = "30px";
......@@ -880,8 +896,9 @@ export default {
marker.addTo(this.map);
marker.on("dragend", function() {
let currentMarkerLngLat = marker.getLngLat();
that.countriesData[i].Lng = currentMarkerLngLat.lng;
that.countriesData[i].Lat = currentMarkerLngLat.lat;
x.Lng = currentMarkerLngLat.lng;
x.Lat = currentMarkerLngLat.lat;
console.log(that.countriesData,'--------')
});
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