# Find polygon within proximity

136 Reputation points
2023-01-17T09:16:21.8+00:00

Hi,

We have developed an application using Bing map in that we have the requirement to show areas ( plotted area using polygon) that are covered by specific proximity say suppose 5 miles. For example, we have plotted area as a polygon now we wanted to show the area that covers by proximity search as shown below. We wanted to show all polygon those are touched the proximity circle.

In any one have the best solution to show area within proximity.

Thanks!

Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
249 questions

1. 15,546 Reputation points Microsoft Employee
2023-01-17T16:56:08.01+00:00

To achieve this you will need to loop through all your polygons and do an intersection test with your proximity circle polygon. Since you are using the Bing Maps V8 web SDK, you can use the spatial math module to do the intersection test. Here is a quick example.

``````Microsoft.Maps.loadModule('Microsoft.Maps.SpatialMath', function () {

//Assume this is an array of polygons.
var polygons = [];

//Assume this is the polygon area you want to search in (i.e. circle);
var searchPolyogn = {};

//Loop through each polygon.
for(var i=0,len=polygons.length; i < len; i++){
//Test each polygon to see if it itersects the search polygon.
if(Microsoft.Maps.SpatialMath.Geometry.intersects(polygons[i], searchPolyogn)){
//If it does, do something, like change it's color.
polygons[i].setOptions({fillColor: 'red' });
} else {
//It didn't intersect, maybe change the color back to a default color.
polygons[i].setOptions({fillColor: 'blue' });
}
}
});
``````

Here is a similar example: https://samples.bingmapsportal.com/?sample=select-data-in-drawn-polygon-area