我正在创建一个使用apiv3 for Google Maps的可视化。目前,我在地图上绘制了几千个多边形,还有一些标记。问题是我试图绘制的一些区域被认为是“多重多边形”。例如,投票区有多个区域,这些区域是分开的,而不是连接在一个多边形中。我该如何画这个?
试过这个,但它似乎没有渲染。
var Poly14591;
var outer = new google.maps.MVCArray([new google.maps.LatLng( 42.862496, -78.151154), new google.maps.LatLng( 42.862251, -78.151319), new google.maps.LatLng( 42.86189, -78.151538), new google.maps.LatLng( 42.861765, -78.151647)]);
var inner = new google.maps.MVCArray([new google.maps.LatLng( 42.867545, -78.151817), new google.maps.LatLng( 42.866978, -78.151813), new google.maps.LatLng( 42.866044, -78.151787), new google.maps.LatLng( 42.864956, -78.151712), new google.maps.LatLng( 42.864231, -78.151709), new google.maps.LatLng( 42.863593, -78.151708)]);
var paths = new google.maps.MVCArray([outer, inner]);
Poly14591 = new google.maps.Polygon({paths:paths, strokeOpacity: 10.0, strokeWeight: 20, strokeColor: "#FF0000", fillColor: "#FF0000", fillOpacity: 0.35});
Poly14591.setMap(map);
答案 0 :(得分:0)
这实际上似乎允许我映射单独的多边形,这些多边形实际上仍然在单个谷歌地图多边形对象的上下文中。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polygon</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
// This example creates a simple polygon representing the Bermuda Triangle.
function initialize() {
var mapOptions = {
zoom: 5,
center: new google.maps.LatLng(24.886436490787712, -70.2685546875),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var bermudaTriangle;
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var Poly14591;
var paths = [[new google.maps.LatLng( 42.862496, -78.151154), new google.maps.LatLng( 42.862251, -78.151319), new google.maps.LatLng( 42.86189, -78.151538), new google.maps.LatLng( 42.861765, -78.151647)], [new google.maps.LatLng( 42.867545, -78.151817), new google.maps.LatLng( 42.866978, -78.151813), new google.maps.LatLng( 42.866044, -78.151787), new google.maps.LatLng( 42.864956, -78.151712), new google.maps.LatLng( 42.864231, -78.151709), new google.maps.LatLng( 42.863593, -78.151708)]];
Poly14591 = new google.maps.Polygon({paths:paths, strokeOpacity: 10.0, strokeWeight: 20, strokeColor: "#FF0000", fillColor: "#FF0000", fillOpacity: 0.35});
Poly14591.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>