且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将现有的传单多边形添加到现有的传单图层

更新时间:2023-08-29 17:55:46

你必须将你的多边形添加到 featureGroup drawnItems !比方说,

You have to add your polygons to the featureGroup drawnItems ! Let's say,

    var polyLayers = dbArray;

是您的带有多边形的数据库数组.首先使用您绘制的项目创建一个特征组:

is your database array with polygons. First create a feature group with your drawn items:

    var drawnItems = new L.FeatureGroup();

并将其添加到地图中:

    map.addLayer(drawnItems);

然后你只需要从你的数据库中迭代你的多边形并将它们添加到drawedItems FeatureGroup:

Then you simply need to iterate over your polygons from your database and add them to the drawnItems FeatureGroup:

    for(layer of polyLayers) {
        drawnItems.addLayer(layer); 
    };

现在图层已添加到地图并可以编辑.

Now the layers are added to the map and editable.

这里有一个示例:

    var drawnItems = new L.FeatureGroup();
    map.addLayer(drawnItems);

    var polyLayers = [];

    var polygon1 = L.polygon([
        [51.509, -0.08],
        [51.503, -0.06],
        [51.51, -0.047]
    ]);
    polyLayers.push(polygon1)

    var polygon2 = L.polygon([
        [51.512642, -0.099993],
        [51.520387, -0.087633],
        [51.509116, -0.082483]
    ]);
    polyLayers.push(polygon2)

    // Add the layers to the drawnItems feature group 
    for(let layer of polyLayers) {
        drawnItems.addLayer(layer); 
    }