我正在尝试用 ClojureScript 重写 OpenLayers 的示例用法。
Javascript 源代码如下所示:
var map, layer;
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.OSM("Simple OSM Map");
map.addLayer(layer);
var projection = new OpenLayers.Projection("EPSG:4326");
var center = new OpenLayers.LonLat(-71.147, 42.472).transform(projection, map.getProjectionObject());
map.setCenter(center, 12);
我已经像这样重写了这段代码:
(ns hello.map)
(def mapp (.Map js/OpenLayers "map"))
(def layer (.Layer.OSM js/OpenLayers "Simple OSM Map"))
(.addLayer mapp layer)
(def projection (.Projection js/OpenLayers "EPSG:4326"))
(def center (.Transform (.LonLat js/OpenLayers -71.147 42.472) projection (.getProjectionObject mapp)))
(.setCenter mapp center 12)
Lein 生成以下代码:
var hello = {map:{}};
hello.map.mapp = OpenLayers.Map("map");
hello.map.layer = OpenLayers.Layer.OSM("Simple OSM Map");
hello.map.mapp.addLayer(hello.map.layer);
hello.map.projection = OpenLayers.Projection("EPSG:4326");
hello.map.center = OpenLayers.LonLat(-71.147, 42.472).Transform(hello.map.projection, hello.map.mapp.getProjectionObject());
hello.map.mapp.setCenter(hello.map.center, 12);
hello.hello = {};
它不工作。那么问题在于 ClojureScript 在没有new
其他东西的情况下生成代码吗?