Polymaps和Angularjs

时间:2014-04-06 13:37:05

标签: angularjs polymaps

我试图在angularjs应用中添加一个polymaps地图。

TypeError: Object [object Object] has no method 'setAttribute'
at Object.a.container (http://localhost:8000/lib/polymaps.min.js:15:341)
at new <anonymous> (http://localhost:8000/js/controllers.js:22:4)
at d (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:33:335)
at Object.instantiate
(http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:33:464)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:65:486
at link (http://localhost:8000/lib/angular-route.min.js:7:248)
at J (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:52:492)
at h (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:46:28)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:45:200
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:46:431 <div ng-view="" class="ng-scope">

Javascript无法在我的角度视图中的元素上设置setAttribute吗?

我的HTML看起来像这样:

<article class="dashboard container">
    <div id="map"></div>
</article>

基本的polymaps代码是:

var po = org.polymaps;

var map = po.map()
    .container(document.getElementById("map").appendChild(po.svg("svg")))
    .add(po.interact())
    .add(po.hash());
    .add(po.image().url(
      po.url("http://{S}tile.openstreetmap.org" + "/{Z}/{X}/{Y}.png")
      .hosts(["a.","b.","c.",""])))
    .center({lat:  -33.882957, lon: 151.073685})
    .zoom(11);

我认为这是有角度的。有什么工作吗?

1 个答案:

答案 0 :(得分:0)

要回答我自己的问题,我必须做两件事才能使它在Angular.js中运行。

首先,解决这个问题的方法就是像我一样包装#map元素。事实证明,当我将#map元素作为我视图中的唯一元素时,我的缓存就是保留了这个错误。 (所以我有正确的想法,删除缓存删除了错误)

由于polymaps使用#{zoom} / {coordinateX} / {coordinateY}路由,第二件事就是添加:

$locationProvider.html5Mode(true);

到我的app.js文件中删除路由中的/#/。否则,角度和人造地图在网址上进行了无限的争斗。