How to get pushpin information inside polygon shape, in bing maps v8? RRS feed

  • Question

  • I'm loading pushpins in map layer. Once map loaded with pushpins, using polygon am drawing a rectangle over a map. Then inside a drawn polygon i have few pushpins. I need to get pushpin information inside the polygon and store into a javascript array/object using Bing maps V8.
    Wednesday, August 9, 2017 1:49 PM


All replies

  • There are several ways to do this depend where the pushpin data is hosted. By the sound of it, in your case the pushpins are already on the map. With this in mind you can accomplish this fairly easily using the built in Spatial Math module in Bing Maps V8. Here is a code sample that shows how to do this: 


    [Blog] [twitter] [LinkedIn]

    Wednesday, August 9, 2017 7:03 PM
  • Ricky_Brundritt,

    Thanks for your suggestion. i have tried your example code, when im trying to access the pushpin information which is intersecting, am always getting the first pushpin information on all other pushpin. Please review below code and comments on the code.

    var pinss = pinLayer.getPrimitives();

    console.log(pinss); // here all pushpin information are proper appropriately. var intersectingPins = null; intersectingPins = Microsoft.Maps.SpatialMath.Geometry.intersection(pinss, selectBox); if (intersectingPins) { if (intersectingPins && !(intersectingPins instanceof Array)) { intersectingPins = [intersectingPins]; } console.log(intersectingPins); for (var i = 0; i < intersectingPins.length; i++) { console.log(intersectingPins[i].metadata); // Here am getting first loaded pushpin information for all intercting pushpin }


    Friday, August 11, 2017 7:25 AM
  • Your right. Looking into this, I now remember why this is. When the spatial math geometry functions take in an array of shapes as a single parameter, it is considered a single complex shape such as a MultiPolygon and only the metadata information of the first shape is included in the copied version of the output shape. 

    With this in mind I have modified the code such that it maps the intersecting pushpins back to the original pushpin references. The code sample has been updated: http://bingmapsv8samples.azurewebsites.net/#Select%20Data%20in%20Drawn%20Polygon%20Area

    [Blog] [twitter] [LinkedIn]

    Friday, August 11, 2017 4:17 PM
  • Thanks, It worked as expected.
    Wednesday, August 16, 2017 6:21 AM