[Geomoose-users] Toggle or Turn A Layer On or Off Programmatically from an Action or Service

Reynolds, Michael J. (MNIT) mike.reynolds at state.mn.us
Tue Sep 4 11:46:14 PDT 2018


That worked much better.

Since we’re displaying mapserver type layers and searching wfs type layers (for instance query-as) we actually wanted the search service to turn on the related layer.

/** custom-search.js */
/** constructor */

    /** Define the layer(s) to turn on during the search.
     *  Use searchLayers if turnLayersOn is not configured.
     */
    this.turnLayersOn = options.turnLayersOn ? options.turnLayersOn : [];
    if (options.turnLayersOn) {
                this.turnLayersOn = options.turnLayersOn;
    } else if (options.searchLayers) {
                this.turnLayersOn = options.searchLayers;
    } else {
                this.turnLayersOn = [];
    };

/** added this to the this.query… */

this.query = function(selection, fields) {

….
        // turn each search layer on, regardless of results found
        for(var i = 0, ii = this.turnLayersOn.length; i < ii; i++) {
                var path = this.turnLayersOn[i];
                var path_source = path.split('/')[0];
            var path_layer = path.split('/')[1];
                                                Application.dispatch({type: "MAPSOURCE_LAYER_VIS", mapSourceName: path_source, layerName: path_layer, on: true});
        }
…

And an example apps.js search service config leveraging this…
…
                //CMMT Boreholes
                app.registerService('search-cmmtboreholes', SearchService, {
                    searchLayers: ['cmmt_boreholes-wfs/boreholes_search'],
                    turnLayersOn: ['cmmt_boreholes/boreholes'],
                    fields: [
                        {type: 'text', label: 'SP Number', name: 'sp'},
                    ]
                                });
…

From: Dan Little [mailto:theduckylittle at gmail.com]
Sent: Saturday, September 1, 2018 7:26 AM
To: Reynolds, Michael J. (MNIT) <mike.reynolds at state.mn.us>
Cc: GeoMOOSE Users List <geomoose-users at lists.osgeo.org>
Subject: Re: [Geomoose-users] Toggle or Turn A Layer On or Off Programmatically from an Action or Service

Try moving the dispatch to the query method. The Services don't expose the full react-component cycle yet.

On Fri, Aug 31, 2018 at 11:21 AM Reynolds, Michael J. (MNIT) <mike.reynolds at state.mn.us<mailto:mike.reynolds at state.mn.us>> wrote:
I tucked that into a search service resultsAsHtml function but that resulted in the pesky
Warning: Cannot update during an existing state transition (such as within `render` or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.

Do I use app.registerAction and app.startAction instead? Or should I use app.dispatch from some other service location?

From: Dan Little [mailto:theduckylittle at gmail.com<mailto:theduckylittle at gmail.com>]
Sent: Friday, August 31, 2018 10:22 AM
To: Reynolds, Michael J. (MNIT) <mike.reynolds at state.mn.us<mailto:mike.reynolds at state.mn.us>>
Cc: GeoMOOSE Users List <geomoose-users at lists.osgeo.org<mailto:geomoose-users at lists.osgeo.org>>
Subject: Re: [Geomoose-users] Toggle or Turn A Layer On or Off Programmatically from an Action or Service

This is the ugly answer:

app.dispatch({type: "MAPSOURCE_LAYER_VIS", mapSourceName: 'source', layerName: 'layer', on: true});

We should write a wrapper function to make that easier.

On Thu, Aug 30, 2018 at 9:02 AM Reynolds, Michael J. (MNIT) <mike.reynolds at state.mn.us<mailto:mike.reynolds at state.mn.us>> wrote:
Looking for the object and method that will toggle a layer visibility from an Action or Service.

I didn't see examples within the docs or existing services/actions.

On a related note, the geomoose search service, doesn't seem to turn on the layer being searched.  It shows a results layer but along with it, we'd like to have the  whole layer appear as reference.  Do we have our search configured wrong?
_______________________________________________
Geomoose-users mailing list
Geomoose-users at lists.osgeo.org<mailto:Geomoose-users at lists.osgeo.org>
https://lists.osgeo.org/mailman/listinfo/geomoose-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geomoose-users/attachments/20180904/683616f3/attachment-0001.html>


More information about the Geomoose-users mailing list