1

私はいくつかのマップに取り組んでいますが、非常に基本的なものに行き詰まっています。

私がやっていることの要点は、マップに 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);
};

ただし、ベストズームレベルを計算しようとしてまだ行き詰まっています

4

3 に答える 3

3

JavaScript バージョンを使用している場合は、計算する必要はありません。VELatLong オブジェクトの配列を VEMap.SetMapView に直接渡すとすべてのピンが表示されるように中央揃え + ズームされます。

于 2010-11-10T16:16:22.923 に答える
1

同様の問題があったとき、ピンの(大まかな)重心を計算して解決しました。「ラフ」と言うのは、各ポイントの緯度/経度を平均しただけで、地球は球体であるため正しくありません。

于 2010-11-06T21:12:16.517 に答える
0

答えてくれてありがとう@wildpeaks。正しい方向に微調整する必要がある他の人のために、ここに私の結果を投稿しました。

$(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
    var latlonArray = new Array();  // used to create an Array of lat and lon in order to "SetMapView"

    // 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 () {
        latlonArray[increment] = new VELatLong(this.lat, this.lon); // Add to the array before the increment
        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 latlonCenter = new VELatLong(sumLat / increment, sumLon / increment);

    // Set the new map Center based on the average of all points.
    map.SetCenter(latlonCenter);
    map.SetMapView(latlonArray); // pass the latlonArray object to the SetMapView in order to display all map pins appropriately.

});
于 2010-11-10T20:57:13.417 に答える