저는 Silverlight Bing Maps Control을 사용 중이며 많은 MapPolygon 영역을지도 컨트롤의 자식으로 정의했습니다. 내가 이상적으로 원하는 것은 MapPolygon 내부의 중앙에 TextBlock 레이블을 추가하는 것입니다.Bing Maps MapPolygon에 라벨을 첨부하는 방법은 무엇입니까?
어떻게해야합니까?
저는 Silverlight Bing Maps Control을 사용 중이며 많은 MapPolygon 영역을지도 컨트롤의 자식으로 정의했습니다. 내가 이상적으로 원하는 것은 MapPolygon 내부의 중앙에 TextBlock 레이블을 추가하는 것입니다.Bing Maps MapPolygon에 라벨을 첨부하는 방법은 무엇입니까?
어떻게해야합니까?
다각형의 대략적인 중심 만 필요하면 경계 상자의 중심을 찾고 다각형 위에 프로그래밍 방식으로 TextBlock을 추가 할 수 있습니다.
그래서 이런 식으로 뭔가를 작동 할 수 있습니다 :
(XAML)
<MapControl:Map x:Name="MyMap">
<MapControl:Map.Children>
<MapControl:MapPolygon Fill="Red" Stroke="Yellow" StrokeThickness="5" Opacity="0.7">
<MapControl:MapPolygon.Locations>
<m:LocationCollection>
<m:Location>20, -20</m:Location>
<m:Location>20, 20</m:Location>
<m:Location>-20, 20</m:Location>
<m:Location>-20, -20</m:Location>
</m:LocationCollection>
</MapControl:MapPolygon.Locations>
</MapControl:MapPolygon>
</MapControl:Map.Children>
</MapControl:Map>
(Codebehind가)
public partial class MainPage : UserControl
{
private MapLayer tbLayer;
public MainPage()
{
InitializeComponent();
tbLayer = new MapLayer();
List<TextBlock> newTbs = new List<TextBlock>();
// loop through the maps children and find the polygons
foreach (var child in MyMap.Children)
{
if (child is MapPolygon)
{
var poly = child as MapPolygon;
// get the average lat and long to calculate the "center"-ish of the polygon
var avgLat = poly.Locations.Select(l => l.Latitude).Average();
var avgLon = poly.Locations.Select(l => l.Longitude).Average();
TextBlock tb = new TextBlock
{
Text = "Hey there. I'm a polygon."
};
// set the position of the textblock and add it to a new map layer
MapLayer.SetPositionOrigin(tb, PositionOrigin.Center);
MapLayer.SetPosition(tb, new Location(avgLat, avgLon));
tbLayer.Children.Add(tb);
}
}
// add the new maplayer to the parent map
MyMap.Children.Add(tbLayer);
}
}
당신의 다각형 내 일반적인 예와 같이 작은 사각형이 이상한 모양이 아니라 좋은 경우 , 그러면 좀 더 더러워 질 필요가 있습니다. 이 경우 다각형의 중심을 계산할 수있는 웹 서비스 (WCF)가 필요할 수 있습니다. 나는 Silverlight에서이 작업을 수행하는 간단한 방법이라고 생각하지 않습니다.
다음과 유사한 과정이 될 것입니다.
다소 혼란 스럽지만, Silverlight에서 공간적인 작업을하는 것은 항상 내 경험에서 지저분합니다.
도움이되었거나 너무 오래 바람을 피운 희망 :