我正在开发一些东西,利用 Google Maps API 使用 GeoJSON 绘制 n
个多边形。我成功地绘制了它,但我还想增加所绘制多边形的不透明度
,并删除每个多边形上丑陋的轮廓。
我浏览了 Google Maps API 的文档 here ,但它只告诉你如何加载GeoJSON文件,而不是修改绘制多边形的特征。
map.data.loadGeoJson('google.json');
上面是加载 GeoJSON 的方式以及您可以使用的唯一命令。我知道我似乎没有尝试过任何事情,但我已经尝试过,而且没有一个足够重要到可以包含在这个问题中。
所以我的问题是 - 如何从 GeoJSON 绘制图像中删除轮廓并增加不透明度?
下面也是它当前的样子:
最佳答案
在样式选项中使用 fillOpacity: 1
和 StrokeWeight: 0
https://plnkr.co/edit/puMK8mAskLiaExmNKIEI?p=preview
<!DOCTYPE html>
<html>
<head>
<title>Data Layer: Styling</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: {lat: -28, lng: 137}
});
// Load GeoJSON.
map.data.loadGeoJson(
'https://storage.googleapis.com/mapsdevsite/json/google.json');
// Set the stroke width, and fill color for each polygon
map.data.setStyle(function(feature) {
var color = feature.getProperty('color');
return {
fillColor: color,
fillOpacity: 1,
strokeWeight: 0
};
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?callback=initMap">
</script>
</body>
</html>
关于javascript - 在 Google Maps API 上的 GeoJSON 绘制的多边形中删除轮廓并增加不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49501886/