CJW*_*WEB 2 javascript google-maps
我需要对 Google 卫星地图应用色调。
我知道可以设置路线图的样式,但 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;
};
Run Code Online (Sandbox Code Playgroud)
代码片段:
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;
};
Run Code Online (Sandbox Code Playgroud)
/** @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);
Run Code Online (Sandbox Code Playgroud)
html,
body,
#map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3110 次 |
最近记录: |