首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更新geoxml3上的中心点

更新geoxml3上的中心点
EN

Stack Overflow用户
提问于 2015-02-06 12:40:37
回答 1查看 403关注 0票数 0

我使用geoxml3进行了加载和样式设计。现在我想更新地图,只改变中心点和缩放级别。我怎样才能做到这一点。

代码语言:javascript
复制
var latlng = new google.maps.LatLng(29.722601, -11.681680); 
    var myOptions = {
            zoom : 1,
            //minZoom:2,
            maxZoom:10,
            center : latlng,
            //disableDefaultUI: true,
            streetViewControl: false,
            mapTypeControl: false,
            panControl: true,
            zoomControl: true,
            suppressInfoWindows : true,
            preserveViewport : true,
            scrollwheel: false,
            styles:style
        };

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var geoXml = new geoXML3.parser({
        map: map,
        singleInfoWindow: false,
        afterParse: useTheData,
        suppressInfoWindows : true,
        zoom : false
    });
    geoXml.parse(url_kml+'basins.kml');

一旦加载了上述内容,我希望使用onclick来应用chnage。我的onclick运行在js函数下面

代码语言:javascript
复制
function updatekmmap(region){
    console.log(region);
    console.log(map);
    var latlng = new google.maps.LatLng(29.722601, -11.681680);
    //
    switch(region){
    case "north":
        latlng = new google.maps.LatLng(56.065192, -104.814452); 
        break;
    }
    gMap = new google.maps.Map(document.getElementById('map_canvas')); 
    gMap.setZoom(10);      // This will trigger a zoom_changed on the map
    gMap.setCenter(latlng);

}

这不保留原来的风格等等。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-06 13:45:43

我现在让它起作用了。我在重新创建地图对象。

代码语言:javascript
复制
function updatekmmap(region){
    console.log(region);
    console.log(map);
    var latlng = new google.maps.LatLng(29.722601, -11.681680);
    //
    switch(region){
        case "north":
            latlng = new google.maps.LatLng(31.137854, -90.256931); 
            break;
        case "south":
            latlng = new google.maps.LatLng(31.137854, -90.256931); 
            break;
        case "caribbean":
            latlng = new google.maps.LatLng(31.137854, -90.256931); 
            break;
        case "eu":
            latlng = new google.maps.LatLng(50.352658, -9.316490); 
            break;
        case "med":
            latlng = new google.maps.LatLng(37.309248, 18.786537); 
            break;
        case "africa":
            latlng = new google.maps.LatLng(-14.933886, -59.495213); 
            break;
        case "asia":
            latlng = new google.maps.LatLng(31.137854, -90.256931); 
            break;
    }
    //gMap = new google.maps.Map(document.getElementById('map_canvas')); 
    map.setZoom(3);      // This will trigger a zoom_changed on the map
    map.setCenter(latlng);
    //console.log( geoXml.getDefaultBounds());
    //return false;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28366016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档