0

I am trying to figure out how to use the Identify tool with imported layers from a computer. I have tried to see if it is possible to use IdentifyTask, but it requires a URL from the layer to use. I've looked into changing the layerOption in the IdentifyParameters to LAYER_OPTION_VISIBLE. However, it is already set to LAYER_OPTION_ALL and it only seems to pull features from the layer's URL given in new IdentifyTask(layer.url).

Code for the map click handler for the identify tool:

var map = mapService.getEsriMap();
map.infoWindow.hide();

map.graphics.clear();
return map.on('click', function (evt) {
    _.each(map.graphics.graphics, function (graphic) {
        if (graphic.selected) {
            map.graphics.remove(graphic);
            graphic.symbol.setColor(graphic.originalColor);
            graphic.selected = false;
            map.graphics.add(graphic);
        }
    });
    var features = [];
    var idParams = new IdentifyParameters();
    var symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,
        idParams.tolerance,
        new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 255, 0.5]), 1),
        new dojo.Color([0, 0, 255, 0.5]));
    var graphic = new Graphic(evt.mapPoint, symbol);

    map.graphics.clear();

    var processIdentifyTaskResponse = function (response) {
        var layer = this.layer;
        if (response.length !== 0) {
            // Stores the selected features and their details
            _.map(response, function (result) {
                var feature = result.feature;
                var template = new InfoTemplate('${name}');
                template.setTitle(layer.sDispNm);
                feature.setInfoTemplate(template);
                features.push(feature);
            });
        }
    };

    // Sets up a filter to see which layers the features are located in
    var identifyParams = new IdentifyParameters();
    identifyParams.layerIds = [0];
    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
    identifyParams.tolerance = appInfo.IdentifyTolerance;
    identifyParams.width = map.width;
    identifyParams.height = map.height;
    identifyParams.returnGeometry = true;
    identifyParams.geometry = evt.mapPoint;
    identifyParams.mapExtent = map.extent;

    // Filters through the layers to see which features are located in which layers
    var identifyLayers = _.where(appInfo.modules.layers, { svisible: true, sidentify: true });
    var identifyTaskPromises = [];
    $scope.showSpinner = true;
    _.each(identifyLayers, function (layer) {
        var identifyTask = new IdentifyTask(layer.url);
        var identifyTaskPromise =
            identifyTask.execute(identifyParams).then(function (result) {
                return processIdentifyTaskResponse.bind({ layer: layer }, result)();
            }, function (error) {
                console.log(error);
                return error;
            });
        identifyTaskPromises.push(identifyTaskPromise);
    });

    // Adds the features to the info window to navigate through
    $q.all(identifyTaskPromises).then(function () {
        if (features.length > 0) {
            map.infoWindow.setFeatures(features);
        } else {
            map.infoWindow.clearFeatures();
            map.infoWindow.setContent("No features to display");
        }
        map.infoWindow.show(evt.mapPoint);
        map.graphics.add(graphic);
        $scope.showSpinner = false;
    });

    $('.close').click(function () {
        map.ClearAllButCapture();
        map.infoWindow.hide();
    });
});

I am using the same code given in this example to load in a shapefile: https://developers.arcgis.com/javascript/3/jssamples/portal_addshapefile.html

I've looked into modifying the featureLayer.on('click', function () {}) to send a copy of attributes to the infoWindow's features list, but this only works on the top most imported feature.

Your Answer

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

Browse other questions tagged or ask your own question.