简体   繁体   English

在Bing地图上检测VE形状内的图钉

[英]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. 我希望能够找出VE Shape圆半径内还有哪些其他图钉,并创建其地址列表。

     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. 这是它调用的buildCircle()函数。

     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. 这是添加图钉并在地图上填充圆之后的样子,其圆心以位置之一为中心,半径为50英里。

我的代码填充了什么

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. 我希望能够使用JavaScript或C#来检测哪些其他图钉,除了以圆为中心的图钉之外,它们还位于中心位置的半径内。 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: 取圆的中心点和半径执行以下操作:

  • Loop through all pushpins and measure their distance from the center point using the Haversine formula: http://rbrundritt.wordpress.com/2008/10/14/calculate-distance-between-two-coordinates/ 循环遍历所有图钉并使用Haversine公式测量它们与中心点的距离: http ://rbrundritt.wordpress.com/2008/10/14/calculate-distance-between-two-coordinates/
  • If the distance is less than or equal to the circles radius then the pushpin is inside the circle. 如果距离小于或等于圆的半径,则图钉位于圆的内部。

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. 很久以前,我还针对Bing地图v6撰写了一篇有关MSDN的文章,但看起来它已脱机,以及Bing地图v6.3的所有文档。

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. 综上所述,值得一提的是Bing Maps V6.3确实很老,最近一次更新是在5或6年前。 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. 不建议对其进行任何新开发,而要使用版本7,该版本功能强大得多,具有更多功能,并且下载大小明显较小。 I have a migration guide here: http://social.technet.microsoft.com/wiki/contents/articles/20958.migrating-bing-maps-v6-3-to-v7.aspx 我在这里有一个迁移指南: http : //social.technet.microsoft.com/wiki/contents/articles/20958.migrating-bing-maps-v6-3-to-v7.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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