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

Does legend widget work for map service beside feature service? #659

Closed
JudyZhou opened this issue Jan 6, 2017 · 9 comments
Closed

Does legend widget work for map service beside feature service? #659

JudyZhou opened this issue Jan 6, 2017 · 9 comments

Comments

@JudyZhou
Copy link

JudyZhou commented Jan 6, 2017

My viewer uses map service, not feature service. The legend does not work in a proper way. legend panel only display legend for default layers turned on at initial time. When I turn on/off layers the legend doesn't change accordingly. Please help!

@tmcgee
Copy link
Member

tmcgee commented Jan 6, 2017

@JudyZhou The Legend widget is an Esri widget not a CMV widget. The layers that are supported by that widget are listed in the documentation. I'm not sure why that widget behaves the way it does but for what its worth, there have been a few other comments recently about that Esri Legend widget not properly updating and reflecting the state of the map.

@JudyZhou
Copy link
Author

JudyZhou commented Jan 9, 2017

@tmcgee thanks for the help. I found that even the demo from this website http://demo.cmv.io/viewer, when I check/uncheck layers in dynamic map service Louisville Public Safety/Public Safety or Louisville Public Safety/Emergency Operations, the legend doesn't update, but when uncheck and check again top level service name Louisville Public Safety, then the legend update. Legend widget doesn't have issue with ESRI Web AppBuilder though. Please check.

@green3g
Copy link
Member

green3g commented Jan 9, 2017

@JudyZhou Its true, the web app builder does update the legend when layers and sublayers are toggled. Web app builder's layer control and legend widget are dependent on the web app builder framework though, so if you'd like to use those widgets you would need to set up web app builder's files in cmv, and use @tmcgee 's web app builder mixin for cmv.

@tmcgee
Copy link
Member

tmcgee commented Jan 10, 2017

@roemhildtg @JudyZhou

Does a new CMV widget like below solve the issue(s)?

define([
    'dojo/_base/declare',
    'dijit/_WidgetBase',
    'dojo/_base/lang',
    'esri/dijit/Legend'
], function (
    declare,
    _WidgetBase,
    lang,
    Legend
) {
    return declare([_WidgetBase], {
        startup: function () {
            this.inherited(arguments);

            this.legend = new Legend({
                arrangement: this.arrangement || Legend.ALIGN_LEFT,
                autoUpdate: this.autoUpdate || true,
                id: this.id + '_legend',
                layerInfos: this.layerInfos,
                map: this.map,
                respectCurrentMapScale: this.respectCurrentMapScale || true
            }, this.domNode);
            this.legend.startup();

            this.map.on('update-end', lang.hitch(this, function () {
                this.legend.refresh();
            }));

            this._started = true;
        }
    });
});

@green3g
Copy link
Member

green3g commented Jan 10, 2017

Looks like that would work. I'm guessing update end fires when any layer is updated also?

@tmcgee
Copy link
Member

tmcgee commented Jan 10, 2017

That is exactly what the event is for. Per the API docs Fires after layers that are updating their content have completed. Not clear why the Legend dijit doesn't listen to it by default.

@green3g
Copy link
Member

green3g commented Jan 10, 2017

I've just tested it in the develop branch. It works. I can make a pull request.

green3g added a commit to green3g/cmv-app that referenced this issue Jan 10, 2017
 - adds new gis/dijit/Legend widget from cmv#659
 - fixes cmv#340
 - fixes cmv#294
@green3g
Copy link
Member

green3g commented Jan 10, 2017

@JudyZhou when you get a chance to test the widget out, please let us know if it fixes your issue.

@tmcgee
Copy link
Member

tmcgee commented Jan 11, 2017

new core CMV Legend widget added in #660

@tmcgee tmcgee closed this as completed Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants