简体   繁体   中英

Detect Pushpins Inside a VE Shape on a Bing Map

I have a map which populates pushpins from a database. And a circle. I want to be able to figure out what other pushpins are within the VE Shape circles radius and create a list of their addresses.

     function addPushPin(lat, long) {
     //var point = new Microsoft.Maps.Point(e.getX(), e.getY());

     //var pushpinLocation = new(lat, long);
     var s = new VEShape(VEShapeType.Pushpin, new VELatLong(lat,long)); 


     var customIcon = new VECustomIconSpecification();
     //customIcon.TextContent = "yo bana4na4";
     customIcon.Image = "http://universidadescancun.com/wp-content/themes/GeoUnis3/images/pinpoint-fiesta.png";
     //customIcon.ImageOffset = new VEPixel();

     s.SetTitle("First Pin <span style=color:red>Demo Title<>/span>");
     s.SetDescription("This comes to the <b>description</b> of pushpin.");
     s.SetMoreInfoURL("http://dotnetricks.blogspot.com");
     s.SetPhotoURL("http://upload.wikimedia.org/wikipedia/commons/8/8a/Banana-Single.jpg");

     s.SetCustomIcon(customIcon);
     s.SetIconAnchor(new VELatLong(lat, long));
     map.AddShape(s);


 }

I also have my map populate a circle around one of these pushpins. It is populated like so.

     function getCircleNow(lat, long) {

     var latin = lat;
     var lonin = long;
     var latlong = new VELatLong(latin, lonin);
     centerPoint = (latlong);
     //var center = map.GetCenter().toString();
     //alert(center);
     //Get initial circle points
     var circlePoints = buildCircle(centerPoint.Latitude, centerPoint.Longitude, 50.74);
     //Build circle
     circle = new VEShape(VEShapeType.Polygon, circlePoints);
     circle.HideIcon();
     circle.SetLineWidth(2);
     map.AddShape(circle);
     //Build mask
     circleMask = new VEShape(VEShapeType.Polygon, circlePoints);
     circleMask.HideIcon();
     circleMask.Hide();
     circleMask.SetLineColor(new VEColor(0, 0, 0, 0.5));
     circleMask.SetFillColor(new VEColor(0, 0, 0, 0.0));
     circleMask.Primitives[0].symbol.stroke_dashstyle = "Dash";
     map.AddShape(circleMask);


 }

And here is the buildCircle() function it calls.

     function buildCircle(latin, lonin, radius) {
     var locs = new Array();
     var lat1 = latin * Math.PI / 180.0;
     var lon1 = lonin * Math.PI / 180.0;
     var d = radius / 3956;
     var x;
     for (x = 0; x <= 360; x += 10) {
         var tc = (x / 90) * Math.PI / 2;
         var lat = Math.asin(Math.sin(lat1) * Math.cos(d) + Math.cos(lat1) * Math.sin(d) * Math.cos(tc));
         lat = 180.0 * lat / Math.PI;
         var lon;
         if (Math.cos(lat1) == 0) {
             lon = lonin; // endpoint a pole
         }
         else {
             lon = ((lon1 - Math.asin(Math.sin(tc) * Math.sin(d) / Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI;
         }
         lon = 180.0 * lon / Math.PI;
         var loc = new VELatLong(lat, lon);
         locs.push(loc);
     }
     return locs;

 }

This is what my map looks like after I have added the pushpins and I have populated the circle on the map, with it centered around one of the locations and with a 50 mile radius.

我的代码填充了什么

WHAT I WANT TO BE ABLE TO DO

I want to be able to use either JavaScript or C# to detect what other pushpins, besides the one the circle is centered around, are within the radius of the center location. Or more simply, what other locations/pushpins are in the circle, and populate a list with values of each address. I can't think of any special methods that can do this so any help would be appreciated. This is Bing maps That I'm using.

This is fairly easy to do. Take the center point and radius of the circle do the following:

That's it. I also wrote an MSDN article on this for v6 of Bing maps a long time ago but it looks like it has been taken offline, along with all the documentation for v6.3 of Bing maps.

With all this said, its worth pointing out that Bing Maps V6.3 is really old and was last updated about 5 or 6 years ago. It's not recommended to do any new development on it but to instead make use of version 7 which is a lot more powerful, has more features, and is significantly smaller in terms of download size. I have a migration guide here: http://social.technet.microsoft.com/wiki/contents/articles/20958.migrating-bing-maps-v6-3-to-v7.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM