2012-05-12 9 views
0

オーストラリアの座標を選択できるポップアップダイアログを作成しようとしていますが、Silverlightコントロールと非常によく似ていますが、WPFコントロールの特定のドキュメントを見つけるのが難しいです。Bingsは単一の国に限定されたコントロールをマップしますか?

基本的には、オーストラリアの地図を中心にして3.8のレベルにズームしてから、オーストラリア座標の範囲外で地図をスクロールしないようにします。 - オーストラリアの範囲外の別の場所で地図を表示します。ここで

は私のコードは、これまでのところです:

<Window x:Class="GetP51.Views.Dialogs.SelectCoordinatesDialog" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF" 
     Title="GetP51 - Select Coordinates" MinHeight="525" Height="525" MaxHeight="525" MinWidth="500" Width="500" MaxWidth="500" Icon="../../GetP51.ico" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow"> 

    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="25"></RowDefinition> 
      <RowDefinition></RowDefinition> 
     </Grid.RowDefinitions> 

     <TextBox x:Name="AddressSearch" Grid.Row="0"></TextBox> 

     <m:Map x:Name="AustralianMap" Grid.Row="1" CredentialsProvider="key" Mode="Aerial"></m:Map> 
    </Grid> 
</Window> 

そして、背後にあるコード:

public partial class SelectCoordinatesDialog : Window 
    { 
     public SelectCoordinatesDialog() 
     { 
      InitializeComponent(); 
      AustralianMap.Center = new Location(-25.274398, 133.775136); 
      AustralianMap.ZoomLevel = 3.8; 
     } 
    } 

誰かがどのように私が何を探しています何を達成するために教えてくださいことはできますか?

ありがとう、 アレックス。

+0

何が効いているのか、それともうまくいきませんか? –

答えて

1

あなたは、単にマップコントロールを無効にして、マウス入力(例のMouseLeftButtonUp)を取得透明制御(例えばキャンバス)でそれを重ねることができます:入力イベントハンドラで

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="25"/> 
     <RowDefinition/> 
    </Grid.RowDefinitions> 
    <TextBox x:Name="AddressSearch" Grid.Row="0" />  
    <m:Map Name="AustralianMap" Grid.Row="1" 
      ZoomLevel="3.8" Center="-25.274398,133.775136" 
      IsEnabled="False" /> 
    <Canvas Grid.Row="1" Background="Transparent" 
      MouseLeftButtonUp="Canvas_MouseLeftButtonUp" /> 
</Grid> 

をあなたのような場所を得ることができますこれは:

private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
{ 
    Location loc = AustralianMap.ViewportPointToLocation(e.GetPosition(AustralianMap)); 

    System.Diagnostics.Trace.TraceInformation("Hit location {0}", loc); 
} 

ここではBing Maps WPF Control API Referenceです。

1

あなたは自分で処理することにより、マップの対応するイベントを無効にすることができます。また、値の与えられた範囲にマップの移動を制限するために、次のコードを使用して試すことができます。

次のコードが設けられた座標にマップを制限し、また提供ズームレベルにそれを制限します。必要に応じて、AerialCustomModeの間で前後に切り替えることができます。 注:これはSilverlightのコードであると私はWPFのマップコントロールを台無しことがないので、これが動作する場合、私は肯定的ではないと思います。

public class CustomMode : MercatorMode { 
    protected static Range<double> validLatitudeRange = new Range<double>(-45.58328975600631, -8.320212289522944); 
    protected static Range<double> validLongitudeRange = new Range<double>(110.7421875, 156.533203125); 

    protected override Range<double> GetZoomRange(Location center) { 
     return new Range<double>(3, 3.8); 
    } 

    public override bool ConstrainView(Location center, ref double zoomLevel, ref double heading, ref double pitch) { 
     bool isChanged = base.ConstrainView(center, ref zoomLevel, ref heading, ref pitch); 

     double newLatitude = center.Latitude; 
     double newLongitude = center.Longitude; 

     if(center.Longitude > validLongitudeRange.To) { 
      newLongitude = validLongitudeRange.To; 
     } else if(center.Longitude < validLongitudeRange.From) { 
      newLongitude = validLongitudeRange.From; 
     } 

     if(center.Latitude > validLatitudeRange.To) { 
      newLatitude = validLatitudeRange.To; 
     } else if(center.Latitude < validLatitudeRange.From) { 
      newLatitude = validLatitudeRange.From; 
     } 

     if(newLatitude != center.Latitude || newLongitude != center.Longitude) { 
      center.Latitude = newLatitude; 
      center.Longitude = newLongitude; 
      isChanged = true; 
     } 

     Range<double> range = GetZoomRange(center); 
     if(zoomLevel > range.To) { 
      zoomLevel = range.To; 
      isChanged = true; 
     } else if(zoomLevel < range.From) { 
      zoomLevel = range.From; 
      isChanged = true; 
     } 

     return isChanged; 
    } 
} 
+0

この回答は参考になりましたが、私はそれをうまく利用していますが、もう1つは実装が簡単で、何をしているのか細かいことです。これは将来のプロジェクトの良い例ですが、ありがとうございます。 –