none
Infobox v8 sdk example : using just one Infobox RRS feed

  • Question

  • Bing v8 SDK example

    In this example, we see how to use just 1 Infobox : 

    var map = new Microsoft.Maps.Map(document.getElementById('myMap'), { 
        credentials: 'Your Bing Maps Key',
        center: new Microsoft.Maps.Location(47.60357,-122.32945)
    });
    var pushpins = Microsoft.Maps.TestDataGenerator.getPushpins(10, map.getBounds());
    var infobox = new Microsoft.Maps.Infobox(pushpins[0].getLocation(), { title: 'title', 
        description: 'description', showCloseButton: false });
    infobox.setMap(map);
    for (var i = 0; i < pushpins.length; i++) {
        var pushpin = pushpins[i];
        Microsoft.Maps.Events.addHandler(pushpin, 'click', (args) => {
            infobox.setLocation(args.target.getLocation());
        });
    }
    map.entities.push(pushpins);
    
    
    However, I find this may be a very low usage, as one would most likely want to have a dynamic (individual) title: and description: for each infobox.  There was no data bucket I could find off of Pushpin to store the data there, so please let me know if there is a elegant way to use one infobox, but have unique data per pushpin.

    Tuesday, July 12, 2016 7:22 PM

Answers

  • That's not the best example. I'll have the devs update it to match the example we have in the documentation which makes a lot more sense: https://msdn.microsoft.com/en-us/library/mt750274.aspx

    The key benefit of this is that you can reuse the infobox and update the title/description values for each pushpin. This will result in only one infobox instance being created which keeps things simple and uses very little memory.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Tuesday, July 12, 2016 7:45 PM
    • Marked as answer by Rybolt Wednesday, July 13, 2016 5:43 PM
    Tuesday, July 12, 2016 7:45 PM
  • The team has updated the sample in the interactive SDK in the experimental branch. This will be in the main release branch in a couple of weeks. Thank you for the feedback.

    [Blog] [twitter] [LinkedIn]

    Friday, August 26, 2016 5:06 PM

All replies

  • My apologies, I think my question was really a questionING of the sdk example's usefulness.  I still don't know how popping an Infobox with the same title/desc. is useful, but I absolutely may be missing something, as inspecting the v8 functionality can be a bit of trial & error .

    My solution for anyone else in this boat, is to maintain your collection of infoboxes, and just hide them all before showing the one clicked on.

       Microsoft.Maps.Events.addHandler(pushPin, 'click', (args) => {
                for(let ib of this._infoBoxes) { ib.setOptions({visible:false});}
                infobox.setOptions({ visible: true });
                infobox.setLocation(args.target.getLocation());
            });



    • Marked as answer by Rybolt Tuesday, July 12, 2016 7:44 PM
    • Edited by Rybolt Tuesday, July 12, 2016 7:51 PM
    • Unmarked as answer by Rybolt Wednesday, July 13, 2016 5:43 PM
    Tuesday, July 12, 2016 7:34 PM
  • That's not the best example. I'll have the devs update it to match the example we have in the documentation which makes a lot more sense: https://msdn.microsoft.com/en-us/library/mt750274.aspx

    The key benefit of this is that you can reuse the infobox and update the title/description values for each pushpin. This will result in only one infobox instance being created which keeps things simple and uses very little memory.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Tuesday, July 12, 2016 7:45 PM
    • Marked as answer by Rybolt Wednesday, July 13, 2016 5:43 PM
    Tuesday, July 12, 2016 7:45 PM
  •  Note that all IPrimitive shapes have a metadata property were you can store data for that shape.

    Yes, this example is better , thanks for sharing.

    Wednesday, July 13, 2016 5:43 PM
  • The team has updated the sample in the interactive SDK in the experimental branch. This will be in the main release branch in a couple of weeks. Thank you for the feedback.

    [Blog] [twitter] [LinkedIn]

    Friday, August 26, 2016 5:06 PM