none
It seems to have bug in add() method of a layer at 0 index(Bing Map V8) RRS feed

  • Question

  • I have created a layer and added a shapes in it using say mayLayer.add(myshape). Now I have removed the shape at 0 index using myLayer.removeAt(0). The shape is removed from that index. When I add another shape into 0 index by myLayer.add(myAnotherShape,0), it added up at the last position of the layer. If I add the shape by this way: myLayer.add(myAnotherShape, - myLayer.getPrimitives().length), that is -(minus) length of the array of shapes(primitives) contained by myLayer then it is added into 0 position. Is it any bug or we should use the add() method in this way to add a primitive/shape at 0 index of a layer?


    Wednesday, July 20, 2016 5:53 AM

Answers

  • Ah, ok. I thought you were only using pushpins. Pushpins can never be rendered below shapes. If you only look at the code that adds the data and not at the code that removes it, you will see that the pushpin still renders above. Pushpins are always rendered above polylines, polygons and other layers. Only Infoboxes, other Pushpins, and the navigation controls of the map render above pushpins. In previous versions of Bing Maps you could render pushpins below other shapes, but in 99% of cases where this happened it was an undesired behavior by the developer.

    In V8 there are two main HTML5 canvases used for rendering. The first one renders the map tiles, tile layers, and polylines/polygons. The second canvas is used to render pushpins and map labels. This layer does a lot of calculations as label collision detection is done against pushpins such that labels that overlap a pushpin are either moved to another reasonable position or are hidden.


    [Blog] [twitter] [LinkedIn]

    Thursday, July 21, 2016 4:00 PM

All replies

  • Can you provide sample code that reproduces this. I've tried doing this several different ways and don't seem to be able to reproduce this. Are you using the main release branch or the experimental branch?

    [Blog] [twitter] [LinkedIn]

    Wednesday, July 20, 2016 6:38 PM
  • I am using the release branch. Below is my sample code:

            
    <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release'></script>

    var map = new Microsoft.Maps.Map('#myMap', { credentials: 'your key' });

    var center = map.getCenter(); var layer = new Microsoft.Maps.Layer(); map.layers.insert(layer); var pushpin = new Microsoft.Maps.Pushpin(center, null); layer.add(pushpin, 0); var polyline = new Microsoft.Maps.Polyline([new Microsoft.Maps.Location(center.latitude + 0.02, center.longitude - 0.08), new Microsoft.Maps.Location(center.latitude + 0.02, center.longitude), new Microsoft.Maps.Location(center.latitude - 0.02, center.longitude), new Microsoft.Maps.Location(center.latitude - 0.02, center.longitude + 0.08)], null); layer.add(polyline,1); var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(center.latitude - 0.05, center.longitude - 0.15), new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude - 0.15), new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude - 0.05)], { fillColor: 'yellow', strokeColor: 'orange', strokeThickness: 5, strokeDashArray: [1, 2, 5, 10] }); layer.add(polygon,2); layer.removeAt(0);//pushpin(geometryType:1) is removed from 0 index layer.add(pushpin, 0) //again adding pushpin at 0 index. but added at last position. ////uncomment the below statement to add the pushpin into the layer at 0 index. //layer.add(pushpin, -layer.getPrimitives().length);

    Thanks.

    Thursday, July 21, 2016 6:14 AM
  • Ah, ok. I thought you were only using pushpins. Pushpins can never be rendered below shapes. If you only look at the code that adds the data and not at the code that removes it, you will see that the pushpin still renders above. Pushpins are always rendered above polylines, polygons and other layers. Only Infoboxes, other Pushpins, and the navigation controls of the map render above pushpins. In previous versions of Bing Maps you could render pushpins below other shapes, but in 99% of cases where this happened it was an undesired behavior by the developer.

    In V8 there are two main HTML5 canvases used for rendering. The first one renders the map tiles, tile layers, and polylines/polygons. The second canvas is used to render pushpins and map labels. This layer does a lot of calculations as label collision detection is done against pushpins such that labels that overlap a pushpin are either moved to another reasonable position or are hidden.


    [Blog] [twitter] [LinkedIn]

    Thursday, July 21, 2016 4:00 PM