Ok, I got this working, somewhat, but I'll get to that.This works.
require([
"dojo/Evented",
"dojo/ready",
"dojo/parser",
"dojo/on",
"extras/clusterlayerNew",
"esri/map",
"esri/layers/graphics",
"esri/layers/FeatureLayer",
"esri/layers/GraphicsLayer",
"esri/tasks/QueryTask",
"esri/tasks/query",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojo/domReady!"
],
function (
Evented,
ready,
parser,
on,
ClusterlayerNew,
Map, // you had lower-case map, which can cause problems when creating a map variable
graphics, // This is an empty object because it is not a module
FeatureLayer,
GraphicsLayer,
QueryTask, // was called queryTask, biggest issue
Query,
BorderContainer,
ContentPane
) {
var map;
// scope this out here. The above had same name (case matters).
var queryTask = new QueryTask("http://gis.phila.gov/ArcGIS/rest/services/PhilaGov/Police_Incidents_Last30/MapServer/0");
function init() {
parser.parse();
map = new Map("map", { // You had map = new map(), this could cause issues, probably in IE, everything breaks in IE.
center: [-75.1700, 39.9500],
zoom: 12,
basemap: "hybrid"
});
runQuery(); // you need the map in the runQuery method, so initialize it first then do runQuery
}
function runQuery() {
var query = new Query();
query.returnGeometry = true;
query.where = '1=1';
query.outFields = ["DC_DIST", "POINT_X", "POINT_Y"];
queryTask.on("complete", function (event) {
console.debug('ClusterlayerNew is an empty object?', ClusterlayerNew);
// This clusterlayer module is broken, it returns an empty object, even after I quickly edited it.
// I did not try troubleshooting this
var cL = new ClusterlayerNew({
displayOnPan: false,
map: map,
features: event.featureSet.features,
infoWindow: {
template: new esri.InfoTemplate("${SECTOR}"),
width: 325,
height: 100
},
flareLimit: 15,
flareDistanceFromCenter: 20
});
map.addLayer(cL);
});
// you were trying to execute this outside the scope of the function the query was defined in.
queryTask.execute(query);
};
// before, this was the class "QueryTask", the class is not initialized, thus not an event emitter.
on(queryTask, "error", function (err) {
alert(err.details);
});
// Use the ready() method as opposed to dojo.addOnLoad
ready(init);
});
See my comments for some of the issues you had.One of your main issues seems to be with scope, so I would run through some material and you'll soon see where things broke.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scopeDon't mix the old dojo.lib.ClassName() with the AMD loading of modules. In this case, it probably just added to the confusion.Note - Mixing the two won't necessarily break your code (yet), but it should be avoided fro consistency.That clusterlayerNew module is broken or something, I couldn't get it to work, but my changes above load your map and at least try to create that cluster layer.You may want to check out a project I have been working on to do clusters in a fashion more similar to a FeatureLayer.https://github.com/odoe/esri-clusterfeaturelayerHope that helps a bit.