Google maps Google Maps API v.3将多段线转换为具有给定宽度的多边形

Google maps Google Maps API v.3将多段线转换为具有给定宽度的多边形,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我正在寻找将多段线(从2个坐标创建)转换为至少包含4个坐标的多边形的方法。简单的使用案例是航空地图上的航路,它从A点开始,在B点结束,宽度为x海里。虚拟代码是: var someLine = new google.maps.Polyline({ path: [ {lat: 51.15, lng: 15}, {lat: 51.15, lng: 18} ], geodesic: true, strokeColor: '#000000',

我正在寻找将多段线(从2个坐标创建)转换为至少包含4个坐标的多边形的方法。简单的使用案例是航空地图上的航路,它从A点开始,在B点结束,宽度为x海里。虚拟代码是:

var someLine = new google.maps.Polyline({
    path: [
        {lat: 51.15, lng: 15},
        {lat: 51.15, lng: 18}
    ],
    geodesic: true,
    strokeColor: '#000000',
    strokeOpacity: 1.0,
    strokeWeight: 5
});
someLine.setMap(map);

// how to convert above someLine into?:
var airway = new google.maps.Polygon({
    paths: [
        {lat: 51, lng: 15},
        {lat: 51, lng: 18},
        {lat: 51.3, lng: 18},
        {lat: 51.3, lng: 15}
    ],
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 3,
    fillColor: '#FF0000',
    fillOpacity: 0.35,
    geodesic: true
});
airway.setMap(map);
这看起来像:

其中黑线为公共多段线,红色多边形为理想效果


是否有任何API/插件可用于此任务,或者我需要手动计算多边形的角点?

一个选项是使用根据风道宽度和中心线计算多边形。如果使用米(而不是海里,这只是一个转换)指定空中通道的宽度:

代码片段:

var地理编码器;
var映射;
函数初始化(){
var map=new google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var someLine=new google.maps.Polyline({
路径:[{
拉脱维亚:51.15,
液化天然气:15
}, {
拉脱维亚:49.15,
液化天然气:18
}],
测地线:正确,
strokeColor:“#000000”,
笔划不透明度:1.0,
冲程重量:5
});
setMap(map);
var线宽=10000;/(米)
var lineHeading=google.maps.geometry.spherical.computeHeading(someLine.getPath().getAt(0),someLine.getPath().getAt(1));
var p0a=google.maps.geometry.spherical.computeOffset(someLine.getPath().getAt(0),线宽,行标题+90);
var p0b=google.maps.geometry.spherical.computeOffset(someLine.getPath().getAt(0),线宽,行标题-90);
var p1a=google.maps.geometry.spherical.computeOffset(someLine.getPath().getAt(1),线宽,行标题+90);
var p1b=google.maps.geometry.spherical.computeOffset(someLine.getPath().getAt(1),线宽,行标题-90);
//如何将上面的某行转换为?:
var airway=new google.maps.Polygon({
路径:[p0a、p0b、p1b、p1a],
strokeColor:“#FF0000”,
笔划不透明度:0.8,
冲程重量:3,
填充颜色:'#FF0000',
不透明度:0.35,
测地线:真
});
气道设置图(map);
var bounds=new google.maps.LatLngBounds();
对于(var i=0;i
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}


您必须手动计算。。谷歌地图没有“缓冲区”功能,但出于某种原因,你需要一个区域,或者只是需要一条宽线?如图所示:我有一条黑线,宽度为x海里,我需要将其转换为覆盖多段线路径的红色多边形+此宽度仅在官方文件中,航空公司被描述为从A到B的线,宽度为x英里,我需要在地图上显示它,然后你需要一个真实的区域。。我理解。。
var lineWidth = 10000; // (meters)
var lineHeading = google.maps.geometry.spherical.computeHeading(someLine.getPath().getAt(0), someLine.getPath().getAt(1));
var p0a = google.maps.geometry.spherical.computeOffset(someLine.getPath().getAt(0), lineWidth, lineHeading+90);
var p0b = google.maps.geometry.spherical.computeOffset(someLine.getPath().getAt(0), lineWidth, lineHeading-90);
var p1a = google.maps.geometry.spherical.computeOffset(someLine.getPath().getAt(1), lineWidth, lineHeading+90);
var p1b = google.maps.geometry.spherical.computeOffset(someLine.getPath().getAt(1), lineWidth, lineHeading-90);

var airway = new google.maps.Polygon({
  paths: [p0a, p0b, p1b, p1a],
  strokeColor: '#FF0000',
  strokeOpacity: 0.8,
  strokeWeight: 3,
  fillColor: '#FF0000',
  fillOpacity: 0.35,
  geodesic: true
});