0

I'm creating a application to select features on event 'click' and then using AttributeInspector to edit the attribute fields. I'm also creating draw tools to select features on event click and populate corresponding field values to search widgets. Whenever, i click on a particular feature, the console returns with an error (i.e. unable to complete operation), but when i use draw tool on a feature, the attributeinspector for that feature shows up on the screen. Basically, the Onclick event associated with AttributeInspector is not firing up. Would anyone highlight where i had gone wrong in the script. Please check the below script.

var map;
require(["esri/map","dojo/parser",
    "esri/layers/FeatureLayer",
    "esri/symbols/SimpleMarkerSymbol", 
    "esri/symbols/SimpleFillSymbol",  
    "esri/symbols/SimpleLineSymbol",
    "esri/Color",
    "esri/renderers/SimpleRenderer",
    "esri/dijit/Search",
    "esri/InfoTemplate",
    "esri/toolbars/draw",
    "dojo/dom","dojo/on",
    "dijit/form/Button",
    "esri/graphic",
    "esri/tasks/query", 
    "dojo/_base/array", 
    "esri/geometry/webMercatorUtils",
    "esri/dijit/editing/Editor",
    "dijit/registry", 
    "esri/tasks/GeometryService",
    "esri/config",
    "dijit/layout/BorderContainer",
    "dijit/layout/ContentPane", 
    "esri/dijit/AttributeInspector",
    "dijit/layout/AccordionContainer", 
    "dojo/dom-construct", 
    "dojo/ready"
   ], 

function(Map, parser, FeatureLayer, SimpleMarkerSymbol, SimpleFillSymbol, SimpleLineSymbol,
         Color,SimpleRenderer, Search,InfoTemplate,Draw, dom,on, Button, graphic, Query,
         arrayUtil,webMercatorUtils, Editor, registry, GeometryService, esriConfig,
         AttributeInspector, domConstruct)
{ 
map = new Map("mapDiv", {
    basemap: "satellite",
    center: [-56.049, 38.485],
    zoom: 3
});


var myfeatureLayer = new FeatureLayer("http://arcgis-serveruf-1981283418.us-east-1.elb.amazonaws.com/arcgis/rest/services/MyFiles/LandParcels/FeatureServer/0",{
   outFields: ["*"]
});  
var SelectionSymbol= new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.5]));
myfeatureLayer.setRenderer(new esri.renderer.SimpleRenderer(SelectionSymbol));
map.addLayers([myfeatureLayer]);

var mySearch = new Search({ 
   enableHighlight: false,
   enableInfoWindow: true,
   map:map,
   sources: [],
   zoomScale:5000000
},"Address");

var geoSearch = new Search({
   enableHighlight: false,
   enableInfoWindow: false,
   map:map,
   sources: [],
   zoomScale: 1000
},"Coordinates");

var parcelSearch = new Search({
   enableHighlight: false,
   enableInfoWindow: true,
   map:map,
   sources: [],
   zoomScale: 1000
},"parcelName");

var landuseSearch = new Search({
   enableHighlight: false,
   enableInfoWindow: true,
   map:map,
   sources: [],
   zoomScale: 1000
},"landuseSearch");


toolbar = new Draw(map);
toolbar.on("draw-end", addGraphic);
on(dom.byId("polygon"),"click", execute1);
function execute1(){
   toolbar.activate(Draw.FREEHAND_POLYGON);
}

on(dom.byId("polyline"),"click", execute2);
function execute2(){
   toolbar.activate(Draw.FREEHAND_POLYLINE);
}

on(dom.byId("point"),"click", execute3);
function execute3(){
  toolbar.activate(Draw.POINT);
}

function addGraphic(eventObj){
   toolbar.deactivate();
   map.hideZoomSlider(); 
   var geometry = eventObj.geometry;
   var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new    SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new Color([255,0,0]),2), new    Color([255,255,0,2.5]));
   var graphic = new esri.Graphic(geometry, symbol);
   map.graphics.add(graphic);
   queryFeature(eventObj.geometry);
}

function queryFeature(geom){
   var selectQuery = new Query();
   selectQuery.geometry = geom;
   myfeatureLayer.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW);
}

myfeatureLayer.on("selection-complete", addingFieldValue);
   function addingFieldValue(evt) 
{
arrayUtil.forEach(evt.features, function (feature) {
   var addfieldValue= feature.attributes.ADDRESS;
   var parcelfieldValue = feature.attributes.TYPE;
   var landfieldValue = feature.attributes.FOLIO_TYPE;
   mySearch.set("value", addfieldValue);
   parcelSearch.set("value", parcelfieldValue);
   landuseSearch.set("value", landfieldValue);
});

 // Attribute Inspector starts
map.on("layers-add-result", initSelectToolbar);

function initSelectToolbar(evnt) {  

    var layerInfos = [{
    'featureLayer': myfeatureLayer
    }];

    var attInspector = new esri.dijit.AttributeInspector({
    layerInfos: layerInfos
    }, "attributesDiv");

    attInspector.on("attribute-change", function(evnt) {
    var updateFeature = evnt.feature;
    updateFeature.attributes[evnt.fieldName] = evnt.fieldValue;
    });

    var savebutton = new Button({ label: "Save", "class":    "saveButton"},domConstruct.create("div"));
    domConstruct.place(savebutton.domNode, attInspector.deleteBtn.domNode, "after");

    savebutton.on("click", function() {
    updateFeature.getLayer().applyEdits(null, [updateFeature], null);
    });
    attInspector.on("delete", function(evnt) {
    var feature = evnt.feature;
    feature.getLayer().applyEdits(null, null, [feature]);
    map.infoWindow.hide();
    });

    var selectQuery = new esri.tasks.Query();

    myfeatureLayer.on("click", function(et) {
    selectQuery.objectIds = [et.graphic.attributes.OBJECTID];
    myfeatureLayer.selectFeatures(selectQuery); 
    });
    map.addLayers("myfeatureLayer");
}
});
1

I think you need to add mode when you initialize the Feature layer, like:

var myfeatureLayer = new FeatureLayer("http://arcgis-serveruf-1981283418.us-east-1.elb.amazonaws.com/arcgis/rest/services/MyFiles/LandParcels/FeatureServer/0",{
   mode: FeatureLayer.MODE_ONDEMAND,
   outFields: ["*"]
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.