javascript 编程解析< shape>为多边形对象谷歌Map/Angular ngmap

qoefvg9y  于 2023-01-19  发布在  Java
关注(0)|答案(1)|浏览(120)

我正在尝试访问shape并将其解析/转换为Polygon对象,以便检索getPath().getArrays()
有没有什么方法可以让我从html中检索<shape>并在我的控制器中使用它?

$scope.insertAt = function (event) {
            const shape = document.getElementById('polygon');
            const polygon = new google.maps.Polygon(shape);
            console.log("Polygon ", polygon);
            // error here --> polygon.getPath().getArray();
        };
<shape name="polygon" id="polygon" stroke-color="#FF0000"
                       stroke-opacity="1.0"
                       stroke-weight="2"
                       draggable="true"
                       geodesic="false"
                       editable="true"
                       insert-at="{{insertAt()}}"
                       paths="{{mappedGeoCoordinates}}" >
                </shape>

谢谢

h6my8fg2

h6my8fg21#

您尝试将形状直接转换为多边形,但需要先从形状获取路径,然后传递这些路径。

const shape = document.getElementById('polygon');
const paths = shape.getAttribute("paths");
const polygon = new google.maps.Polygon({ paths });

我不确定你的$scope.insertAt是什么。假设这是你自己的属性?

相关问题