gpt4 book ai didi

google-maps-api-3 - 地面透明

转载 作者:行者123 更新时间:2023-12-04 07:48:29 27 4
gpt4 key购买 nike

我有一个在线 map ,其中包含一个地面覆盖的图像,并且希望将图像设为半透明的,以便基础 map 能够显示出来。是否可以向该叠加层添加透明度值?

http://www.tpwd.state.tx.us/fishboat/fish/recreational/lakes/ingulf1c.phtml

这是地面覆盖层的代码:

var imageBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(25.71438633861514, -98.33555959121725),
new google.maps.LatLng(30.40813339247205, -93.57953893270167));


function initialize() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(28.0041,-96.3618),
zoom: 7,
mapTypeId: 'roadmap'
});
overlay = new google.maps.GroundOverlay(
'/fishboat/fish/recreational/lakes/images/statemaps/gulfregion.gif',
imageBounds);
overlay.setMap(map);

最佳答案

有一个setOpacity method of the GroundOverlay(适用于我的值在0到1.0之间):

var overlay = null;

function initialize() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(28.0041,-96.3618),
zoom: 7,
mapTypeId: 'roadmap'
});
overlay = new google.maps.GroundOverlay('http://www.tpwd.state.tx.us/fishboat/fish/recreational/lakes/images/statemaps/gulfregion.gif',
imageBounds);
overlay.setMap(map);

}

google.maps.event.addDomListener(window, 'load', initialize);

function setOpacity() {
var opacityStr = document.getElementById('opacity').value;
var opacity = parseFloat(opacityStr);
overlay.setOpacity(opacity);
}

<input type="text" id="opacity" value="0.2"></input>
<input type="button" value="setOpacity" onclick="setOpacity();"></input>

working example- proof of concept fiddle

screenshot of resulting map

代码段:

var overlay = null;

function initMap() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(28.0041, -96.3618),
zoom: 7,
mapTypeId: 'roadmap'
});

var imageBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(25.71438633861514, -98.33555959121725),
new google.maps.LatLng(30.40813339247205, -93.57953893270167));

overlay = new google.maps.GroundOverlay(
'http://www.tpwd.state.tx.us/fishboat/fish/recreational/lakes/images/statemaps/gulfregion.gif',
imageBounds);
overlay.setMap(map);
map.fitBounds(imageBounds);
}

function setOpacity() {
var opacityStr = document.getElementById('opacity').value;
var opacity = parseFloat(opacityStr);
overlay.setOpacity(opacity);
}
html,
body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}

#map {
width: 100%;
height: 90%;
}
<div id="map"></div>
<input type="text" id="opacity" value="0.2" />
<input type="button" value="setOpacity" onclick="setOpacity();" />

<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap"></script>

关于google-maps-api-3 - 地面透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20620073/

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