ArcGIS API for Silverlight開発入門(8):プログラムでVirtual Earthを使用するサービス


SilverlightAPIにはESRIも含まれている.ArcGIS.VirtualEarth.dllクラスライブラリは、古いオーナーのVirtualEarthサービスに簡単にアクセスできます.現在SilverlightAPIで提供されているVirtualEarthサービスは、Map、Geocode、Routingの3種類がありますが、見ると2つのサービスは国内のデータにとって縁がないことがわかります.
Mapサービスを使って地図データを取得する方法を直接見てみましょう.前にSilverlightプロジェクトを新規作成し、ESRIを追加します.ArcGIS.dllとESRI.ArcGIS.VirtualEarth.dllの参照は、xmlネーミングスペースを導入し、xamlに次のように書きます.
<esri:Map x:Name="Map1" Loaded="Map1_Loaded">
            <esri:Map.Layers>
                <esriVE:TileLayer ID="VELayer" LayerStyle="AerialWithLabels" ServerType="Staging"/>
            </esri:Map.Layers>
        </esri:Map>

他のレイヤーを追加するのと基本的に同じであることがわかります.SIlverlightAPIでVEマップに対するレイヤータイプはTileLayer,LayerStyleの3種類:Road,Aerial,AerialWithLabels,それぞれベクトルマップ,映像マップ,街路表示付き映像マップに対応する.ServerTypeは比較的特殊で、StagingとProductionの2種類があり、それぞれVEサービスにアクセスするアカウントカテゴリに対応しており、前者は無料で、後者は有料です.この時点でプログラムを実行すると、TileLayerにはキーのtokenプロパティが設定されていないため、地図は見えません.
VEのサービスはかなり安全で、VEのサービスにアクセスするたびにtoken(暗号化文字列)を提供して認証を行いますが、このtokenはTokenServiceによって自動的に生成され、TokenServiceによってtokenを生成するには合法的なMicrosoft Virtual Earth Platformdeveloper accountが必要です......この過程が分かったら、私たちの仕事をしましょう.
まず、Microsoft Virtual Earth Platform developer accountを申請します.もちろん、Windows Liveアカウントが必要です.申請したこのアカウントはEvaluation版なので、後でStagingのサービスしか使えないことを決めました.Production版にするなら、メールでマイクロソフトに連絡して、料金を払うことができます.
その後、登録時に記入したメールボックスに登録して申請したMicrosoft Virtual Earth Platform developeraccountアカウントをアクティブにし、パスワードを設定します(8-14でなければなりません.大文字、小文字、数字、アルファベット以外の文字も含まれています.windows server 2008と同じです).急いで設定したパスワードを記録することをお勧めします.
いつか忘れてしまうかもしれない.このアカウントとパスワードでTokenServiceにアクセスし、tokenを生成してTileLayerのtoken属性に渡すことができます.
安全目的のためにtokenはSilverlightプログラムで直接設定することは推奨されません.では、どうしましょうか.1、SilverlightのaspxページのPage_をマウントすることでLoadメソッドは、私たちのtokenを申請し、Silverlightの初期パラメータに追加します.2、Silverlightプラグインをロードするとき、tokenを読み出します.3、Map_Loadedイベントでは、TileLayerに割り当てられます.
1、TokenServiceでtokenを申請する:
Webappでadd webreference,url用https://staging.common.virtualearth.net/find-30/common.asmx?wsdlああ、VirtualEarthServicesという名前です.TokenService.
<script language="C#" runat="Server">
    private string VEAccountID = "  ID(    AccountID)";
    private string VEAccountPassword="    ";
    
    protected void Page_Load(object sender,EventArgs e)
    {

_08_virtual_earth.Web.VirtualEarthService.TokenService.CommonService
commenservice = new
_08_virtual_earth.Web.VirtualEarthService.TokenService.CommonService();
        
        commenservice.Credentials = new System.Net.NetworkCredential(VEAccountID, VEAccountPassword);


_08_virtual_earth.Web.VirtualEarthService.TokenService.TokenSpecification
tokenSpec=new
_08_virtual_earth.Web.VirtualEarthService.TokenService.TokenSpecification();
        tokenSpec.TokenValidityDurationMinutes=480;
        if (HttpContext.Current!=null && !HttpContext.Current.Request.IsLocal)
        {
            tokenSpec.ClientIPAddress=HttpContext.Current.Request.UserHostAddress;
        } 
        else
        {
            tokenSpec.ClientIPAddress="127.0.0.1";
        }
        
        string token = "";
        token = commenservice.GetClientToken(tokenSpec);

        Xaml1.InitParameters = string.Format("token={0}", token);
    }
</script>

Xaml 1はSilverlightプラグインのID:2、Silverlightプラグインの読み込み時にこのtokenを読み出します.Appでxaml.cs:

private void Application_Startup(object sender, StartupEventArgs e)
        {
            VEtoken = e.InitParams["token"];
            this.RootVisual = new Page();
        }

3、          ,  token:
private void Map1_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (Layer layer in Map1.Layers)
                if (layer is TileLayer)
                    (layer as TileLayer).Token = (Application.Current as App).VEtoken;
        }

やっとVEの図が見えてきました.もちろん、私たちの開発口座は無料なので、地図には「Staging」の麻点がたくさんあります(tileごとに1つ):
ここまで、ArcGIS API for Silverlightの開発入門はもう終わりました.私も皆さんと同じように勉強しながら書いたので、ちょうどこの2日間SIlverlightAPIが2番目のBeta版をアップグレードしました.実はSilverlightはFlexと同じように、伝統的なWebGISに新しい魅力を放つことができ、私たちのプログラムをRIAの道を大きく前進させ、どのような効果を出すことができるかは基本的に想像力の制約にすぎない.Silverlight 3の発売に伴い、Silverlightの明日がもっと良いと信じる理由もあります.