使用开放图层图时如何指定形状的显示顺序

问题描述 投票:0回答:0

我创建了一张由不同形状(例如 2 个圆圈和一条线)组成的地图。该线连接 2 个圆的中心。即使我先添加线条,然后添加圆圈,线条总是会越过圆圈。

如何设置这些形状的显示顺序?

还有什么方法可以用圆和线作为组合单个形状来绘制单个形状?

function drawCircle(lon, lat) {
    var circleFeature = new ol.Feature({
        geometry: new ol.geom.Circle(
            ol.proj.fromLonLat([lon, lat]), // Center coordinate
            40000 // Radius in meters
        ),
    });
    circleFeature.setStyle(style1);
    featuresSource.addFeature(circleFeature);
}

// Function to draw a line between two points on the map
function drawLine(startLon, startLat, endLon, endLat) {
    const lineFeature = new ol.Feature({
        geometry: new ol.geom.LineString([
            ol.proj.fromLonLat([startLon, startLat]),
            ol.proj.fromLonLat([endLon, endLat]),
        ]),
    });
    lineFeature.setStyle(style);

    featuresSource.addFeature(lineFeature);
}

drawCircle(0, 0); // Draw a circle at (0, 0)
drawCircle(1, 1); // Draw another circle at (10, 10)

drawLine(0, 0, 1, 1);
map.addLayer(featuresLayer);
javascript dictionary openlayers openlayers-3 overlapping
© www.soinside.com 2019 - 2024. All rights reserved.