2013-02-26 3 views
0

나는 OpenLayers에 액세스하려면 다트에서 js 라이브러리를 사용하고 있습니다. 관련 코드는 다음과 같습니다.어떻게 자바 스크립트 함수에서 값을 반환합니까

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'

그래서, 내 다트 코드에서 자바 스크립트 기능에서/핸들 반환 값을 얻을 수있는 올바른 방법은 무엇인가 : 그 라인은 내가 오류가 발생 실행하면?

답변

1

layers은 배열입니다 (OpenLayers.Map.layers 참조). 그래서 당신은 사용해야합니다 : 당신이 함수이었다로 layers를 호출하려고했다 _treemap.layers()

var result = _treemap.layers; 

.

코드의 한 쪽 메모 : js.map({})을 사용할 때 js.array 또는 js.map을 오브젝트 트리에 사용할 필요가 없습니다. JSON과 같은 구조를 지정하기 만하면됩니다.

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' : [ 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) 
       ]) 
}); 
+0

고마워요! 그리고 보너스 팁을 주셔서 감사합니다! –

관련 문제