虚拟地球/ Bing地图 - 如何计算最佳变焦状态 [英] Virtual Earth / Bing Maps - How To Calculate Best Zoom Level

查看:196
本文介绍了虚拟地球/ Bing地图 - 如何计算最佳变焦状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一些地图的东西,我坚持的东西,这似乎是很基本的。

的什么,我做的是增加10标志地图,我需要动态设置基于引脚(图需要在尽可能被放大的位置在地图的缩放级别和中心的要点可能同时还显示所有引脚)。

这工作完全与Multimap之预期没有任何干预(如预期),但虚拟地球地图没有发挥好。如果我不给它一个中心纬度/经度,则默认为显示所有美国。

任何人都可以点我在正确的方向,为了得到这个工作?

修改

好吧,我是能够通过使用来计算适当的中心在我的MVC控制器以下

 ''#我们要在这里摇滚平均LAT / LON
昏暗EVENTCOUNT为整数= 0
昏暗totalLat为双= 0
昏暗totalLon为双= 0
对于每个梅尔MapEventList
    totalLat + = mel.lat
    totalLon + = mel.lon
    EVENTCOUNT + = 1
下一个
ViewData的(centerLat)= totalLat / EVENTCOUNT
ViewData的(centerLon)= totalLon / EVENTCOUNT

现在我只是坚持尝试计算在最佳变焦状态

修改2:

所以,我已经移除了控制器计算并把它添加到我的javascript。脚本的重量很轻,但将有由客户机来完成计算,而不是我的服务器(如果有价值/时,该网站开始越来越命中桩)

  $(文件)。就绪(函数(){
    //装载了Bing地图和填充它
    VAR增量= 0; //用于增加活动场所
    变种sumLat = 0; //用于找到平均LAT位置
    变种sumLon = 0; //用于找到平均LON位置    //加载初始地图
    LoadMap();    //遍历所有事件,然后将地图上的点
    //也增加了sumLat和sumLon变量
    $。每个(JSON_OBJECT,函数(){
        增量= ++增量;
        sumLat = sumLat + this.lat;
        sumLon = sumLon + this.lon;
        LOADPOINT(this.lat,this.lon,this.title,this.desc,增量);
    });    //找到averate纬度和经度在地图定心
    VAR centerLat = sumLat /增量;
    VAR centerLon = sumLon /增量;
    LatLon =新VELatLong(centerLat,centerLon);    //设置的基础上平均所有点的新地图中心。
    map.SetCenter(LatLon)
});功能LoadMap(){
    地图=新VEMap('bingMap');
    的MapOptions =新VEMapOptions    //设置asthetics地图选项
    mapOptions.DashboardColor =黑色;
    mapOptions.EnableDashboardLabels = FALSE;
    mapOptions.EnableBirdseye = FALSE;
    mapOptions.EnableDashboardLabels = FALSE;    //加载初始地图
    //注:LatLon是空在这一点上,因为我们要
    //地图中心后基于平均所有点的。
    map.LoadMap(NULL,个zoomLevel,NULL,NULL,NULL,假,空,的MapOptions);};功能载入点(纬度,经度,标题,说明,pinId){
    VAR点=新VELatLong(纬度,经度);
    VAR引脚=新VEShape(VEShapeType.Pushpin,点);
    pin.SetTitle(职称);
    pin.SetDescription(DESC +< BR />< BR />纬度:+纬度+LON:+ LON);
    pin.SetCustomIcon(< D​​IV CLASS ='pinStyle'>< D​​IV CLASS ='pinText'>中+ pinId +< / DIV>< / DIV>中);
    map.AddShape(PIN);
};

但是我仍然停留试图计算出最佳的缩放级别


解决方案

如果您使用的是JavaScript版本,那么你不需要来计算的话,可以直接给数组VELatLong反对的 VEMap.SetMapView ,而且将集中+变焦,使所有引脚均可见。

I'm working on some map stuff and I'm stuck with something that seems to be quite basic.

The gist of what I'm doing is adding 10 flags to a map, and I need to dynamically set the zoom level and center of the map based on the position of the pins (map needs to be zoomed in as far as possible while still showing all pins).

This works exactly as expected with MultiMap without any intervention (as expected), but the Virtual Earth map doesn't play nice. If I don't give it a center Lat/Lon, it defaults to showing all of the USA.

Can anyone point me in the right direction in order to get this working?

EDIT:

Ok, I was able to calculate the proper center by using the following in my MVC Controller

''# 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

Now I'm just stuck trying to calculate the Best Zoom Level

EDIT 2:

So I've removed the calculations from my controller and added it to my Javascript. The weight of the script is quite light, but will have the calculations done by the client machine and not my server (valuable if/when the site starts getting piles of hits)

$(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);
};

However I'm still stuck trying to calculate the Best Zoom Level

解决方案

If you are using the javascript version, then you don't need to calculate it, you can directly give the array of VELatLong objects to VEMap.SetMapView, and it will center + zoom so that all pins are visible.

这篇关于虚拟地球/ Bing地图 - 如何计算最佳变焦状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆