我正在尝试写一个聚合物元素负责绘制谷歌地图表示法。Dart +聚合物+ google_maps
这是代码:
@CustomTag('map-element')
class MapElement extends PolymerElement {
...
@override
void attached() {
super.attached();
canvasMap = $['canvas_map'];
initMap();
window.navigator.geolocation.watchPosition(enableHighAccuracy: true)
.listen(
(Geoposition position) {addPosition(position);},
onError: (error) => handleError(error));
}
...
void initMap(){
gmap = new GMap(
canvasMap,
new MapOptions()
..zoom = 4
..center = new LatLng(0, 0)
..mapTypeId = MapTypeId.ROADMAP
);
line = new Polyline(
new PolylineOptions()
..map = gmap
..strokeColor='#0022ee'
..geodesic=true
..strokeOpacity=0.7
..strokeWeight=2
..visible=true);
}
}
这是抛出的异常,当我尝试创建GMAP的一个实例:
Class 'GElement' has no instance method '[]'.
NoSuchMethodError: method not found: '[]'
Receiver: Instance of 'GElement'
Arguments: ["maps"]
我认为这个问题是因为聚合物使用DOM影子,你知道任何解决方法吗?
这里是整个项目:https://github.com/carlosvin/snowroute
现在它的工作,在这里你可以尝试一下:http://carlosvin.github.io/snowroute/
我只index.html中添加JavaScript代码,而不是在聚合物元素声明。
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
我尝试为https://github.com/carlosvin/snowroute,对于这个问题的相关文件:网络/ map_element.dart,网络/ map_element.html和web/index.html的。
我现在没有时间整理,但我认为Angular.dart也有类似的问题,答案也可能适用于您。 – 2014-11-06 19:15:38
谢谢我要去找Angular.dart,然后我会发布我的研究结果。我正在为Polymer.dart寻找类似的问题,但我找不到解决方法。 – carlosvin 2014-11-06 19:49:00