我正在嘗試寫一個聚合物元素負責繪製谷歌地圖表示法。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