如何在多边形下面绘制折线?

时间:2014-06-12 13:47:58

标签: javascript google-maps polygon

如何在google maps javascript中的多边形下方绘制折线?我首先绘制多边形,然后绘制折线,我不希望线条通过多边形,我希望多边形是顶层。

我像这样创建多边形和折线:

new google.maps.Polyline({
                path: googleCoordinates,
                geodesic: true,
                strokeColor: '#40FF00',
                strokeOpacity: 0.5,
                strokeWeight: 2
            });

new google.maps.Polygon({
                path: googleCoordinates,
                geodesic: true,
                strokeColor: '#FF0000',
                strokeOpacity: 0.5,
                strokeWeight: 2
            });

1 个答案:

答案 0 :(得分:1)

https://developers.google.com/maps/documentation/javascript/reference?csw=1#PolylineOptions  https://developers.google.com/maps/documentation/javascript/reference?csw=1#PolygonOptions

折线和多边形都有zIndex属性,我认为这就是你要找的东西:

new google.maps.Polyline({
            path: googleCoordinates,
            geodesic: true,
            strokeColor: '#40FF00',
            strokeOpacity: 0.5,
            strokeWeight: 2,
            zIndex: 10
        });

new google.maps.Polygon({
            path: googleCoordinates,
            geodesic: true,
            strokeColor: '#FF0000',
            strokeOpacity: 0.5,
            strokeWeight: 2,
            zIndex: 11
        });

在这个示例中,我将它们设置为10和11,您必须使用这些值,因为我不知道它们是否仅限于地图(我认为是这样)或者它们会影响整页中多边形和折线的zIndex。