I am attempting to recreate the ESRI example for attribute inspections (https://developers.arcgis.com/javascript/jssamples/ed_attribute_inspector.html).
I am having an issue when I create my feature service that contains a point feature class vs. the polygon feature class the example uses.
My initSelectToolbar(evt) function isn't "seeing" the point from the feature layer. If I only change the urls to the feature/map services (noted in commented out service declaration) the selection works successfully.
Am I missing something obvious here? Why can I not grab the point?
Blockquote
var map;
var updateFeature;
var map, geocoder, currentBaseMap;
var locatorUrl = "http://gisaprd/ArcGIS/rest/services/SDE.AddressLocator_Comp/GeocodeServer";
require([
"esri/map",
"esri/layers/FeatureLayer",
"esri/dijit/AttributeInspector",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
"dojo/_base/Color",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/ArcGISTiledMapServiceLayer",
"esri/config",
"esri/tasks/query",
"dojo/parser",
"dojo/dom-construct",
"dijit/form/Button",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function (
Map, FeatureLayer, AttributeInspector,
SimpleLineSymbol, SimpleFillSymbol, Color,
ArcGISDynamicMapServiceLayer, ArcGISTiledMapServiceLayer, esriConfig,
Query,
parser, domConstruct, Button
) {
parser.parse();
// refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
esriConfig.defaults.io.proxyUrl = "/proxy";
// Create the map
map = new Map("mapDiv")
map.on("layers-add-result", initSelectToolbar);
//aerialsLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://gisaprd/ArcGIS/rest/services/Aerials_4inch_12inch_Cached/MapServer", { "id": "Aerials", "visible": false });
//map.addLayer(aerialsLayer);
streetsLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisaprd/ArcGIS/rest/services/SRSLandbase/MapServer", { "id": "Streets" });
map.addLayer(streetsLayer);
currentBaseMap = "Streets";
var ISS_Inspections = new ArcGISDynamicMapServiceLayer("http://gisadev:6080/arcgis/rest/services/ISS_Inspections/MapServer", { "id": "ISS_Inspections" });
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// If I use a map service with only polygons this works
//var ISS_Inspections = new ArcGISDynamicMapServiceLayer("http://gisadev:6080/arcgis/rest/services/testDeleteMe2222/MapServer", { "id": "ISS_Inspections" });
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
ISS_Inspections.setDisableClientCaching(true);
map.addLayer(ISS_Inspections);
var ISS_InspectionsFL = new FeatureLayer("http://gisadev:6080/arcgis/rest/services/ISS_Inspections/FeatureServer/0", {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// If I use a feature service with only polygons this works
// var ISS_InspectionsFL = new FeatureLayer("http://gisadev:6080/arcgis/rest/services/testDeleteMe2222/FeatureServer/0", {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
mode: FeatureLayer.MODE_SELECTION,
outFields: ["*"]
});
highlightSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([255, 255, 0]));
ISS_InspectionsFL.setSelectionSymbol(highlightSymbol);
ISS_InspectionsFL.on("edits-complete", function () {
ISS_Inspections.refresh();
});
map.addLayers([ISS_InspectionsFL]);
function initSelectToolbar(evt) {
var ISS_InspectionsFL = evt.layers[0].layer;
var selectQuery = new Query();
map.on("click", function (evt) {
selectQuery.geometry = evt.mapPoint;
ISS_InspectionsFL.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW, function (features) {
if (features.length > 0) {
//store the current feature
updateFeature = features[0];
map.infoWindow.setTitle(features[0].getLayer().name);
map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
} else {
map.infoWindow.hide();
}
});
});
map.infoWindow.on("hide", function () {
ISS_InspectionsFL.clearSelection();
});
var layerInfos = [{
'featureLayer': ISS_InspectionsFL,
'showAttachments': false,
'isEditable': true,
'fieldInfos': [
{ 'fieldName': 'PS_READING_INLET_SIDE', 'isEditable': true, 'tooltip': 'Current Status', 'label': 'Status:' },
]
}];
var attInspector = new AttributeInspector({
layerInfos: layerInfos
}, domConstruct.create("div"));
//add a save button next to the delete button
var saveButton = new Button({ label: "Save", "class": "saveButton" });
domConstruct.place(saveButton.domNode, attInspector.deleteBtn.domNode, "after");
saveButton.on("click", function () {
updateFeature.getLayer().applyEdits(null, [updateFeature], null);
});
attInspector.on("attribute-change", function (evt) {
//store the updates to apply when the save button is clicked
updateFeature.attributes[evt.fieldName] = evt.fieldValue;
});
attInspector.on("next", function (evt) {
updateFeature = evt.feature;
console.log("Next " + updateFeature.attributes.objectid);
});
attInspector.on("delete", function (evt) {
evt.feature.getLayer().applyEdits(null, null, [feature]);
map.infoWindow.hide();
});
map.infoWindow.setContent(attInspector.domNode);
map.infoWindow.resize(350, 240);
}
}
);
Blockquote
Best Answer
is the problem that 'evt.layers[0].layer' doesn't resolve within the edit initialization function or that you just can't trigger the query when clicking on the map?
if the second, check out this blog post/sample code on querying points and polylines by clicking the map.
Querying points and lines on click with the ArcGIS JavaScript API http://blogs.esri.com/esri/arcgis/2009/01/15/querying-points-and-lines-on-click-with-the-arcgis-javascript-api/