Commit be02ae86 authored by youjie's avatar youjie

no message

parent 3fec8dad
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
</el-option> </el-option>
</el-select> </el-select>
<el-color-picker <el-color-picker
v-if="x.MId!=651&&x.MId!=891"
style="vertical-align: middle;" style="vertical-align: middle;"
v-model="x.ColorStr" v-model="x.ColorStr"
@change="getColorStr" @change="getColorStr"
...@@ -64,13 +65,13 @@ ...@@ -64,13 +65,13 @@
<div> <div>
<span class="MapImgButtom CancelMapImg" @click="Cancel">取消</span> <span class="MapImgButtom CancelMapImg" @click="Cancel">取消</span>
</div> </div>
<div style="margin-left: 20px;"> <!-- <div style="margin-left: 20px;">
<span <span
class="MapImgButtom setMapImg" class="MapImgButtom setMapImg"
@click="SavePositionStr" @click="SavePositionStr"
>保存坐标</span >保存坐标</span
> >
</div> </div> -->
<div style="margin-left: 20px;"> <div style="margin-left: 20px;">
<span <span
class="MapImgButtom setMapImg" class="MapImgButtom setMapImg"
...@@ -241,7 +242,7 @@ export default { ...@@ -241,7 +242,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
...@@ -263,7 +264,7 @@ export default { ...@@ -263,7 +264,7 @@ export default {
zoom: 6, zoom: 6,
preserveDrawingBuffer: true preserveDrawingBuffer: true
}); });
this.map.on("load", async () => { this.map.on("style.load", async () => {
this.map.addSource("word-source", { this.map.addSource("word-source", {
type: "geojson", type: "geojson",
data: worldGeoJSON, data: worldGeoJSON,
...@@ -300,6 +301,35 @@ export default { ...@@ -300,6 +301,35 @@ export default {
this.drawMap(2); this.drawMap(2);
} }
}, },
// 绘制地图
async drawMap(type) {
console.log(type, "1初始化---- 2数据更新");
// 显示国家
this.addCountryFillRange();
// 获取坐标信息
await this.calcCitiesGeoInfoHandler();
// 可见范围
const bounds = new mapboxgl.LngLatBounds();
this.citiesData.forEach(city => {
bounds.extend([city.longitude, city.latitude]);
});
this.map.fitBounds(bounds,{
padding: 150, // 可选:在地图边界周围添加一些内边距
});
if(this.countriesData&&this.countriesData.length>0&&this.countriesData.length==1){
this.map.setCenter(bounds.getCenter());
}
// 更新数据时再标记
if(type==2){
this.addMarker(); //标记
}
this.createLineHandler(); //连线
await this.addCountriesMaker(); //标记国家
//this.addDocumentEventListener();
},
// 组装数据 // 组装数据
UpdateDatas(){ UpdateDatas(){
let listCity = []; let listCity = [];
...@@ -337,6 +367,8 @@ export default { ...@@ -337,6 +367,8 @@ export default {
this.citys = this.citys.filter( this.citys = this.citys.filter(
x => this.citiesData.findIndex(y => y.name == x) == -1 x => this.citiesData.findIndex(y => y.name == x) == -1
); );
// console.log(this.citys,'-----222')
// console.log(this.citiesData,'-----111')
this.countries = [...new Set(listCountries)]; this.countries = [...new Set(listCountries)];
this.clearCountriesMaker(); this.clearCountriesMaker();
...@@ -372,7 +404,7 @@ export default { ...@@ -372,7 +404,7 @@ export default {
// 清除已有源 // 清除已有源
ClearSource(Id,type){ ClearSource(Id,type){
if(type){ if(type){
if(this.map.getLayer(Id)) { if(this.map&&this.map.getLayer(Id)) {
this.map.removeLayer(Id); this.map.removeLayer(Id);
if(type==2) this.map.removeSource(Id); if(type==2) this.map.removeSource(Id);
} }
...@@ -397,30 +429,6 @@ export default { ...@@ -397,30 +429,6 @@ export default {
} }
}, },
// 绘制地图
async drawMap(type) {
console.log(type, "1初始化---- 2数据更新");
// 显示国家
this.addCountryFillRange();
// 获取坐标信息
await this.calcCitiesGeoInfoHandler();
// 可见范围
const bounds = new mapboxgl.LngLatBounds();
this.citiesData.forEach(city => {
bounds.extend([city.longitude, city.latitude]);
});
this.map.fitBounds(bounds,{
padding: 150, // 可选:在地图边界周围添加一些内边距
});
if(this.countriesData&&this.countriesData.length>0&&this.countriesData.length==1){
this.map.setCenter(bounds.getCenter());
}
this.addMarker(); //标记
this.createLineHandler(); //连线
await this.addCountriesMaker(); //标记国家
//this.addDocumentEventListener();
},
// 保存标记坐标 // 保存标记坐标
SavePositionStr() { SavePositionStr() {
this.TripMapList.forEach(x => { this.TripMapList.forEach(x => {
...@@ -652,7 +660,7 @@ export default { ...@@ -652,7 +660,7 @@ export default {
paintBgObj = that.paintHgBgObj paintBgObj = that.paintHgBgObj
} }
} }
this.map.addLayer({ this.map&&this.map.addLayer({
id: "world-layer-" + x.MId, id: "world-layer-" + x.MId,
type: "fill", type: "fill",
source: source, source: source,
...@@ -661,7 +669,7 @@ export default { ...@@ -661,7 +669,7 @@ export default {
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)
that.ClearSource("mapLayerId-" + x.MId,1) that.ClearSource("mapLayerId-" + x.MId,1)
this.map.setPaintProperty("world-layer-" + x.MId, "fill-color",[ this.map&&this.map.setPaintProperty("world-layer-" + x.MId, "fill-color",[
"match", "match",
["get", "NAME_ZH"], ["get", "NAME_ZH"],
x.name, x.name,
...@@ -670,13 +678,13 @@ export default { ...@@ -670,13 +678,13 @@ export default {
]); ]);
}else { }else {
that.ClearSource("world-layer-" + x.MId,1) that.ClearSource("world-layer-" + x.MId,1)
this.map.addLayer({ this.map&&this.map.addLayer({
id: "mapLayer-"+ x.MId, id: "mapLayer-"+ x.MId,
type: "fill", type: "fill",
source: source, source: source,
filter: ["==", "NAME_ZH", x.name], filter: ["==", "NAME_ZH", x.name],
}); });
this.map.addLayer({ this.map&&this.map.addLayer({
id: "mapLayerId-"+ x.MId, id: "mapLayerId-"+ x.MId,
type: "fill", type: "fill",
source: source, source: source,
...@@ -686,6 +694,29 @@ export default { ...@@ -686,6 +694,29 @@ export default {
}); });
}, },
// 编辑国家和城市
async EditCountryCity(end){
const query = await fetch(
`https://api.mapbox.com/directions/v5/mapbox/cycling/${start[0]},${start[1]};${end[0]},${end[1]}?steps=true&geometries=geojson&access_token=${mapboxgl.accessToken}`,
{ method: 'GET' }
);
const json = await query.json();
const data = json.routes[0];
const route = data.geometry.coordinates;
const geojson = {
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: route
}
};
this.countriesData.forEach((x, i) => {
if (this.map.getSource('world-layer-'+x.MId)) {
this.map.getSource('route').setData(geojson);
}
})
},
clearCitiesMarkersHandler() { clearCitiesMarkersHandler() {
if (this.deviceMarkers && this.deviceMarkers.length > 0) { if (this.deviceMarkers && this.deviceMarkers.length > 0) {
this.deviceMarkers.forEach(x => { this.deviceMarkers.forEach(x => {
...@@ -696,17 +727,16 @@ export default { ...@@ -696,17 +727,16 @@ export default {
}, },
addMarker() { addMarker() {
// let markerColor = calculateComplementaryColor("#71adeb"); // let markerColor = calculateComplementaryColor("#71adeb");
// console.log(this.citiesData,'----00')
this.citiesData.forEach((item, i) => { this.citiesData.forEach((item, i) => {
var marker = new mapboxgl.Marker({ color: "#d73b33", scale: 0.5 }) var marker = new mapboxgl.Marker({ color: "#d73b33", scale: 0.5 })
.setLngLat([item.longitude, item.latitude]) .setLngLat([item.longitude, item.latitude])
.addTo(this.map); .addTo(this.map);
console.log(item.Lng,'=====')
if (item.Lng && item.Lat) { if (item.Lng && item.Lat) {
this.addLabel(item, i, item); this.addLabel(item, i, item);
} else { } else {
this.addLabel(item, i); this.addLabel(item, i);
} }
this.deviceMarkers.push(marker); this.deviceMarkers.push(marker);
}); });
}, },
...@@ -729,6 +759,7 @@ export default { ...@@ -729,6 +759,7 @@ export default {
let currentMarkerLngLat = marker.getLngLat(); let currentMarkerLngLat = marker.getLngLat();
that.citiesData[i].Lng = currentMarkerLngLat.lng; that.citiesData[i].Lng = currentMarkerLngLat.lng;
that.citiesData[i].Lat = currentMarkerLngLat.lat; that.citiesData[i].Lat = currentMarkerLngLat.lat;
that.SavePositionStr()
}); });
this.deviceMarkers.push(marker); this.deviceMarkers.push(marker);
...@@ -746,7 +777,8 @@ export default { ...@@ -746,7 +777,8 @@ export default {
const data = await response.json(); const data = await response.json();
if (data.features.length > 0) { if (data.features.length > 0) {
const [longitude, latitude] = data.features[0].center; const [longitude, latitude] = data.features[0].center;
this.citiesData.push({ let tempI = this.citiesData.findIndex(y=>y.name==cityName)
if(tempI==-1) this.citiesData.push({
name: cityName, name: cityName,
longitude, longitude,
latitude, latitude,
...@@ -771,6 +803,7 @@ export default { ...@@ -771,6 +803,7 @@ export default {
}, },
createLineHandler() { createLineHandler() {
// let poilines = this.pois.split(","); // let poilines = this.pois.split(",");
let that = this
this.listCity.forEach((p, i) => { this.listCity.forEach((p, i) => {
if (i < this.listCity.length - 1) { if (i < this.listCity.length - 1) {
let x = this.citiesData.find(x => x.name == p.MName); let x = this.citiesData.find(x => x.name == p.MName);
...@@ -794,11 +827,11 @@ export default { ...@@ -794,11 +827,11 @@ export default {
} }
] ]
}; };
this.map.addSource("curve-source-" + p.MId, { that.map&&that.map.addSource("curve-source-" + p.MId, {
type: "geojson", type: "geojson",
data: geojson data: geojson
}); });
this.map.addLayer({ that.map&&that.map.addLayer({
id: "curve-layer-" + p.MId, id: "curve-layer-" + p.MId,
type: "line", type: "line",
source: "curve-source-" + p.MId, source: "curve-source-" + p.MId,
...@@ -923,6 +956,7 @@ export default { ...@@ -923,6 +956,7 @@ export default {
TripMapList = that.TripMapList.filter(y=> y.MName==x.MName) TripMapList = that.TripMapList.filter(y=> y.MName==x.MName)
TripMapList[0].Lng = currentMarkerLngLat.lng; TripMapList[0].Lng = currentMarkerLngLat.lng;
TripMapList[0].Lat = currentMarkerLngLat.lat; TripMapList[0].Lat = currentMarkerLngLat.lat;
that.SavePositionStr()
}); });
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