0
我正在使用Dart中的js庫訪問OpenLayers。相關的代碼如下所示:如何從javascript函數返回值
js.scoped(() {
ol = js.retain(js.context.OpenLayers);
var max_extent = new js.Proxy(ol.Bounds, -13652354.432172, 6026153.418145, -13574082.915218, 6065289.1766216);
var restricted_extent = max_extent;
if (controls == null){
var options = js.map ({
'maxExtent': max_extent,
'restrictedExtent' : restricted_extent,
'units' : 'm',
'projection': new js.Proxy(ol.Projection, 'EPSG:900913'),
'displayProjection' : new js.Proxy(ol.Projection, 'EPSG:4326'),
'controls' : js.array([ new js.Proxy(ol.Control.Attribution),
new js.Proxy(ol.Control.Navigation),
new js.Proxy(ol.Control.ArgParser),
new js.Proxy(ol.Control.PanPanel),
new js.Proxy(ol.Control.ZoomPanel)
])
});
_treemap = js.retain(new js.Proxy(ol.Map, map_div_id, options));
}
var roads = new MapLayer(ol, layer_type:'road').layer;
var aerial = new MapLayer(ol, layer_type:'hybrid').layer;
_treemap.addLayers(js.array([roads, aerial]));
_treemap.setBaseLayer(roads);
_treemap.zoomToMaxExtent();
var result = _treemap.layers();
});
除了最後一行,所有功能都按預期工作。 _treemap.layers()
應該返回一個數組OpenLayer.Layer
。當該行執行,我得到一個錯誤:
Exception: TypeError: Object [object Array] has no method 'apply'
那麼,是什麼讓我的飛鏢代碼JavaScript函數/手柄返回值的正確方法是什麼?
謝謝!並感謝您的獎金提示! – 2013-02-27 18:34:10