我正在尝试绘制一个带孔的矩形多边形.我的问题是我无法创建覆盖整个世界的多边形.多边形被反转,因此只选择一条线而不是整个世界.
下面是我能够做出的最大选择的例子.例如,如果我试图改变0(行中的新google.maps.LatLng(-85.1054596961173,0)),以任何其他值用于反转的选择.
也许我错过了一些明显的东西,但我似乎无法让它发挥作用.
function initialize() {
var mapOptions = {
zoom: 1,
center: new google.maps.LatLng(24.886436490787712, -70.2685546875),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var worldCoords = [
new google.maps.LatLng(-85.1054596961173, -180),
new google.maps.LatLng(85.1054596961173, 180),
new google.maps.LatLng(85.1054596961173, 180),
new google.maps.LatLng(-85.1054596961173,0)
];
var EuropeCoords = [
new google.maps.LatLng(29.68224948021748, -23.676965750000022),
new google.maps.LatLng(29.68224948021748, 44.87772174999998),
new google.maps.LatLng(71.82725578445813, 44.87772174999998),
new google.maps.LatLng(71.82725578445813, -23.676965750000022)
];
// Construct the polygon.
poly = new google.maps.Polygon({
paths: [worldCoords,EuropeCoords],
strokeColor: '#000000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#000000',
fillOpacity: 0.35
});
poly.setMap(map);
}
Run Code Online (Sandbox Code Playgroud)
geo*_*zip 11
您需要使外多边形的缠绕方向与内多边形的方向相反并添加一个点:
var worldCoords = [
new google.maps.LatLng(-85.1054596961173, -180),
new google.maps.LatLng(85.1054596961173, -180),
new google.maps.LatLng(85.1054596961173, 180),
new google.maps.LatLng(-85.1054596961173, 180),
new google.maps.LatLng(-85.1054596961173, 0)
];
Run Code Online (Sandbox Code Playgroud)
工作代码片段:
function initialize() {
var mapOptions = {
zoom: 1,
center: new google.maps.LatLng(24.886436490787712, -70.2685546875),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var worldCoords = [
new google.maps.LatLng(-85.1054596961173, -180),
new google.maps.LatLng(85.1054596961173, -180),
new google.maps.LatLng(85.1054596961173, 180),
new google.maps.LatLng(-85.1054596961173, 180),
new google.maps.LatLng(-85.1054596961173, 0)];
var EuropeCoords = [
new google.maps.LatLng(29.68224948021748, -23.676965750000022),
new google.maps.LatLng(29.68224948021748, 44.87772174999998),
new google.maps.LatLng(71.82725578445813, 44.87772174999998),
new google.maps.LatLng(71.82725578445813, -23.676965750000022)];
// Construct the polygon.
poly = new google.maps.Polygon({
paths: [worldCoords, EuropeCoords],
strokeColor: '#000000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#000000',
fillOpacity: 0.35
});
poly.setMap(map);
}
initialize();Run Code Online (Sandbox Code Playgroud)
<script src="http://maps.googleapis.com/maps/api/js"></script>
<div id="map-canvas" style="width:500px;height:500px;"></div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2944 次 |
| 最近记录: |