私はいくつかのマップに取り組んでいますが、非常に基本的なものに行き詰まっています。
私がやっていることの要点は、マップに 10 個のフラグを追加することです。ピンの位置に基づいてズーム レベルとマップの中心を動的に設定する必要があります (マップは可能な限りズームインする必要があります。すべてのピンを表示)。
これは、介入なしで (予想どおり) MultiMap で予想どおりに機能しますが、Virtual Earth マップは適切に機能しません。中央の緯度/経度を指定しないと、デフォルトで米国全体が表示されます。
これを機能させるために、誰かが私を正しい方向に向けることができますか?
編集:
OK、MVCコントローラーで次を使用して、適切な中心を計算できました
''# we're going to rock the AVERAGE LAT/LON here
Dim eventCount As Integer = 0
Dim totalLat As Double = 0
Dim totalLon As Double = 0
For Each mel In MapEventList
totalLat += mel.lat
totalLon += mel.lon
eventCount += 1
Next
ViewData("centerLat") = totalLat / eventCount
ViewData("centerLon") = totalLon / eventCount
今、私は最高のズームレベルを計算しようとして立ち往生しています
編集2:
そのため、コントローラーから計算を削除し、Javascript に追加しました。スクリプトの重量は非常に軽いですが、サーバーではなくクライアント マシンによって計算が行われます (サイトが大量のヒットを取得し始めた場合に価値があります)。
$(document).ready(function () {
// Load the Bing Map and populate it
var increment = 0; // used to increment event locations
var sumLat = 0; // used to find the average LAT location
var sumLon = 0; // used to find the average LON location
// Load the initial map
LoadMap();
// loop through all events and place a point on the map
// also add to the sumLat and sumLon variable
$.each(json_object, function () {
increment = ++increment;
sumLat = sumLat + this.lat;
sumLon = sumLon + this.lon;
LoadPoint(this.lat, this.lon, this.title, this.desc, increment);
});
// find the averate Lat and Lon for map centering
var centerLat = sumLat / increment;
var centerLon = sumLon / increment;
LatLon = new VELatLong(centerLat, centerLon);
// Set the new map Center based on the average of all points.
map.SetCenter(LatLon)
});
function LoadMap() {
map = new VEMap('bingMap');
mapOptions = new VEMapOptions
// sets map options for asthetics
mapOptions.DashboardColor = "black";
mapOptions.EnableDashboardLabels = false;
mapOptions.EnableBirdseye = false;
mapOptions.EnableDashboardLabels = false;
// Load the initial map
// note: the LatLon is "null" at this point because we are going to
// center the map later based on the average of all points.
map.LoadMap(null, zoomLevel, null, null, null, false, null, mapOptions);
};
function LoadPoint(lat, lon, title, desc, pinId) {
var point = new VELatLong(lat, lon);
var pin = new VEShape(VEShapeType.Pushpin, point);
pin.SetTitle(title);
pin.SetDescription(desc + "<br /><br />lat: " + lat + " lon: " + lon);
pin.SetCustomIcon("<div class='pinStyle'><div class='pinText'>" + pinId + "</div></div>");
map.AddShape(pin);
};