I have an application that I've built using the arcgis javascript API. It uses feature layers to pull in information and to allow different searches on the map, but 15 feature layers really bogs down my client's server, so we're looking into alternatives. I've tried to find something else to work with that doesn't kill the functionality of my application, but I've yet to find a solution. The application currently has these search capabilities:
1) Display all features in a layer
2) Display all features in a layer within a settable radius
3) Display all features within a settable radius of the user's current location (if allowed access)
All of the above search options can have their displayed features whittled down by performing a query on the layer (using queryFeatures()) to only show the features that have categoryX and/or industryY.
It all works like a charm aside from the hit it gives their server whenever the feature layers are turned on or off.
Is there a way to accomplish all of this without relying on the feature layers?
edit: Here's an example of what I'm doing: http://developers.arcgis.com/javascript/sandbox/sandbox.html?sample=query_buffer
Using featurelayers allows you to have geometries directly on your client. Having geometries on your client is mandatory in some cases ( for example if you need to edit features) but in many other cases it is not the better choice.
To achieve your goals maybe you can just use many ArcGISDynamicMapServiceLayer and identify or query tasks to get your informations from the server.
edit: I have modified the sample you posted
var map;
require([
"esri/map", "esri/layers/ArcGISDynamicMapServiceLayer",
"esri/tasks/query", "esri/geometry/Circle",
"esri/graphic", "esri/InfoTemplate", "esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/renderers/SimpleRenderer",
"esri/config", "esri/Color", "dojo/dom","esri/tasks/QueryTask", "dojo/domReady!"
], function(
Map, ArcGISDynamicMapServiceLayer,
Query, Circle,
Graphic, InfoTemplate, SimpleMarkerSymbol,
SimpleLineSymbol, SimpleFillSymbol, SimpleRenderer,
esriConfig, Color, dom, QueryTask
) {
esriConfig.defaults.io.proxyUrl = "/proxy/";
map = new Map("mapDiv", {
basemap: "streets",
center: [-95.249, 38.954],
zoom: 14,
slider: false
});
var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer");
var queryTask = new QueryTask("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/0");
var circleSymb = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_NULL,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SHORTDASHDOTDOT,
new Color([105, 105, 105]),
2
), new Color([255, 255, 0, 0.25])
);
var circle;
var symbol = new SimpleMarkerSymbol(
SimpleMarkerSymbol.STYLE_CIRCLE,
12,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_NULL,
new Color([247, 34, 101, 0.9]),
1
),
new Color([207, 34, 171, 0.5])
);
//when the map is clicked create a buffer around the click point of the specified distance.
map.on("click", function(evt){
circle = new Circle({
center: evt.mapPoint,
geodesic: true,
radius: 1,
radiusUnit: "esriMiles"
});
map.graphics.clear();
map.infoWindow.hide();
var graphic = new Graphic(circle, circleSymb);
map.graphics.add(graphic);
var query = new Query();
query.geometry = circle.getExtent();
//use a fast bounding box query. will only go to the server if bounding box is outside of the visible map
require([
"esri/tasks/query"
], function (Query) {
var query = new Query();
query.spatialRelationship = Query.SPATIAL_REL_CONTAINS;
query.geometry = circle;
query.returnGeometry = true;
queryTask.execute(query, function (fset1) {
dojo.forEach(fset1.features, function (feature, i) {
console.log("feature", feature);
feature.setSymbol(symbol);
map.graphics.add(feature);
});
});
});
});
function selectInBuffer(response){
var feature;
var features = response.features;
var inBuffer = [];
//filter out features that are not actually in buffer, since we got all points in the buffer's bounding box
for (var i = 0; i < features.length; i++) {
feature = features[i];
if(circle.contains(feature.geometry)){
inBuffer.push(feature.attributes[featureLayer.objectIdField]);
}
}
var query = new Query();
query.objectIds = inBuffer;
//use a fast objectIds selection query (should not need to go to the server)
featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){
var totalPopulation = sumPopulation(results);
var r = "";
r = "<b>The total Census Block population within the buffer is <i>" + totalPopulation + "</i>.</b>";
dom.byId("messages").innerHTML = r;
});
}
function sumPopulation(features) {
var popTotal = 0;
for (var x = 0; x < features.length; x++) {
popTotal = popTotal + features[x].attributes["POP2000"];
}
return popTotal;
}
});