如何在 google-map 中显示 WellKnownText

How to display WellKnownText in google-map

我目前正在使用 goolge maps angular 组件,并且具有以下完美运行的功能。 问题是我的数据不是他们使用的格式....

polygons: [{path: [{latitude: x, longitude: y },...]

但采用 WellKnownText (WKT) 格式,例如:

POLYGON ((y x,...))

有没有什么方法可以让 google 地图改为显示 WKT 格式?

这是我目前拥有的,并且运行良好:

<ui-gmap-google-map center="map.coordinates" zoom="map.zoom" options="options">
    <ui-gmap-polygon 
        ng-repeat="poly in map.polygons"
        path='poly.path'
        fill='poly.fill'
        stroke='poly.stroke'
        clickable='poly.clickable'
        draggable='poly.draggable'
        editable='poly.editable'>
    </ui-gmap-polygon>
</ui-gmap-google-map>

angularjs 控制器看起来像这样

$scope.map = {
        visible: false,
        coordinates: _startingCoordinates,
        zoom: _zoom,
        bounds: {},
        polygons: [{
            path: [
                { latitude: 52.39786758957449, longitude: -9.951156616210937 },
                { latitude: 52.38278195910962, longitude: -9.848846435546875 },
                { latitude: 52.32028936800865, longitude: -9.855026245117187 },
                { latitude: 52.30517723258029, longitude: -9.896911621093750 },
                { latitude: 52.24635875956514, longitude: -9.868072509765625 },
                { latitude: 52.26863493471054, longitude: -9.999908447265625 },
                { latitude: 52.33749412738444, longitude: -9.986175537109375 },
                { latitude: 52.34714264824414, longitude: -10.05895996093750 }
            ],
            fill: {
                color: "#00f274",
                opacity: 0.4
            },
            stroke: {
                color: "#cacaca",
                weight: 1,
                opacity: .8
            },
            visible: true,
        }]
    };

也许 google API 中有设置或选项,但我找不到?

您可以尝试使用自定义函数解析 WKT 字符串。一些例子可以在这里看到:link