【问题标题】:ngMap - how to draw a polygon using an arrayngMap - 如何使用数组绘制多边形
【发布时间】:2015-09-28 09:19:02
【问题描述】:

我正在尝试使用http://ngmap.github.io/ 绘制多边形。如果我使用以下代码,它会完美运行:

    <map center="<% latitude %>, <% longitude %>" zoom="2">
        <marker 
            ng-repeat="marker in GoogleMap.markers" 
            on-click="showInfoWindow(event, marker)" 
            icon="/images/<% marker.icon %>" 
            position="<% marker.latitude %>, <% marker.longitude %>"
        >
        </marker>
        <shape
            paths="[[25.774252, -80.190262],[18.466465, -66.118292],[32.321384, -64.75737],[25.774252, -80.190262]]"
            name="polygon"
            stroke-color="#FF0000" 
            stroke-opacity="0.8" 
            stroke-weight="2" 
            fill-color="#FF0000" 
            fill-opacity="0.35"
        >
        </shape>
    </map>

但是,如果我将多边形坐标分配给控制器内的范围变量,它会因“不是数组”而崩溃,如下所示

    <map center="<% latitude %>, <% longitude %>" zoom="2">
        <marker 
            ng-repeat="marker in GoogleMap.markers" 
            on-click="showInfoWindow(event, marker)" 
            icon="/images/<% marker.icon %>" 
            position="<% marker.latitude %>, <% marker.longitude %>"
        >
        </marker>
        <shape
            paths="polgon"
            name="polygon"
            stroke-color="#FF0000" 
            stroke-opacity="0.8" 
            stroke-weight="2" 
            fill-color="#FF0000" 
            fill-opacity="0.35"
        >
        </shape>
    </map>

...其中多边形在我的控制器内定义为

$scope.polygon = [[25.774252, -80.190262],[18.466465, -66.118292],[32.321384, -64.75737],[25.774252, -80.190262]];

我是否遗漏了一些明显的东西?任何帮助表示赞赏。

【问题讨论】:

  • 可能是因为它的路径 = "polygon" 字符串,而不是你在控制器中定义的。尝试将其更改为路径=多边形。
  • 谢谢,非常接近!我需要用 angularjs 括号括起来(doh!)星期一早上,我还在睡觉。
  • 哈哈哈......是的......:D
  • 我添加了相同的答案,只是为了记录。

标签: angularjs ng-map


【解决方案1】:

问题是路径的值是“多边形”字符串,而不是数组。

已通过添加花括号解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 1970-01-01
    • 1970-01-01
    • 2015-12-15
    • 2015-08-02
    相关资源
    最近更新 更多