Leaflet openOn(地图)仅在firefox中有效,在chrome或edge中无效

Leaflet openOn(地图)仅在firefox中有效,在chrome或edge中无效,leaflet,popup,leaflet.draw,Leaflet,Popup,Leaflet.draw,tl;dr popup.openOn(map)仅适用于firefox,不适用于chrome或edge。标记上的弹出窗口可以完美地工作 冗长版本: 我有点滥用传单。画图让用户插入图像覆盖。我让用户画一个矩形,抓住相关的角点,然后用它来放置图像覆盖。图像本身由用户通过一些表单字段上传。这些都显示在我在绘制的矩形中心位置打开的弹出窗口中。代码如下所示,最重要的部分是最后一行: map.on('draw:created', function (event) { if (event.la

tl;dr

popup.openOn(map)
仅适用于firefox,不适用于chrome或edge。标记上的弹出窗口可以完美地工作

冗长版本:

我有点滥用传单。画图让用户插入图像覆盖。我让用户画一个矩形,抓住相关的角点,然后用它来放置图像覆盖。图像本身由用户通过一些表单字段上传。这些都显示在我在绘制的矩形中心位置打开的弹出窗口中。代码如下所示,最重要的部分是最后一行:

 map.on('draw:created', function (event) {
        if (event.layerType === 'rectangle') {
            insertImage(event);
        }
}

function insertImage(event){
    layer = event.layer,
    feature = layer.feature = layer.feature || {};              // Intialize layer.feature
    feature.type = feature.type || "Feature";                   // Intialize feature.type
    props = feature.properties = feature.properties || {};      // Intialize feature.properties
    props.imageURL = "";                                        // Define the necessary feature properities -> imageURL and zoomLevels
    props.zoomLevel = minZoom+1;                                
    props.endZoomLevel = maxZoom;                               
    var editablePopup = L.responsivePopup({maxWidth: "auto"});  // create the popup and afterward the content for it
    imageBounds = layer.getBounds();                            // get the bounding box of the rectangle aka its NE and SW corner
    content = imageForm("", props.zoomLevel, props.endZoomLevel, imageBounds, "create"); //create the form in the popup
    editablePopup.setContent(content);                          // add the content to the popup
    event.layer.addTo(map);                                     //we need to add the event layer to the map in order be use the getCenter method to place the popup                 
    editablePopup.setLatLng(event.layer.getCenter());           //the popup will open at the center of the drawn rectangle
    map.removeLayer(event.layer);                               //now we can get rid of the layer and remove it from the map
    editablePopup.openOn(map);                                  //open the popup
};
它在Firefox中工作得非常好,但在Chrome或Edge中不会打开弹出窗口,控制台中也不会显示错误或警告

注意事项:

  • 我确实使用了responsivePopup插件,但已经用常规的L.popup进行了测试,得到了 同样的结果
  • 标记上的弹出窗口在所有浏览器中都可以正常工作
  • 如果我将最后一行替换为
    layer.bindpoop(editablePopup)它停止一起工作,即使在Firefox中也是如此

请分享一个工作演示(JSFIDLE)。它在Chrome和Firefox中对我有效如果这对你有效,那么by代码中还有其他东西破坏了它。不幸的是,整个js相当长(接近900行),我不知道如何将其分解为JSFIDLE或codesandbox。您可以看到它的实时运行:只需在这里登录:使用用户“test”和pw“test”,然后单击testmap旁边的小编辑(铅笔)图标。您将在左上角的控件中看到矩形按钮。抱歉,Chrome和Edge上也会打开弹出窗口:/尝试清除缓存。F12(打开控制台),然后在“重新加载”按钮(搜索栏左侧)上单击鼠标右键,然后单击最后一个操作。奇怪的是,它对您有效。我已经清除了缓存十几次了,但没有任何改变。即使我尝试不同的计算机,它也不能与这些浏览器一起工作。非常好奇,我不知道如何调试它。请分享一个工作演示(JSFIDLE)。它在Chrome和Firefox中对我有效如果这对你有效,那么by代码中还有其他东西破坏了它。不幸的是,整个js相当长(接近900行),我不知道如何将其分解为JSFIDLE或codesandbox。您可以看到它的实时运行:只需在这里登录:使用用户“test”和pw“test”,然后单击testmap旁边的小编辑(铅笔)图标。您将在左上角的控件中看到矩形按钮。抱歉,Chrome和Edge上也会打开弹出窗口:/尝试清除缓存。F12(打开控制台),然后在“重新加载”按钮(搜索栏左侧)上单击鼠标右键,然后单击最后一个操作。奇怪的是,它对您有效。我已经清除了缓存十几次了,但没有任何改变。即使我尝试不同的计算机,它也不能与这些浏览器一起工作。非常好奇,我不知道如何调试这个。