Find polygon within proximity

Balasaheb Molawade 66 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.

11

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

Waiting for your reply.  

Thanks!

Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
188 questions
No comments
{count} votes

2 answers

Sort by: Most helpful
  1. rbrundritt 7,096 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


  2. IoTGirl 1,981 Reputation points Microsoft Employee
    2023-01-18T00:31:32.6166667+00:00

    Hi Balasaheb,

    Your screen shot does show which polygons are touched by the circle so I would like a better understanding of what you are looking to actually show. Rather than random distance circles, we see customers using distance isochrones like this Isochrone Demo does. Note that the pins within the isochrone are recolored each time the isochrone is calculated. You could do the same for whatever object type you want to color.

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

    Sincerely,

    IoTGirl