• OpenLayers中面拆分


    面拆分效果图

    绘制面
    结果
    使用turf进行处理
    方法参数说明:layer 图层对象,选中的图元feature,layerID 图层ID

    polygonFn(layer, features, layerID) {
        let self = this;
        let drawSourceVector = new VectorSource();
        self.drawFaceSplit = new Draw({
            source: drawSourceVector,
            type: "Polygon",
            style: new Style({
                image: new sCircle({
                    radius: 5,
                    fill: new Fill({
                        color: "#03a9f4",
                    }),
                }),
                stroke: new Stroke({
                    color: "#03a9f4",
                    width: 2,
                }),
                fill: new Fill({
                    color: "rgba(255, 255, 255, 0.7)",
                }),
            }),
        });
    
        window.map.addInteraction(self.drawFaceSplit);
    
        // 监听绘制结束事件
        self.drawFaceSplit.on("drawend", (evt) => {
            window.map.removeInteraction(self.drawFaceSplit);
            let splitResult = [];
    let featureGeoJson = JSON.parse(
        new GeoJSON().writeFeature(evtFeature)
    );
    let coorArr = [];
    for (let i = 0; i < featureGeoJson.geometry.coordinates[0].length; i++) {
        let coor = featureGeoJson.geometry.coordinates[0][i];
        coorArr.push(coor);
    }
    
    let polyDikuai = turf.polygon(this.coordinates);
    let polyDraw = turf.polygon([coorArr]);
    let intersection = turf.intersect(polyDikuai, polyDraw);
    let difference1 = turf.difference(polyDikuai, polyDraw);
    // 判断面是否包含面
    let contains = turf.booleanContains(polyDikuai, polyDraw);
    let intersectionArray = intersection.geometry ? intersection.geometry.coordinates : [];
    let differenceArray = difference1.geometry ? difference1.geometry.coordinates : [];
    splitResult.push(intersectionArray);
    if (differenceArray && differenceArray.length > 1 && !contains) {
        for (let item of differenceArray) {
            splitResult.push(item);
        }
    }
    else {
        splitResult.push(differenceArray);
    }
    
    if (intersection && splitResult.length > 0) {
        for (let item in splitResult) {
            let polygonResult = new Polygon(splitResult[item]);
            let featureResult = new Feature(polygonResult);
            let Area = getPolygonArea(featureResult);
            let length = getPolygonLength(featureResult);
            let name =
                features.get("region_name") === undefined
                    ? ("采集地块-" + Area)
                    : features.get("region_name");
            featureResult.set("Area", Area);
            featureResult.set("Length", length);
            featureResult.set("region_name", name);
    
            if (layer) {
                layer.getSource().addFeature(featureResult);
            }
        }
    
        try {
            setTimeout(() => {
                layer.getSource().removeFeature(features);
            }, 100);
        }
        catch (e) {
            console.warn(e);
        }
    }
        })
    },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
  • 相关阅读:
    电力系统机组组合优化调度(IEEE14节点、IEEE30节点、IEEE118节点)(Matlab代码实现)
    数据结构篇_编程思想板块_第一章顺序表和链表
    【C++】setjmp,longjmp的详细使用说明
    KubeSphere 社区双周报 | 2022-09-02
    MySQL库的操作
    EF7学习指南
    2023年电赛---运动目标控制与自动追踪系统(E题)OpenART mini的代码移植到OpenMV
    java-php-python-红河旅游信息服务系统计算机毕业设计
    强化学习到底是什么?它是怎么运维的
    CMMI2.0和1.3之间的区别有哪些?
  • 原文地址:https://blog.csdn.net/weixin_40187450/article/details/126105152