none
GetPrimitives Method of the Layer Class Only Returns Primitives if the Layer is Visible RRS feed

  • Question

  • Hi,

    I have a layer of unit pushpins that I want to be able to modify options of whether the layer is currently visible or not. However, it seems that GetPrimitives() is only returning primitives if the layer is visible. Is this by design?

    I can work around it by accessing layer._primitives directly, but it doesn't feel right.

    Thanks,

    Ken

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8" />
    </head>
    <body>
        <div id="myMap"></div>
        <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap'  async defer></script>
        <script type='text/javascript'>
        function GetMap() {

    map = new Microsoft.Maps.Map('#myMap', {
                credentials: 'Your Bing Maps Key'
            });

            //Create a layer.
            var layer = new Microsoft.Maps.Layer();

            //Add some data to it.
            layer.add(Microsoft.Maps.TestDataGenerator.getPushpins(2, map.getBounds()));

            //Add layer to map.
            map.layers.insert(layer);

            console.log("Layer Visible: ", layer.getVisible());
            console.log("Primitives Count: ", layer.getPrimitives().length);

            layer.setVisible(false);

            console.log("Layer Visible: ", layer.getVisible());
            console.log("Primitives Count: ", layer.getPrimitives().length);

            console.log("Accesing _primitives directly:");
            console.log("Primitives Count: ", layer._primitives.length);

        }

        </script>
    </body>
    </html>

    Friday, July 1, 2016 9:38 PM

Answers

  • This is related to the other issue you mentioned about shapes that where not visible were not showing up in the getPrimitives results. Ends up this was originally by design as this function is used by the rendering engine of the map and to save processing time, it only returns the shapes that are visible. The team is looking to modify the default behavior such that it is more inline with what developers would expect.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Saturday, July 2, 2016 12:22 AM
    • Marked as answer by Ken C Bowman Saturday, July 2, 2016 1:49 AM
    Saturday, July 2, 2016 12:22 AM
  • Good news, the dev team has looked into this issue and fixed it. The fix is currently in the experimental branch of V8 and will be rolled into the main release branch in our next monthly update which will like occur in the first full week of September.

    [Blog] [twitter] [LinkedIn]

    Wednesday, August 10, 2016 6:59 PM

All replies

  • This is related to the other issue you mentioned about shapes that where not visible were not showing up in the getPrimitives results. Ends up this was originally by design as this function is used by the rendering engine of the map and to save processing time, it only returns the shapes that are visible. The team is looking to modify the default behavior such that it is more inline with what developers would expect.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Saturday, July 2, 2016 12:22 AM
    • Marked as answer by Ken C Bowman Saturday, July 2, 2016 1:49 AM
    Saturday, July 2, 2016 12:22 AM
  • My bad. I didn't see the similar question regarding this behavior (i.e. Bing Maps V8 Primitive Visibility Bug ). Thanks! Ken
    Saturday, July 2, 2016 1:49 AM
  • Good news, the dev team has looked into this issue and fixed it. The fix is currently in the experimental branch of V8 and will be rolled into the main release branch in our next monthly update which will like occur in the first full week of September.

    [Blog] [twitter] [LinkedIn]

    Wednesday, August 10, 2016 6:59 PM
  • This works great now, thank you!

    Ken

    Friday, August 12, 2016 3:07 PM