Answered by:
GetPrimitives Method of the Layer Class Only Returns Primitives if the Layer is Visible

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>
console.log("Accesing _primitives directly:");
<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("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.
- 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 -
- Proposed as answer by Ricky_Brundritt Wednesday, August 10, 2016 7:00 PM
- Marked as answer by Ricky_Brundritt Wednesday, August 10, 2016 7:00 PM
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.
- 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! KenSaturday, July 2, 2016 1:49 AM
-
- Proposed as answer by Ricky_Brundritt Wednesday, August 10, 2016 7:00 PM
- Marked as answer by Ricky_Brundritt Wednesday, August 10, 2016 7:00 PM
Wednesday, August 10, 2016 6:59 PM -
This works great now, thank you!
Ken
Friday, August 12, 2016 3:07 PM