I'm finally able to play with the ArcGIS API for JavaScript! To get started, I am playing with deploying the functionality that similar to the sample for "Query Map with buffer polygon:" http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htmHowever, now that I think I have solved the proxy problem (Yikes, Jeremy et al., please include a link in the example of how to install the proxy!), I am finding that the buffer isn't limiting the result to the region inside the buffer.Is this due to a configuration error on my part with the proxy server?I always receive 500 results from the full extent of a several thousand point Layer file served VIA REST.Here's my code snippet:
dojo.require("esri.map");
dojo.require("esri.tasks.query");
dojo.require("esri.tasks.geometry");
/*Initialize map, buffer, & query params*/
function init(){
var startExtent = new esri.geometry.Extent(-119, 40, -110, 50, new esri.SpatialReference({
wkid: 4326
}));
var map = new esri.Map("mapDiv", {
extent: startExtent
});
//listen for when map is loaded and then add query functionality
dojo.connect(map, "onLoad", initFunctionality);
var streetMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
map.addLayer(streetMap);
}
function initFunctionality(map){
var queryTask = new esri.tasks.QueryTask("http://MYDOMAIN/gis/rest/services/develObservations2/MapServer/0/query");
//identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters.
//If this null or not available the buffer operation will not work. Otherwise it will do a http post to the proxy.
esriConfig.defaults.io.proxyUrl = "../server/proxy.ashx";
esriConfig.defaults.io.alwaysUseProxy = true;
// Query
var query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["MYOUTPUTFIELDS"];
//Geometry Service Endpoint
var gsvc = new esri.tasks.GeometryService("http://MYDOMAIN/gis/rest/services/Geometry/GeometryServer");
// +++++Listen for map onClick event+++++
dojo.connect(map, "onClick", function(evt){
map.graphics.clear();
var symbol = new esri.symbol.SimpleMarkerSymbol();
var graphic = new esri.Graphic(evt.mapPoint, symbol);
var params = new esri.tasks.BufferParameters();
params.features = [graphic];
// CASE [1]: if you want to buffer in linear units such as meters, km, miles etc.
params.distances = [dojo.byId('bufferDistance').value];
params.unit = esri.tasks.BufferParameters.UNIT_KILOMETER;
params.bufferSpatialReference = new esri.SpatialReference({
wkid: 4326
});
gsvc.buffer(params);
dojo.byId('messages').innerHTML = "<b>Creating Buffer Using Geometry Service...</b>";
});
// +++++Listen for GeometryService onBufferComplete event+++++
dojo.connect(gsvc, "onBufferComplete", function(graphics){
var symbol = new esri.symbol.SimpleFillSymbol("none", new esri.symbol.SimpleLineSymbol("solid", new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
var graphic = new esri.Graphic(graphics[0].geometry, symbol);
map.graphics.add(graphic);
query.geometry = graphic.geometry;
queryTask.execute(query);
dojo.byId('messages').innerHTML = "<b>Executing Query with Result Buffer Geometry...</b>";
});
// +++++Listen for QueryTask executecomplete event+++++
dojo.connect(queryTask, "onComplete", function(fset){
//create symbol for selected features
var symbol = new esri.symbol.SimpleMarkerSymbol();
symbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE;
symbol.setSize(8);
symbol.setColor(new dojo.Color([0, 255, 255, 0.5]));
//THERE IS PROBABLY A BETTER WAY TO DO THIS, BUT I HAD ISSUES WITH LABELING POINTS AS A MULTIPOINT
var resultFeatures = fset.features;
for (var i = 0, il = resultFeatures.length; i < il; i++) {
var thisx = resultFeatures.attributes.XMin;
var thisy = resultFeatures.attributes.YMin;
thisgeometry = new esri.Graphic(new esri.geometry.Point(thisx, thisy, new esri.SpatialReference({ wkid: 4326 })));
infoTemplate = new esri.InfoTemplate("Observation of " + resultFeatures.attributes.SciName + " ID:" + resultFeatures.attributes.observationid, "Info: " + resultFeatures.attributes.Title);
thisgeometry.setInfoTemplate(infoTemplate);
thisgeometry.setSymbol(symbol);
map.graphics.add(thisgeometry);
}
var totalObservations = resultFeatures.length;
dojo.byId('messages').innerHTML = "<b>The total Observations within the buffer is <i>" + totalObservations + "</i>.</b>";
});
}
dojo.addOnLoad(init);