在 angular-google-maps 中,如何只显示我的自定义图块?

In angular-google-maps, how do I show ONLY my custom tiles?

我可以显示我的自定义图块,但浏览器还在其下方加载 Google 的标准地图图块。如果用户平移到边缘,这会降低性能并使地图看起来很奇怪。知道如何防止法线贴图层吗?

Demo

最后,我最终避免了 ui-gmap-map-type 指令,尽管我保留了父 ui-gmap-google-map. Instead, I waited for the google.maps & $scope.map.control objects to load, then I used the mapTypes.set() 方法来指向我自己的图像块集。

index.html

<ui-gmap-google-map control='map.control'>
  <!-- marker & polygon directives -->
</ui-gmap-google-map>

controller.js

$scope.map = {
  control: {}
};

uiGmapGoogleMapApi.then(function(maps) {
    var moonMapType = new maps.ImageMapType({
      getTileUrl: function(coord, zoom) {
          var normalizedCoord = getNormalizedCoord(coord, zoom);
          if (!normalizedCoord) {
            return null;
          }
          var bound = Math.pow(2, zoom);
          return 'http://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw' +
              '/' + zoom + '/' + normalizedCoord.x + '/' +
              (bound - normalizedCoord.y - 1) + '.jpg';
      },
      tileSize: new maps.Size(256, 256),
      maxZoom: 9,
      minZoom: 0,
      radius: 1738000,
      name: 'Moon'
    });

    $scope.$watch("map.control", function( mapControl, emptyObj ) {
      mapControl.mapTypes.set('moon', moonMapType);
      mapControl.setMapTypeId('moon');
    });
  }

  // Normalizes the coords that tiles repeat across the x axis (horizontally)
  // like the standard Google map tiles.
  function getNormalizedCoord(coord, zoom) {
    var y = coord.y;
    var x = coord.x;

    // tile range in one direction range is dependent on zoom level
    // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc
    var tileRange = 1 << zoom;

    // don't repeat across y-axis (vertically)
    if (y < 0 || y >= tileRange) {
      return null;
    }

    // repeat across x-axis
    if (x < 0 || x >= tileRange) {
      x = (x % tileRange + tileRange) % tileRange;
    }

    return {x: x, y: y};
  }
});