必应地图多边形更改侦听器

时间:2018-11-27 12:11:32

标签: javascript bing-maps

我需要一个事件侦听器,该事件侦听器在bing地图V8中获取多边形上的更改。我已经用Google搜索了很多,却什么也没发现。我是这样在Google中完成的

 google.maps.event.addListener(regionPolygon, 'click', function () {
        var ang = regionPolygon.getPath();
        google.maps.event.addListener(ang, 'set_at', function () {
            var newPoints = [];
            newPoints = regionPolygon.getPath().getArray();
            var a = newPoints.length;
            var x = regionPolygon.getPath();
            var bounds = new google.maps.LatLngBounds();
            var strx = "";
            //var b = 0;
            for (b = 0; b < a; b++) {
                var i = b + 1;
                strx = strx + newPoints[b].lat() + ',';

                if (i != a)
                {
                    strx = strx + newPoints[b].lng() + ',';
                }
                else if (i == a)
                {
                    strx = strx + newPoints[b].lng();
                }
            }     
                isFinished = true;
                updateRegion(regionName, strx);
                setTimeout(function () { loadRegions(); },2500);                 
        });}

我在bing地图上找不到。顺便说一下,我设置了这样的可编辑多边形

var多边形=新的Microsoft.Maps.Polygon(点,{                 厚度:1             });

        Microsoft.Maps.loadModule('Microsoft.Maps.DrawingTools', function () {
            //Create an instance of the DrawingTools class and bind it to the map.
            var tools = new Microsoft.Maps.DrawingTools(_this.mapBings);

            //Pass the polygon to the drawing tools to be edited.
            tools.edit(polygon);
        });

        var bestView = Microsoft.Maps.LocationRect.fromLocations(points);

        setTimeout((function () {
            this.mapBings.setView({ bounds: bestView });
        }).bind(_this), 10);

        _this.polygonOverlay = polygon;
        // _this.mapBings.entities.push(polygon);

        Microsoft.Maps.Events.addHandler(polygon, 'click',
            function ()
            {
                alert('hey')
            });

1 个答案:

答案 0 :(得分:1)

将事件添加到图形管理器。如此处所述,有几种可供选择:https://msdn.microsoft.com/en-us/library/mt750463.aspx

如果使用drawingChanged事件,则在编辑多边形时将触发该事件。您可以在此处找到一个实时代码示例,该示例演示何时触发这些事件:http://bingmapsv8samples.azurewebsites.net/#DrawingTools_Events