Solved! Go to Solution.
function runQuery(){ // layer 1 in the service contains all server locations and will be used to cluster var queryTask = new esri.tasks.QueryTask("http://<myserver>/ArcGIS/rest/services/ITSD/serverLocations/MapServer/1"); var query = new esri.tasks.Query(); query.returnGeometry = true; query.where = '1=1'; 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 }; }); // cluster layer that uses OpenLayers style clustering clusterLayer = new extras.ClusterLayer({ "data": inputInfo.data, "distance": 100, "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); // close the info window when the map is clicked // dojo.connect(map, "onClick", cleanUp); // close the info window when esc is pressed dojo.connect(map, "onKeyDown", function(e){ if (e.keyCode == 27) { cleanUp(); } }); dojo.connect(queryTask, "onError", function(err){ alert(err.details); }); }); queryTask.execute(query); }
Sometimes the cluster layer draws fine and sometimes it doesn't draw at all
I"m not sure why I would use an esri.request to the query endpoint as opposed to executing a standard query task. I usually execute my query tasks with a callback to generate my featureset. Is is faster to request the data or formatted differently if I use esri.request instead?
<script> var dojoConfig = { parseOnLoad: true, packages: [{ "name": "extras", "location": location.pathname.replace(/\/[^/]+$/, '') + "/extras" }] }; </script>
dojo.require("extras,ClusterLayer);
I see now that I still had all my references to version 2.5 <snip>
The code still isn't working right, but at least I'm past the first error.
function runQuery(){ // layer 1 in the service contains all server locations and will be used to cluster var queryTask = new esri.tasks.QueryTask("http://<myserver>/ArcGIS/rest/services/ITSD/serverLocations/MapServer/1"); var query = new esri.tasks.Query(); query.returnGeometry = true; query.where = '1=1'; 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 }; }); // cluster layer that uses OpenLayers style clustering clusterLayer = new extras.ClusterLayer({ "data": inputInfo.data, "distance": 100, "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); // close the info window when the map is clicked // dojo.connect(map, "onClick", cleanUp); // close the info window when esc is pressed dojo.connect(map, "onKeyDown", function(e){ if (e.keyCode == 27) { cleanUp(); } }); dojo.connect(queryTask, "onError", function(err){ alert(err.details); }); }); queryTask.execute(query); }