javascript - Bing map 绘图工具模块 - 事件

标签 javascript bing-maps

我正在使用 Bing Map Ajax Control V7 进行测试/学习。 我用信息框创建了一些图钉,并添加了事件:

function InsertEvent(mark, infoBox)
      {
        var obj = {marker : {}, infoWind : {}};
        obj.marker.entity = mark;  
        obj.marker.eID = Microsoft.Maps.Events.addHandler(mark, "click", function(e) {toggleInfo(e, infoBox, true)});

        obj.infoWind.entity = infoBox;
        obj.infoWind.eID = Microsoft.Maps.Events.addHandler(infoBox, "mouseleave", function(e) {toggleInfo(e, infoBox, false)});
        eventsID.push(obj);
      }

因此,这些事件运行良好,直到我将 DrawningToolModule 添加到 map 。

function GetMap()
      {  

         map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), 
            {credentials: "My extra top secret Bing Map Key",
                center: new Microsoft.Maps.Location(51.201547622680664, 16.16974449157715), zoom: 15 });

         Microsoft.Maps.loadModule('Microsoft.Maps.Search', { callback: searchModuleLoaded });

         Microsoft.Maps.registerModule("DrawingToolsModule", "DrawingToolsModule/DrawingToolsModule.js");
         Microsoft.Maps.loadModule("DrawingToolsModule", { callback: function () {
                drawTools = new DrawingTools.DrawingManager(map, {toolbarContainer : document.getElementById("toolbarContainer")});
            }
         });
      }

加载数据后,图钉对点击的 react 很好。 通过 DrawingTool 添加自定义图钉后 - 事件正常。 绘制任何形状(多边形、多边形、圆形)后 - 我的图钉事件未调用。

我添加了一个函数助手来检查事件是否仍然可用:

function showEventsCount()
      {
         alert("Registered events: " + eventsID.length + "\nFirst entity has click event: " +
              Microsoft.Maps.Events.hasHandler(eventsID[0].marker.entity, "click") /*map.entities.getLength()*/);
      }

结果我得到了 true。

这是阻塞事件的错误,还是我遗漏了什么?

最佳答案

可能的问题是您的多边形位于图钉上方,从而阻止了点击事件或存在问题。或者,图钉上方有一个 EntityCollection,其中包含多边形。这是 Bing Maps v7 的一个已知问题。尝试使用以下代码扁平化 map 呈现多边形的方式:

map.getMode().setOptions({drawShapesInSingleLayer: true });

关于javascript - Bing map 绘图工具模块 - 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30454029/

相关文章:

html - Bing Autosuggest 下拉响应式 CSS

javascript - 将 jQuery tablesorter 与 thead 结合起来 : How to assign final html output?

javascript - 您可以使用 HTML 将文本输入作为文件上传吗?

c# - 以编程方式打印 PDF 中的 BING map 位置

css - Bing map - 保留特定版本

jquery - 与 bing/google 地理编码集成的位置搜索自动完成功能

javascript - Javascript 中的单例模式与全局变量用例?

javascript - 异步等待图像加载事件触发器

javascript - 在 Flux/React 中调度级联/依赖异步请求

google-maps - 存在哪些基于 HTML5 Canvas 的映射库?