【问题标题】:Transparent color overlay to Google Satellite map?谷歌卫星地图的透明颜色叠加?
【发布时间】:2014-02-04 13:56:16
【问题描述】:

我需要为 Google 卫星地图应用颜色。

我知道可以设置 RoadMaps 的样式,但 API 文档说这对于卫星图像是不可能的 - 我猜是因为它们是照片。

但是我可以使用平铺透明 PNG 图层来达到预期的效果吗?着色层上方仍有可点击标记?

API 文档描述了多边形叠加,但示例都附加到纬度点。我想覆盖整个画布。

【问题讨论】:

    标签: javascript google-maps


    【解决方案1】:

    文档中有一个相当简单的自定义地图示例:

    https://google-developers.appspot.com/maps/documentation/javascript/examples/full/maptype-overlay

    将该示例中的 getTile 例程更改为以下版本会产生绿色覆盖,标记和信息窗口仍按预期工作(未经过特别好的测试):

    CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
      var div = ownerDocument.createElement('div');
      div.style.width = this.tileSize.width + 'px';
      div.style.height = this.tileSize.height + 'px';
      div.style.fontSize = '10';
      div.style.backgroundColor = '#00FF00';
      div.style.opacity = 0.4;
      return div;
    };
    

    Working example

    代码 sn-p:

    /** @constructor */
    function CoordMapType(tileSize) {
      this.tileSize = tileSize;
    }
    
    CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
      var div = ownerDocument.createElement('div');
      //  div.innerHTML = coord;
      div.style.width = this.tileSize.width + 'px';
      div.style.height = this.tileSize.height + 'px';
      div.style.fontSize = '10';
      //  div.style.borderStyle = 'solid';
      //  div.style.borderWidth = '1px';
      //  div.style.borderColor = '#AAAAAA';
      div.style.backgroundColor = '#00FF00';
      div.style.opacity = 0.4;
      return div;
    };
    
    var map;
    var chicago = new google.maps.LatLng(41.850033, -87.6500523);
    
    function initialize() {
      var mapOptions = {
        zoom: 10,
        center: chicago,
        mapTypeId: google.maps.MapTypeId.HYBRID
      };
      map = new google.maps.Map(document.getElementById('map-canvas'),
        mapOptions);
    
      var marker = new google.maps.Marker({
        position: chicago,
        title: "test",
        map: map
      });
      var infowindow = new google.maps.InfoWindow({});
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent("Hello<br>" + marker.getPosition().toUrlValue(6));
        infowindow.open(map, marker);
      });
    
      // Insert this overlay map type as the first overlay map type at
      // position 0. Note that all overlay map types appear on top of
      // their parent base map.
      map.overlayMapTypes.insertAt(
        0, new CoordMapType(new google.maps.Size(256, 256)));
    }
    
    google.maps.event.addDomListener(window, 'load', initialize);
    html,
    body,
    #map-canvas {
      height: 100%;
      margin: 0px;
      padding: 0px
    }
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
    <div id="map-canvas"></div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-29
      • 2017-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 2011-08-24
      相关资源
      最近更新 更多