【问题标题】:How to draw my stored polygon from database onto the google map如何将我存储的多边形从数据库绘制到谷歌地图上
【发布时间】:2016-04-04 15:38:09
【问题描述】:

对于角度谷歌地图,我希望我可以将存储的标记多边形数组绘制到地图上。

我使用的技术是:Angular version 1 with JavaScript,使用 angular 指令和 templateUrl。

这是我的 html 指令模板:

<ui-gmap-google-map center="config.map.center" zoom="config.map.zoom" options="config.map.options" events="config.map.events" draggable="true">

        <ui-gmap-polygon path="compatiblePolygon" stroke="polygonConfig.stroke" fill="polygonConfig.fill" fit="true" static="true" visible="polygonConfig.visible" editable="polygonConfig.editable" draggable="polygonConfig.draggable" clickable="true" events="polygonConfig.events">
        </ui-gmap-polygon>

        <ui-gmap-markers models="compatiblePoints" coords="'self'" idKey="'id'"
            options="pointsConfig.options"
            clickable="true">
        </ui-gmap-markers>

        <ui-gmap-drawing-manager options="config.drawing.options" static="true" control="drawingManagerControl" events="config.drawing.events"></ui-gmap-drawing-manager>

    </ui-gmap-google-map>

【问题讨论】:

    标签: javascript angularjs google-maps google-maps-api-3 angular-google-maps


    【解决方案1】:

    您需要将多边形作为编码字符串存储在数据库中,而不是多边形坐标。 您可以按如下方式获得编码的多边形:

    /* This function save latitude and longitude to the polygons[] variable after we call it. */
        function encodePolygon(polygon)
        {
            //This variable gets all bounds of polygon.
            var path = polygon.getPath();
    
            var encodeString = 
            google.maps.geometry.encoding.encodePath(path);
    
            /* store encodeString in database */
        }
    

    然后您可以随时从编码字符串中重新绘制多边形:

    function DrawPolygon(encodedString){
        var decodedPolygon =   
       google.maps.geometry.encoding.decodePath(encodedString);
    
                var polygon = new google.maps.Polygon({
                    paths: decodedPolygon,
                    editable: false,
                    strokeColor: '#FFFF',
                    strokeOpacity: 0.8,
                    strokeWeight: 2,
                    fillColor: '#FFFF',
                    fillOpacity: 0.35
                });
    }
    

    【讨论】:

    • 问题是我的指令没有 Google 的名字
    • - 确保在 index.html 中的指令文件之前加载 google API - 将 http[s] 参数放在路径中 - 您没有在任何代理后面。看到这个帖子:stackoverflow.com/questions/7567602/…
    • 我尝试了所有这些方法,但仍然出现错误:“找不到名称 'google' '”
    • 在一个单独的问题下提出这个问题,或者最好搜索人们之前遇到的类似问题。给出的答案为这里提出的问题提供了解决方案。
    猜你喜欢
    • 1970-01-01
    • 2012-08-25
    • 2019-09-27
    • 1970-01-01
    • 2012-05-31
    • 2014-07-21
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多