zqq:遥感影像页绘制矩形

This commit is contained in:
qqGroup0 2023-04-25 10:14:11 +08:00
parent 5f025a2c8e
commit c587d3218a
1 changed files with 50 additions and 33 deletions

View File

@ -21,6 +21,8 @@ const map = ref()
let homeMap = null
let featureLayerG_area = null
let featureLayerG_point = null
let layerRectangle = null
onMounted(() => {
homeMap = L.map(map.value, {
@ -59,28 +61,28 @@ const mapOperations = {
let layer = omnivore.wkt.parse(res)
layer.addTo(featureLayerG_point)
let attr=Object.values(layer._layers)
let attr = Object.values(layer._layers)
// flyTo
if(attr[0].feature.geometry.type.indexOf('Polygon')==-1){
homeMap.flyTo([attr[0].feature.geometry.coordinates[1],attr[0].feature.geometry.coordinates[0]],3)
if (attr[0].feature.geometry.type.indexOf('Polygon') == -1) {
homeMap.flyTo([attr[0].feature.geometry.coordinates[1], attr[0].feature.geometry.coordinates[0]], 3)
}
// fly
else{
let polygons=[];
for(let i=0;i<attr[0].feature.geometry.coordinates.length;i++){
else {
let polygons = [];
for (let i = 0; i < attr[0].feature.geometry.coordinates.length; i++) {
console.log(attr[0].feature.geometry.coordinates[i])
polygons.push(turf.polygon([attr[0].feature.geometry.coordinates[i]]));
}
let centers = polygons.map(polygon => turf.centroid(polygon));
// console.log(centers)
let features=[]
for(let i=0;i<centers.length;i++){
let features = []
for (let i = 0; i < centers.length; i++) {
features.push(turf.point(centers[i].geometry.coordinates))
}
let final_center=turf.center(turf.featureCollection(features))
let final_center = turf.center(turf.featureCollection(features))
// console.log(final_center)
homeMap.flyTo([final_center.geometry.coordinates[1],final_center.geometry.coordinates[0]],3)
homeMap.flyTo([final_center.geometry.coordinates[1], final_center.geometry.coordinates[0]], 3)
}
return layer
@ -301,16 +303,16 @@ const mapOperations = {
// console.log('2-2')
variableStore.layerGroupPoint = null
featureLayerG_point.clearLayers()
homeMap.pm.enableDraw('Polygon',{ snappable: false });
let polygon=null;
homeMap.on("pm:create",(e)=>{
homeMap.pm.enableDraw('Polygon', { snappable: false });
let polygon = null;
homeMap.on("pm:create", (e) => {
featureLayerG_area.clearLayers()
e.layer.setStyle({
color: '#FF0080',
opacity: 1,
})
e.layer.addTo(featureLayerG_area)
polygon=e.layer
polygon = e.layer
})
// featureLayerG_area.clearLayers()
// variableStore.layerGroupPoly=null;
@ -349,7 +351,7 @@ const mapOperations = {
homeMap.pm.enableGlobalEditMode({
allowSelfIntersection: false,
})
if(featureLayerG_area.getLayers().length==1){
if (featureLayerG_area.getLayers().length == 1) {
featureLayerG_area.eachLayer(function (layer) {
layer.on('pm:edit', (e) => {
let features = featureLayerG_area.toGeoJSON().features
@ -360,7 +362,7 @@ const mapOperations = {
});
});
}
else if(featureLayerG_point.getLayers().length==1){
else if (featureLayerG_point.getLayers().length == 1) {
featureLayerG_point.eachLayer(function (layer) {
layer.on('pm:edit', (e) => {
let features = featureLayerG_point.toGeoJSON().features
@ -371,12 +373,27 @@ const mapOperations = {
});
});
}
else{
else {
console.log('error')
}
},
drawRectangle: () => {
if (layerRectangle != null) {
homeMap.removeLayer(layerRectangle)
layerRectangle = null
}
homeMap.pm.enableDraw('Rectangle', {
snappable: true,
snapDistance: 20,
});
homeMap.on('pm:create', (e) => {
L.PM.reInitLayer(e.layer);
layerRectangle = e.layer
});
},
deleteRectangle: () => {
homeMap.removeLayer(layerRectangle)
}
}
//omnivore.wkt.parse('POINT(-80 0)').addTo(homeMap);