gpt4 book ai didi

javascript - 透明颜色叠加到谷歌卫星 map ?

转载 作者:行者123 更新时间:2023-11-29 18:18:15 25 4
gpt4 key购买 nike

我需要对 Google 卫星 map 应用色调。

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

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

API 文档描述了多边形叠加层,但示例都附在经纬度点上。我想覆盖整个 Canvas 。

最佳答案

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

https://google-developers.appspot.com/maps/documentation/javascript/examples/full/maptype-overlay (不再工作)

above link no longer works, version on archive.org

将该示例中的 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

screenshot of resulting map

代码片段:

/** @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>

关于javascript - 透明颜色叠加到谷歌卫星 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21148582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com