Leaflet openOn(地图)仅在firefox中有效,在chrome或edge中无效
tl;drLeaflet 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
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中也是如此