简体   繁体   English

多边形地图和Angular.js

[英]Polymaps and Angularjs

I'm trying to add a polymaps map inside an angularjs app. 我试图在一个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 is not able to setAttribute on an element inside my angular view? Javascript无法在我的角度视图内的元素上设置setAttribute?

My html looks like this: 我的html看起来像这样:

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

And the basic polymaps code is: 基本的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);

I'm assuming this is angular. 我假设这是有角度的。 Is there any work around? 有什么解决办法吗?

To answer my own question I had to do two things to make it work in Angular.js. 要回答我自己的问题,我必须做两件事才能使其在Angular.js中起作用。

The first, to solve this problem was to wrap the #map element as I did. 首先,要解决此问题,是像我一样包装#map元素。 It turns out my caching was keeping this error from when I had the #map element as the only element in my view. 事实证明,当我将#map元素作为视图中的唯一元素时,我的缓存阻止了此错误。 (So I had the right Idea, deleting cache removed the error) (所以我有正确的想法,删除缓存可以消除错误)

Since polymaps uses a #{zoom}/{coordinateX}/{coordinateY} routing, the second thing was to add: 由于polymap使用#{zoom} / {coordinateX} / {coordinateY}路由,因此第二件事是添加:

$locationProvider.html5Mode(true);

To my app.js file to remove the /#/ in my routes. 到我的app.js文件中,删除我的路线中的/#/。 Otherwise, angular and polymaps undertook an infinite battle over the url. 否则,角度地图和多边形地图将对网址进行无限的争夺。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM