【问题标题】:Access a featureType within a styled mapType of Google Maps在 Google 地图的样式化 mapType 中访问 featureType
【发布时间】:2015-12-03 15:57:39
【问题描述】:

在例如maps.amsterdam.nl/hoegroot 我使用不同风格的地图类型:Google Light、Google Dark 和 Google Grey。我想在不更改整个 mapType 的情况下使用按钮打开/关闭所有标签。我正在寻找一种仅通过 Javascript 设置功能类型标签的可见性的方法:

{featureType:'label', stylers:[{visibility:'offon'}]}

如何访问 MapType 中的 featureType?

【问题讨论】:

    标签: google-maps-api-3 google-maps-styled


    【解决方案1】:

    获取de mapTypes的样式。

    标签关闭时在数组末尾推送一个样式。

    标签打开时在数组末尾弹出此样式。

    function doLabels() {
    var theCurrentMapType = theMap.getMapTypeId();
    var theMapTypes = ['GOOGLE_LIGHT', 'GOOGLE_DARK', 'GOOGLE_GREY'];
    for (i = 0; i < theMapTypes.length; i++) { // change all maptypes, to hold labels on/off
        var theMapStyles = theMap.mapTypes[theMapTypes[i]].styles;
        if ($('#labelsonoff input').is(":checked")) theMapStyles.pop();
        else theMapStyles.push({featureType:'all', elementType:'labels', stylers:[{visibility:'off'}]});            
    }   
    theMap.setMapTypeId('GOOGLE_WHITE'); // change first to other maptype
    theMap.setMapTypeId(theCurrentMapType);     // then back to current maptype
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多