【发布时间】:2014-02-04 13:56:16
【问题描述】:
我需要为 Google 卫星地图应用颜色。
我知道可以设置 RoadMaps 的样式,但 API 文档说这对于卫星图像是不可能的 - 我猜是因为它们是照片。
但是我可以使用平铺透明 PNG 图层来达到预期的效果吗?着色层上方仍有可点击标记?
API 文档描述了多边形叠加,但示例都附加到纬度点。我想覆盖整个画布。
【问题讨论】:
我需要为 Google 卫星地图应用颜色。
我知道可以设置 RoadMaps 的样式,但 API 文档说这对于卫星图像是不可能的 - 我猜是因为它们是照片。
但是我可以使用平铺透明 PNG 图层来达到预期的效果吗?着色层上方仍有可点击标记?
API 文档描述了多边形叠加,但示例都附加到纬度点。我想覆盖整个画布。
【问题讨论】:
文档中有一个相当简单的自定义地图示例:
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;
};
代码 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>
【讨论】: