0
因此,我正在使用bing地圖v8編寫一個應用程序。不幸的是,它沒有z-index支持(儘管有z-index函數...)。所以我正在嘗試使用圖層來完成類似的事情。問題是當我在層之間交換引腳時,事件開始在正確的引腳位置上觸發錯誤的元數據。Bing地圖v8事件傳遞不正確的引腳?
這裏是我創建的引腳
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;
}
出於某種原因,我把每一個具有正確的位置,但不正確的元數據時得到一個腳物件在鼠標懸停。如果我評論取消選擇...我得到正確的兩個。
這是我如何選擇和取消選擇引腳。基於我給出的例子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;
}