はじめに
前回に引き続いて今回もBing Map App SDKの紹介です。前回はごく簡単なアプリケーションを作り,
- パネルの追加
- レイヤーのシリアライズ
今回作成するMap Appは,
プラグイン クラスの作成
最初にMap Appのプロジェクトおよびプラグイン クラスを作りましょう。前回と同様ですので,
プロジェクトはC#のSilverlightクラス ライブラリ プロジェクトです。プロジェクト作成後,
続いて,
namespace CapitalCitiesBingMapApp
{
using System;
using Microsoft.Maps.Core;
using Microsoft.Maps.Plugins;
public class CapitalCitiesPlugin : Plugin
{
private Layer mainLayer;
[ImportSingle("Microsoft/MapContract", ImportLoadPolicy.Synchronous)]
public MapContract DefaultMap { get; set; }
[ImportSingle("Microsoft/LayerManagerContract", ImportLoadPolicy.Synchronous)]
public LayerManagerContract LayerManagerContract { get; set; }
[ImportSingle("Microsoft/PushpinFactoryContract", ImportLoadPolicy.Synchronous)]
public PushpinFactoryContract PushpinFactoryContract { get; set; }
public override void Initialize()
{
// (後で編集)
}
public override void Activate(System.Collections.Generic.IDictionary<string, string> activationParameters)
{
if (LayerManagerContract.ContainsLayer(this.mainLayer))
{
LayerManagerContract.BringToFront(this.mainLayer);
}
else
{
LayerManagerContract.AddLayer(this.mainLayer);
}
}
}
}
エンティティの作成
エンティティとはプッシュピンなどの地図上に表示するアイテムでした。前回のコードでは,
プロジェクトに新しいクラスを追加して,
namespace CapitalCitiesBingMapApp
{
using Microsoft.Maps.Core;
public class CityEntity : Entity
{
public string Name { get; set; }
}
}
レイヤーの作成
続いてレイヤーを作成しましょう。レイヤーには県庁所在地を示すエンティティを追加します。また,
前回のコードではエンティティの追加を,
XMLファイルの追加
県庁所在地の名前と経緯度情報は,
プロジェクトに新しい項目としてXMLファイルを追加します
図3 埋め込まれたリソース
XMLファイルの内容は次のように,
<?xml version="1.0" encoding="utf-8" ?>
<Pushpins>
<Pushpin Name="札幌市" Latitude="43.0646147" Longitude="141.3468074" />
<Pushpin Name="青森市" Latitude="40.8243077" Longitude="140.7399984" />
<Pushpin Name="盛岡市" Latitude="39.7036194" Longitude="141.1526839" />
(省略)
<Pushpin Name="鹿児島市" Latitude="31.5610825" Longitude="130.5577279" />
<Pushpin Name="那覇市" Latitude="26.2124013" Longitude="127.6809317" />
</Pushpins>
以上でXMLファイルの準備は完了です。内容からわかるように別に県庁所在地である必要はなく,