有人可以帮我解决这个问题。上面的代码有什么不对,它不会显示任何错误但集群层没有显示。剩余的功能正在运行。我正在使用这个例子https://github.com/nickcam/FlareClusterLayer
var dojoConfig = {
async: true,
packages: [{
name: 'extras',
location: location.pathname.replace(/[^\/]+$/, '') + 'JS/extras'
}]
};
var findTask, findParams;
ready(function () {
parser.parse();
var clusterLayer;
// registry.byId("ddlDistrict").on("onchange", doFind);
var intialextent = new Extent(8245227.8765913, 1297819.43274543, 8758703.79511306, 2095175.01113784, new SpatialReference({ wkid: 102100 }));
var AgricultureBoundary = new ArcGISDynamicMapServiceLayer("http://[myserver]/arcgisserver/rest/services/CRD/CRD1/MapServer", {
opacity: 0.75
});
var pointFeatureLayer = new FeatureLayer("http://[myserver]/arcgisserver/rest/services/CRD/CRD2/FeatureServer/0", {
id: "Points"
});
map = new Map("mapDiv", {
center: [77.2, 14],
zoom: 7,
extent: intialextent,
basemap: "streets",
});
map.addLayers([AgricultureBoundary, pointFeatureLayer]);
var queryTask = new esri.tasks.QueryTask("http://[myserver]/arcgisserver/rest/services/CRD/CRD2/FeatureServer/0");
var query = new esri.tasks.Query();
query.returnGeometry = true;
query.where = "pointcollected = 'No'";
query.outFields = ["*"];
dojo.connect(queryTask, "onComplete", function (featureSet) {
var inputInfo = {};
inputInfo.data = dojo.map(featureSet.features, function (feature) {
var pointX = feature.geometry.x;
var pointY = feature.geometry.y;
var att = feature.attributes;
return { "x": pointX, "y": pointY, "attributes": att };
});
clusterLayer = new ClusterFeatureLayer({
"data": inputInfo.data,
"distance": 1,
"id": "clusters",
"labelColor": "#fff",
"labelOffset": 10,
"resolution": map.extent.getWidth() / map.width,
"singleColor": "#888",
"singleTemplate": infoTemplate
});
var defaultSym = new esri.symbol.SimpleMarkerSymbol().setSize(4);
var renderer = new esri.renderer.ClassBreaksRenderer(defaultSym, "clusterCount");
var blue = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/BluePin1LargeB.png", 32, 32).setOffset(0, 15);
var green = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/GreenPin1LargeB.png", 64, 64).setOffset(0, 15);
var red = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/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);
});
});
答案 0 :(得分:1)
在构造函数中传递数据不会做任何事情(虽然它可能应该处理它)。
请尝试以下方法:
dojo.connect(queryTask, "onComplete", function (featureSet) {
var inputInfo = {};
inputInfo.data = dojo.map(featureSet.features, function (feature) {
var pointX = feature.geometry.x;
var pointY = feature.geometry.y;
var att = feature.attributes;
return { "x": pointX, "y": pointY, "attributes": att };
});
clusterLayer = new ClusterFeatureLayer({
"distance": 1,
"id": "clusters",
"labelColor": "#fff",
"labelOffset": 10,
"resolution": map.extent.getWidth() / map.width,
"singleColor": "#888",
"singleTemplate": infoTemplate
});
var defaultSym = new esri.symbol.SimpleMarkerSymbol().setSize(4);
var renderer = new esri.renderer.ClassBreaksRenderer(defaultSym, "clusterCount");
var blue = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/BluePin1LargeB.png", 32, 32).setOffset(0, 15);
var green = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/GreenPin1LargeB.png", 64, 64).setOffset(0, 15);
var red = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/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);
clusterLayer.addData(inputInfo.data);
});