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

popup.openOnmap仅适用于Firefox,不适用于chrome或edge

如何解决popup.openOnmap仅适用于Firefox,不适用于chrome或edge

tl; dr

display: flex;仅适用于Firefox,不适用于chrome或edge。标记上的弹出窗口可以正常工作。

长版本:

我有点在滥用leaflet.draw来让用户插入图像叠加层。我通过让用户绘制一个矩形,抓住相关的角并使用它来放置图像叠加层来实现此目的。图像本身由用户通过一些表单字段上载。这些显示在我在绘制矩形的中心位置打开的弹出窗口中。代码如下所示,重要的部分是最后一行:

popup.openOn(map)

它在Firefox中运行良好,但是在Chrome或Edge中没有打开任何弹出窗口,并且控制台中未显示任何错误或警告。

注释:

  • 我确实使用了responsePopup插件,但已经使用常规L.popup对其进行了测试,并获得了 结果相同。
  • 标记的弹出窗口在所有浏览器中均可正常运行。
  • 如果我用 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中,它也无法一起工作。

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