如何在google-map中显示WellKnownText

时间:2015-01-15 11:33:37

标签: angularjs google-maps

我目前正在使用goolge maps角度组件,并且具有以下完美的效果。 问题是我的数据不是他们使用的格式......

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

但是以WellKnownText(WKT)格式表示:

POLYGON ((y x,...))

有没有办法让谷歌地图改为显示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,
        }]
    };

也许谷歌API中有一个设置或选项,但我找不到它?

1 个答案:

答案 0 :(得分:0)

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