【问题标题】:Bing Map V8 Infobox Visible not working必应地图 V8 信息框可见不工作
【发布时间】:2016-12-09 10:10:03
【问题描述】:

来自Bing map V8 official documentation 的示例。默认情况下,信息框为 false,但第一次显示它。

            <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8" />
        <script type='text/javascript'
                src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
        <script type="text/javascript">
        var map, clusterLayer, infobox;

        function GetMap() {
            map = new Microsoft.Maps.Map('#myMap', {
                credentials: 'Bing Map Key'
            });

            //Add an infobox to the map.
            infobox = new Microsoft.Maps.Infobox(map.getCenter(), { visible: false });
            infobox.setMap(map);

            Microsoft.Maps.loadModule("Microsoft.Maps.Clustering", function () {
                //Create a clustering layer
                clusterLayer = new Microsoft.Maps.ClusterLayer(createCustomPushpins(100), {
                    clusteredPinCallback: createCustomClusterPushpins,
                    callback: createPushpinList
                });
                map.layers.insert(clusterLayer);
            });
        }

        function createCustomPushpins(size) {
            //Generate random pushpins within the map bounds.
            var pins = Microsoft.Maps.TestDataGenerator.getPushpins(size, map.getBounds());

            for (var i = 0; i < size; i++) {
                //Create a title for each pushpin.
                pins[i].setOptions({ title: 'Pushpin #' + i });

                //Add handler for the pushpin click event.
                Microsoft.Maps.Events.addHandler(pins[i], 'click', pushpinClicked);
            }

            return pins;
        }

        function createCustomClusterPushpins(cluster) {
            //Create a title for the cluster.
            cluster.setOptions({
                title: 'Cluster of ' + cluster.containedPushpins.length + ' pins'
            });

            //Add handler for the cluster click event.
            Microsoft.Maps.Events.addHandler(cluster, 'click', pushpinClicked);
        }

        function pushpinClicked(e) {
            //Show an infobox when a pushpin is clicked.
            showInfobox(e.target);
        }

        function createPushpinList() {
            //Create a list of displayed pushpins each time clustering layer updates.

            if (clusterLayer != null) {
                infobox.setOptions({ visible: false });

                //Get all pushpins that are currently displayed.
                var data = clusterLayer.getDisplayedPushpins();
                var output = [];

                //Create a list of links for each pushpin that opens up the infobox for it.
                for (var i = 0; i < data.length; i++) {
                    output.push("<a href='javascript:void(0);' onclick='showInfoboxByGridKey(", data[i].gridKey, ");'>");
                    output.push(data[i].getTitle(), "</a><br/>");
                }

                document.getElementById('listOfPins').innerHTML = output.join('');
            }
        }

        function showInfoboxByGridKey(gridKey) {
            //Look up the cluster or pushpin by gridKey.
            var clusterPin = clusterLayer.getClusterPushpinByGridKey(gridKey);

            //Show an infobox for the cluster or pushpin.
            showInfobox(clusterPin);
        }

        function showInfobox(pin) {
            var description = [];

            //Check to see if the pushpin is a cluster.
            if (pin.containedPushpins) {

                //Create a list of all pushpins that are in the cluster.
                description.push('<div style="max-height:75px;overflow-y:auto;"><ul>');
                for (var i = 0; i < pin.containedPushpins.length; i++) {
                    description.push('<li>', pin.containedPushpins[i].getTitle(), '</li>');
                }
                description.push('</ul></div>');
            }

            //Display an infobox for the pushpin.
            infobox.setOptions({
                title: pin.getTitle(),
                location: pin.getLocation(),
                description: description.join(''),
                visible: true
            });
        }
        </script>
    </head>
    <body>
        <div id="myMap" style="position:relative; width:600px; height:400px;"></div>
        <br />
        <div id="listOfPins" style="max-height:250px;width:250px;overflow-y:scroll;"></div>
    </body>
    </html>

根据官方文档,我们必须在实例化 infobox 对象时传递 visible false (infobox = new Microsoft.Maps.Infobox(map.getCenter(), { visible: false });)有什么建议我哪里出错了吗?

【问题讨论】:

    标签: maps bing-maps


    【解决方案1】:

    奇怪,刚试了IE11、Edge、Chrome和Firefox中提供的代码。它在除 Chrome 之外的所有浏览器中都能正常工作。不知道为什么 Chrome 的行为有所不同。将让团队对此进行调查。感谢您的报告。

    【讨论】:

    • 由于多个图钉的经纬度相同,是否有任何事件可以识别无法挖掘的集群
    • 创建集群图钉时,检查缩放级别。如果地图完全放大,那么您正在创建的集群图钉将无法在您完全放大时分开。
    • @rbrundritt 对此有何修复?
    • 由于假期旺季,必应地图平台在 12 月份处于代码冻结状态。我们的大多数客户也处于代码冻结状态,因此本月我们无法推出任何更新。该团队目前还在处理许多大型任务。计划在 1 月份对此进行调查。
    • 好消息,现在在实验分支中解决了。此修复将在发布分支的下一次更新中进行,可能在 2 月。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多