1

When attempting to add features to a featureLayer with applyEdits, the features do not get added to the layer.

    var featureCollection = JSON.parse(mapdata);
    var features = JSON.parse(mapdata).featureSet.features;
    featureCollection.featureSet.features = [];
    var pointFeatures = [];
    var featureLayer = new esri.layers.FeatureLayer(featureCollection, {
       id: 'HourlyDataLayer'
    });

    for (var i = 0; i < features.length; i++) {
       if (features[i].attributes[selectedField] > maxValue) {
          maxValue = features[i].attributes[selectedField];
       }
       if (features[i].attributes[selectedField] < minValue) {
          minValue = features[i].attributes[selectedField];
       }
    }

    for (var i = 0; i < features.length; i++) {
       var feature = features[i];
       var size = (feature.attributes[selectedField] - minValue) * ((150 - 5) / (maxValue - minValue)) + 5
       var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, size,
           new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
           new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
       var attr = feature.attributes;
       var latlong = LatLonToWebMercator(feature.geometry.x, feature.geometry.y);
       var geometry = new esri.geometry.Point(latlong[0], latlong[1], spatialReference);
       var graphic = new esri.Graphic(geometry, symbol);
       graphic.setInfoTemplate(infoTemplate);
       graphic.setAttributes(attr);
       pointFeatures.push(graphic);
   }

   featureLayer.setEditable(true);
   featureLayer.applyEdits(pointFeatures, null, null);

   map.addLayers([featureLayer]);
1

Turns out this was really easy, but not at all intuitive to me, and I didn't see anything in documentation to suggest it, but you have to add the FeatureLayer to the map before you can apply edits:

    var featureCollection = JSON.parse(mapdata);
    var features = JSON.parse(mapdata).featureSet.features;
    featureCollection.featureSet.features = [];
    var pointFeatures = [];
    var featureLayer = new esri.layers.FeatureLayer(featureCollection, {
       id: 'HourlyDataLayer'
    });

    map.addLayers([featureLayer]);

    for (var i = 0; i < features.length; i++) {....
    featureLayer.applyEdits(pointFeatures, null, null);
  • This seems to be broken at API v3.23. Works at 3.22. Is the API work on github or someplace where it's easy to file a bug report? Every time I try and find where to file I bug report I get worn out searching. :) – GetFuzzy Dec 30 '17 at 4:46

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.