未定义地图图层

时间:2014-07-05 01:18:26

标签: dictionary arcgis esri arcgis-js-api

我正在尝试根据从数据库中获取的JSON对象来创建点集群层。这是我绘制点集群层的JavaScript:

function addClusters() {
$.ajax({
    url: "index.aspx/getBusCommuter",
    type: "POST",
    data: "",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
        var parsed = JSON.parse(data.d);
        $.each(parsed, function (i, jsondata) {
            var coordXicon = jsondata.BusStopX;
            var coordYicon = jsondata.BusStopY;
            var commuterAmt = jsondata.CommuterAmt;

            var latlng = new esri.geometry.Point({ "x": coordXicon, "y": coordYicon, "spatialReference": { "wkid": 4326 } });

            // cluster layer that uses OpenLayers style clustering
            clusterLayer = new ClusterLayer({
                "data": commuterAmt,
                "distance": 100,
                "id": "clusters",
                "labelColor": "#fff",
                "labelOffset": 10,
                "resolution": map.extent.getWidth() / map.width,
                "singleColor": "#888"
            });
            var defaultSym = new SimpleMarkerSymbol().setSize(4);
            var renderer = new ClassBreaksRenderer(defaultSym, "clusterCount");

            var picBaseUrl = "http://static.arcgis.com/images/Symbols/Shapes/";
            var blue = new PictureMarkerSymbol(picBaseUrl + "BluePin1LargeB.png", 32, 32).setOffset(0, 15);
            var green = new PictureMarkerSymbol(picBaseUrl + "GreenPin1LargeB.png", 64, 64).setOffset(0, 15);
            var red = new PictureMarkerSymbol(picBaseUrl + "RedPin1LargeB.png", 72, 72).setOffset(0, 15);
            renderer.addBreak(0, 2, blue);
            renderer.addBreak(2, 200, green);
            renderer.addBreak(200, 1001, red);

            clusterLayer.setRenderer(renderer);
            map.addLayer(clusterLayer);
        });
    },
    error: function (request, state, errors) {
    }
});
}

但是,当我尝试运行它时,它告诉我一条错误消息,即未定义clusterLayer。我想知道我错过了哪一部分,我正在以正确的方式做。

另外,我想知道将获得的commuterAmt设置为数据是否可能/正确,以便地图上的每个点都附加正确的数量?

我从ArcGIS Documentation

获取参考资料

提前致谢。

1 个答案:

答案 0 :(得分:0)

尝试下载示例代码ArcGIS Documentation 包括来自extras direxctory

的ClusterLayer.js
 var dojoConfig = { 
        paths: {
          extras: location.pathname.replace(/\/[^/]+$/, "") + "/extras"
        }
      };

然后在你的代码中使用

define dojo.provide("extras.ClusterLayer");

并致电

clusterLayer = new extras.ClusterLayer({
                "data": commuterAmt,
                "distance": 100,
                "id": "clusters",
                "labelColor": "#fff",
                "labelOffset": 10,
                "resolution": map.extent.getWidth() / map.width,
                "singleColor": "#888"
            });