【问题标题】:Bing maps v8 event passes incorrect pin?必应地图 v8 事件传递了错误的密码?
【发布时间】:2017-02-10 07:28:03
【问题描述】:

所以我正在使用 bing maps v8 编写一个应用程序。不幸的是,它没有 z-index 支持(尽管有 z-index 功能......)。所以我试图使用图层来完成类似的事情。问题是当我在层之间交换引脚时,事件开始在具有错误元数据的正确引脚位置触发。

这是我创建图钉的方法

function createImagePin(location, index, objArray)
{
    var obj = objArray[index];
    var smallPin = getSmallPin(obj);

    var pin = new Microsoft.Maps.Pushpin(location,
    {
        visible: true,
        icon: smallPin.data,
        anchor: new Microsoft.Maps.Point(smallPin.width / 2, smallPin.height / 2) //Align center of pushpin with location.
    });

    pin.metadata = {};
    pin.metadata.index = index;
    pin.metadata.dataTarget = obj;
    pin.metadata.isSelected = false;

    Microsoft.Maps.Events.addHandler(pin, 'click', function (e) {

        if(e.targetType === 'pushpin')
        {
            SetRowSelection(e.target.metadata.index);
        }
    });

    Microsoft.Maps.Events.addHandler(pin, 'mouseover', function (e)
    {
        if(e.targetType === 'pushpin')
        {
            SelectPin(e.target); 
            ShowInfobox(e.target);
            console.log(e.target.getLocation());
        }
    });

    Microsoft.Maps.Events.addHandler(pin, 'mouseout', function (e)
    {
        if (e.targetType === 'pushpin')
        {
            DeselectPin(e.target);
            HideInfobox();
        }
    });

    return pin;
}

由于某种原因,每次鼠标悬停时,我都会在鼠标悬停时得到一个 pin 对象,该对象具有正确的位置但元数据不正确。如果我注释掉 Deselect ... 我得到正确的两个。

这是我选择和取消选择图钉的方法。根据给我的例子Bing Maps pushpin icon issues

目前没有其他代码可以触及这些引脚......这对我来说似乎很奇怪。这几乎就像在内部一样,它只是在图层中复制一些信息,而不是移动所有附加到对象的项目。事实上,如果我只是注释掉添加/删除它会停止向我传递不正确的数据......虽然我失去了我的 z-indexing。

function SelectPin(pin)
{
    switch (pin.metadata.dataTarget.ComparableType)
    {
        case "Subject":
            mapLayers.subjectLayer.remove(pin);
            pin.setOptions({ visible: true, icon: largeGreenHouse.data, anchor: new Microsoft.Maps.Point(largeGreenHouse.width / 2, largeGreenHouse.height / 2) });
            break;
        case "Listing Comp":
            mapLayers.compLayer.remove(pin);
            pin.setOptions({ visible: true, icon: largeBlueHouse.data, anchor: new Microsoft.Maps.Point(largeBlueHouse.width / 2, largeBlueHouse.height / 2) });
            break;
        case "Sales Comp":
            mapLayers.compLayer.remove(pin);
            pin.setOptions({ visible: true, icon: largeBlueHouse.data, anchor: new Microsoft.Maps.Point(largeBlueHouse.width / 2, largeBlueHouse.height / 2) });
            break;
        case "Hidden":
            pin.setOptions({ visible: false });
            return;
        default:
            mapLayers.observableLayer.remove(pin);
            pin.setOptions({ visible: true, icon: largeGreyHouse.data, anchor: new Microsoft.Maps.Point(largeGreyHouse.width / 2, largeGreyHouse.height / 2) });
            break;
    }

    mapLayers.selectionLayer.add(pin);
    pin.metadata.isSelected = true;
}

function DeselectPin(pin)
{
    if(!pin.metadata.isSelected)
        return;

    pin.metadata.isSelected = false;
    mapLayers.selectionLayer.remove(pin);  
    switch (pin.metadata.dataTarget.ComparableType)
    {
        case "Subject":
            pin.setOptions({ visible: true, icon: greenHouse.data, anchor: new Microsoft.Maps.Point(greenHouse.width / 2, greenHouse.height / 2) });
            mapLayers.subjectLayer.add(pin);
            break;
        case "Listing Comp":
            pin.setOptions({ visible: true, icon: blueHouse.data, anchor: new Microsoft.Maps.Point(blueHouse.width / 2, blueHouse.height / 2) });
            mapLayers.compLayer.add(pin);
            break;
        case "Sales Comp":
            pin.setOptions({ visible: true, icon: blueHouse.data, anchor: new Microsoft.Maps.Point(blueHouse.width / 2, blueHouse.height / 2) });
            mapLayers.compLayer.add(pin);
            break;
        case "Hidden":
            pin.setOptions({ visible: false });
            return;
        default:
            pin.setOptions({ visible: true, icon: greyHouse.data, anchor: new Microsoft.Maps.Point(greyHouse.width / 2, greyHouse.height / 2) });
            mapLayers.observableLayer.add(pin);
            break;
    }

【问题讨论】:

    标签: javascript bing-maps


    【解决方案1】:

    嗯,这似乎是数据问题而不是代码问题。对于某些地址不同的属性,我的数据被地理编码为相同的纬度/经度。因此,阵列的重新排列会导致具有相同位置的不同阵列获得“顶部位置”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      相关资源
      最近更新 更多