1

如何在 Dart 中引用 dojo 方法?我特别尝试使用ESRI 的 Javascript API ,它通过参考Google 关于 javascript/Dart 互操作性的文章构建在 dart 中的 dojo 之上

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <title>Home Extent</title>
  <link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
  <style>
    html, body, #map {
      padding:0;
      margin:0;
      height:100%;
    }
    #HomeButton {
      position: absolute;
      top: 95px;
      left: 20px;
      z-index: 50;
    }
  </style>
  <script src="//js.arcgis.com/3.8/"></script>
  <script>

    require([
      "esri/map", 
      "esri/dijit/HomeButton",
      "dojo/domReady!"
    ], function(
      Map, HomeButton
    )  {

      var map = new Map("map", {
    center: [-56.049, 38.485],
    zoom: 3,
    basemap: "streets"
      });

      var home = new HomeButton({
    map: map
      }, "HomeButton");
      home.startup();

    });
  </script>
</head>
<body>
  <div id="map" class="map">
    <div id="HomeButton"></div>
  </div>
</body>
</html>

我想我很好地掌握了如何调用方法和转换对象,但我不知道如何调用 dojo 方法(特别是Dojo 1.7+ 方法),在这种情况下是“需要”。

4

1 回答 1

1

使用dart:js应该可以:

import 'dart:js' as js;
main() {
  js.context.callMethod('require', [new js.JsArray.from(["esri/map",
      "esri/dijit/HomeButton", "dojo/domReady!"]), (Map, HomeButton) {
      var map = new js.JsObject(Map, ["map", new js.JsObject.jsify({
          'center': [-56.049, 38.485],
          'zoom': 3,
          'basemap': "streets"
        })]);

      var home = new js.JsObject(HomeButton, [new js.JsObject.jsify({
          map: map
        }), "HomeButton"]);
      home.callMethod('startup');
    }]);
}
于 2014-03-19T21:13:20.520 回答