How can I focus and show infobox in bing cards?

My code does .pantolatlong and then .showinfobox

The info window does not appear if I do not delete pantolatlong. It probably stops him. I tried adding it to the endpan event, but that didn't work.

What is the easiest way to pan by clicking a button and displaying an info box for it?

I used setcenter, but I found that sometimes setcenter pans, and this violates it.

+5
source share
2 answers

After a crazy Google search, I came up with a solution, and I will share it here so that others can hope that I did not have the grief that I experienced.

, javascript, no sdk iframe. javascript , , asp.net.

setCenter() Bing-, , , . ... . , , . SetCenter, ShowInfoBox, , .

? , sdk, , , , . onendpan, . onchangeview, .

, ... . ?

, , . setTimeout 10 . .

, , , , , , ( - onclick). / " ", , , , .

, , . , / , . , , , .

, , , / setTimeout, , 100 . , .

, , , javascript - , , , , .

, , , , . , :

// An array of our pins to allow panning to them
var myPushPins = [];

// Used by the eventhandler
var eventPinIndex;
var oldMapCenter;

// Zoom in and center on a pin, then show its information box
function ShowPushPin(pinIndex) {
    eventPinIndex = pinIndex;
    oldMapCenter = map.GetCenter();
    map.AttachEvent("onendpan", EndPanHandler);
    map.AttachEvent("onchangeview", ChangeViewHandler);
    setTimeout("DetectNoMapChange();", 200);

    map.SetZoomLevel(9);
    map.SetCenter(myPushPins[pinIndex].GetPoints()[0]);

}


function EndPanHandler(e) {
    map.DetachEvent("onendpan", EndPanHandler);

    setTimeout("map.ShowInfoBox(myPushPins[eventPinIndex]);", 10);

}

function ChangeViewHandler(e) {
    map.DetachEvent("onchangeview", ChangeViewHandler);

    setTimeout("map.ShowInfoBox(myPushPins[eventPinIndex]);", 10);

}

function DetectNoMapChange(centerofmap) {

    if (map.GetCenter().Latitude == oldMapCenter.Latitude && map.GetCenter().Longitude == oldMapCenter.Longitude) {
        map.ShowInfoBox(myPushPins[eventPinIndex]);
    }
}
+4

:

    function addPushpin(lat,lon,pinNumber) {
    var pinLocation = new Microsoft.Maps.Location(lat, lon);

    var pin = new Microsoft.Maps.Pushpin(map.getCenter(), { text: pinNumber.toString() });

    pinInfobox = new Microsoft.Maps.Infobox(pinLocation,
            { title: 'Details',
                description: 'Latitude: ' + lat.toString() + ' Longitude: ' + lon.toString(),
                offset: new Microsoft.Maps.Point(0, 15)
            });


    map.entities.push(pinInfobox);
    map.entities.push(pin);

    pin.setLocation(pinLocation);
    map.setView({ center: pinLocation});
}
+3

All Articles