微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

传单:在 ImageLayer 上绘制时未启用编辑按钮

如何解决传单:在 ImageLayer 上绘制时未启用编辑按钮

全部: 也许我没有以正确的方式这样做。 Leaflet draw 的工作方式是,只要您使用绘图控件(圆形、方形、多边形等)在地图上绘制某些内容删除/编辑按钮就会启用。在我的地图中,通过单击包含 Leaflet 地图的网页上的链接用户可以添加许多 imageOverlays,但是对于这种情况,假设用户单击并添加一个 imageOverlay。 imageOverlay 在地图上显示得很好。现在用户想要在地图上绘制一个形状——比如说一个圆圈。当用户单击绘图控件中的圆形图标并将其绘制在地图上时,删除/编辑按钮不会启用。我难住了。我怀疑这可能与图层/分层有关。如果地图上没有 imageLayers,我需要让删除/编辑按钮的行为像它一样。有人可以启发我吗?谢谢。

我的 React.js 代码将 imageLayers 添加到数组,然后将图像数组添加到 L.featureGroup。 绘制形状时,将图层类型添加到同一个 L.featureGroup 中。

我的代码

In React.js:

let myFeatureGroup = new L.FeatureGroup();
let imageLayersArray = [];

// My function to load imageLayers:
const applyLayer = (mapSubType) => {        

    const mapSubTypeCaps = mapSubType.toupperCase();

    let dlaBounds = null;

    const someOptions = {
        opacity: 0.3,interactive: true,bubblingMouseEvents: true,className: 'imageborder',zIndex: 5,mapsubtypelayer: mapSubType,// required in order to identify a layer upon removal
    };

    // The 8 PNG image coordinates:
    const ImageCoords = [
        [[-90,0],[0,90]],[[0,[90,[[-90,-90],0]],[[-180,[-90,[[90,[180,];

    let counter = 0;

    ImageCoords.map((coordEntry) => {
        counter++;
        const useThisURL = `https://dla-maps-storage.s3.amazonaws.com/DLAMAP${mapSubTypeCaps}${counter}.png`;

        // Need to flip the coordinates from lng/lat to lat/lng for leaflet:

        let arrayofcoordinates = [];
        const flippedarrayofcoordinates = [];
        arrayofcoordinates = coordEntry;

        arrayofcoordinates.map((pairofcoordinates) => {
            const workAry = [];
            // flip the coordinates from lng/lat config to lat/lng:
            workAry[0] = pairofcoordinates[1];
            workAry[1] = pairofcoordinates[0];
            flippedarrayofcoordinates.push(workAry);
        });

        dlaBounds = L.latLngBounds(flippedarrayofcoordinates);

        const anImage = L.imageOverlay(
            useThisURL,dlaBounds,someOptions,)

        // add the imagelayer to the imageLayersArray:
        // Somebody along the way recommended to do this
        imageLayersArray.push(anImage);

        anImage.on('click',(leafletEvent) => {
            handleImageClick(leafletEvent);
        });
    });

    myFeatureGroup = L.featureGroup(imageLayersArray).addTo(map);

};
    
// Draw Event Created:
map.on(L.Draw.Event.CREATED,(e) => {
    console.log('L.Draw.Event.CREATED start:: ');

    const { layer } = e;

    switch (e.layerType) { // types: polyline,polygon,rectangle
        case 'circle':
            // Call rest endpoint with lat/lng coordinates
            break;
        case 'marker':
            // Call rest endpoint with lat/lng coordinates
            break;
        case 'polyline':
            // Call rest endpoint with lat/lng coordinates
        break;
        default:
            // polyGON OR RECTANGLE DRAWN:
            // Call rest endpoint with lat/lng coordinates
        break;                  
}

    myFeatureGroup.addLayer(layer);

    console.log('L.Draw.Event.CREATED end:: ');
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。