Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intended behavior for Identify widget? #713

Open
ghost opened this issue Apr 5, 2017 · 0 comments
Open

Intended behavior for Identify widget? #713

ghost opened this issue Apr 5, 2017 · 0 comments
Labels

Comments

@ghost
Copy link

ghost commented Apr 5, 2017

Using the latest CMV, if I have a 'feature'-type layer and a 'dynamic'-type layer, and use the Identify widget's dropdown to specify only the dynamic layer, I'll still get the feature layer when I go to identify something.

Alternatively, if I choose the feature layer from the dropdown and identify a feature, I'll get the same twice.

What appears to be happening is that the feature layer's graphic gets selected, line 215-227 of Identify.js, and then it gets added to the list of layers to be identified again around line 238-248.

If all my layers are dynamic, it seems to work as intended.

What should the widget be doing?

I needed it to not care whether the layers were feature or dynamic, and I ended up fixing these issues by adding the checks to executeIdentifyTask and the helper function below to Identify.js. Here are those fixes if it's useful to anyone else... there may be cleaner ways to do this but it seems to be working. I'll submit a pull request if the main CMV people think it'd be appropriate.

Thanks

            executeIdentifyTask: function (evt) {

            var mapPoint = evt.mapPoint;
            var identifyParams = this.createIdentifyParams(mapPoint);
            var identifies = [];
            var identifiedlayers = [];
            var selectedLayer = this.getSelectedLayer();

            if (!this.checkForGraphicInfoTemplate(evt)) {
                // return;
                var layer = array.filter(this.layers, function (l) {
                    return l.ref.id === evt.graphic._layer.id;
                })[0];
                if (!layer) {
                    return;
                }
                if (selectedLayer === '***' || layer.ref.id === selectedLayer.split('||')[0]) { //added by me
                    identifiedlayers.push(layer);
                    var d = new Deferred();
                    identifies.push(d.promise);
                    d.resolve([{ feature: evt.graphic }]);
                } //added by me
            }

            this.map.infoWindow.hide();
            this.map.infoWindow.clearFeatures();

            // don't identify on shift-click, ctrl-click or alt-click
            if (evt.shiftKey || evt.ctrlKey || evt.altKey) {
                return;
            }


            array.forEach(this.layers, lang.hitch(this, function (lyr) {
                var layerIds = this.getLayerIds(lyr, selectedLayer);
                if (layerIds.length > 0) {
                    if (!this.doesLayerExistInLayerList(lyr, identifiedlayers)) {//added by me
                        var params = lang.clone(identifyParams);
                        params.layerDefinitions = lyr.ref.layerDefinitions;
                        params.layerIds = layerIds;
                        if (lyr.ref.timeInfo && lyr.ref.timeInfo.timeExtent && this.map.timeExtent) {
                            params.timeExtent = new TimeExtent(this.map.timeExtent.startTime, this.map.timeExtent.endTime);
                        }
                        identifies.push(lyr.identifyTask.execute(params));
                        identifiedlayers.push(lyr);
                    }//added by me
                }
            }));
            if (identifies.length > 0) {
                this.map.infoWindow.setTitle(this.i18n.mapInfoWindow.identifyingTitle);
                this.map.infoWindow.setContent('<div class="loading"></div>');
                this.map.infoWindow.show(mapPoint);
                all(identifies).then(lang.hitch(this, 'identifyCallback', identifiedlayers), lang.hitch(this, 'identifyError'));
            }
        },
        // function added by me
        doesLayerExistInLayerList: function (layer, layerList) {
            var foundDuplicate = false;
            var layerIdToCheck = layer.ref.id;
            array.forEach(layerList, function (lyr) {
                if (lyr.ref.id === layerIdToCheck || foundDuplicate) {
                    foundDuplicate = true;
                }
            });
            return foundDuplicate;
        },
@green3g green3g added the bug label Jul 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant