Filtering what markers are shown on layer depending on search params

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Filtering what markers are shown on layer depending on search params

Asle Benoni
Hi,
I am not sure if this is a GeoServer task. I have an
OpenLayers/Mapfish site using GeoServer 2.1.3 and I want to have a
search box where I search for i.ex. a project name. When I get the
list of projects I click on the projects and the map only shows the
markers from that project. Where do I start to look for clues here? I
see that you can make a layer from SQL but how can I make a dynamic
layer with I guess dynamic SQL?
Thanks for any help!
~asle

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Filtering what markers are shown on layer depending on search params

Larry Theller
If the "projects list" was in postgis as an attribute field
of your features, and if geoserver WMS is styled using that
field, you can do this with Javascript (and CQL) at the web
page level, as we do in
http://driftwatch.agriculture.purdue.edu  where all crops
are in one feature table (each field is a row) and you turn
on and off all fields of specific crops (analogous to your
"projects" I think)using javascript.
In our case the pushpins and polygons are styled by
geoserver using rules in a style:
-style fragment -
<Rule>   <!-- Rule 2: pushpins for crop type: Tomatoes -->
        <ogc:Filter>
          <ogc:PropertyIsEqualTo>
            <ogc:PropertyName>crop</ogc:PropertyName>
            <ogc:Literal>Tomatoes</ogc:Literal>
          </ogc:PropertyIsEqualTo>
        </ogc:Filter>        
       
        <!-- pushpins -->
        <PointSymbolizer>
              <Graphic>
                <ExternalGraphic>
                  <OnlineResource xlink:type="simple"
xlink:href="http://driftwatch.agriculture.purdue.edu/Images/
red_MarkerT.png"/>
                  <Format>image/png</Format>
                </ExternalGraphic>
                <Size><ogc:Literal>30</ogc:Literal></Size>
              </Graphic>
            </PointSymbolizer>
        <!-- end of pushpins -->  
- Larry


-----Original Message-----
From: Asle Benoni [mailto:[hidden email]]
Sent: Monday, April 30, 2012 8:35 AM
To: [hidden email]
Subject: [Geoserver-users] Filtering what markers are shown
on layer depending on search params

Hi,
I am not sure if this is a GeoServer task. I have an
OpenLayers/Mapfish site using GeoServer 2.1.3 and I want to
have a search box where I search for i.ex. a project name.
When I get the list of projects I click on the projects and
the map only shows the markers from that project. Where do I
start to look for clues here? I see that you can make a
layer from SQL but how can I make a dynamic layer with I
guess dynamic SQL?
Thanks for any help!
~asle

------------------------------------------------------------
------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's
security and threat landscape has changed and how IT
managers can respond. Discussions will include endpoint
security, mobile security and the latest in malware threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Filtering what markers are shown on layer depending on search params

Asle Benoni
Thanks. The tables are in Postgis and the layers are defined from the
PostgreSQL server.
How do you do this in your javascript? I have a search that works but
not sure how to send the data to the layer.
If I can use a filter I guess I would need something like this:
......
        <ogc:Filter>
          <ogc:PropertyContains>  // I can't find this kind of filter
            <ogc:PropertyName>projectnavm</ogc:PropertyName>
            <ogc:Literal>'%search_pattern%'</ogc:Literal>
          </ogc:PropertyContains>
        </ogc:Filter>
......

How do you send the data to GeoServer and how do you refresh the layer(s)?
~asle


2012/4/30 Larry Theller <[hidden email]>:

> If the "projects list" was in postgis as an attribute field
> of your features, and if geoserver WMS is styled using that
> field, you can do this with Javascript (and CQL) at the web
> page level, as we do in
> http://driftwatch.agriculture.purdue.edu  where all crops
> are in one feature table (each field is a row) and you turn
> on and off all fields of specific crops (analogous to your
> "projects" I think)using javascript.
> In our case the pushpins and polygons are styled by
> geoserver using rules in a style:
> -style fragment -
> <Rule>   <!-- Rule 2: pushpins for crop type: Tomatoes -->
>        <ogc:Filter>
>          <ogc:PropertyIsEqualTo>
>            <ogc:PropertyName>crop</ogc:PropertyName>
>            <ogc:Literal>Tomatoes</ogc:Literal>
>          </ogc:PropertyIsEqualTo>
>        </ogc:Filter>
>
>        <!-- pushpins -->
>        <PointSymbolizer>
>              <Graphic>
>                <ExternalGraphic>
>                  <OnlineResource xlink:type="simple"
> xlink:href="http://driftwatch.agriculture.purdue.edu/Images/
> red_MarkerT.png"/>
>                  <Format>image/png</Format>
>                </ExternalGraphic>
>                <Size><ogc:Literal>30</ogc:Literal></Size>
>              </Graphic>
>            </PointSymbolizer>
>        <!-- end of pushpins -->
> - Larry
>
>
> -----Original Message-----
> From: Asle Benoni [mailto:[hidden email]]
> Sent: Monday, April 30, 2012 8:35 AM
> To: [hidden email]
> Subject: [Geoserver-users] Filtering what markers are shown
> on layer depending on search params
>
> Hi,
> I am not sure if this is a GeoServer task. I have an
> OpenLayers/Mapfish site using GeoServer 2.1.3 and I want to
> have a search box where I search for i.ex. a project name.
> When I get the list of projects I click on the projects and
> the map only shows the markers from that project. Where do I
> start to look for clues here? I see that you can make a
> layer from SQL but how can I make a dynamic layer with I
> guess dynamic SQL?
> Thanks for any help!
> ~asle
>
> ------------------------------------------------------------
> ------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's
> security and threat landscape has changed and how IT
> managers can respond. Discussions will include endpoint
> security, mobile security and the latest in malware threats.
> http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Geoserver-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geoserver-users
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Geoserver-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geoserver-users

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Filtering what markers are shown on layer depending on search params

Phil Scadden

> How do you do this in your javascript? I have a search that works but
> not sure how to send the data to the layer.
Look at OL Filter examples.

Or consider ECQL (see geoserver docs for syntax). Add it to OL with

Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Filtering what markers are shown on layer depending on search params

Phil Scadden
In reply to this post by Asle Benoni
whoops too quick with send.
Add it in OL with
                 filterParams["cql_filter"] = my CQL filter;
                 layer.mergeNewParams(filterParams);


Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Filtering what markers are shown on layer depending on search params

Asle Benoni
Thanks for pointing me to the CQL filter. I have looked at this and
found this page with a starter insight:
http://www.azavea.com/blogs/labs/2011/06/using-the-cql_filter-parameter-with-openlayers-wms-layers/

Still I do not know how to call this in my page. In the example above it says:
wms_layer.mergeNewParams({'CQL_FILTER':.....
Since I am a newbie I don't know how to call my layer. I.ex. I make a
layer this way:

var createWmsLayer = function(name, url, params, options) {
        map.addLayer(new OpenLayers.Layer.WMS(name, url, params, options));
    };

createWmsLayer("<span class='locc'>Ikke listet</span>",
"http://localhost/geoserver/wms",
                {layers: 'gbif_ns:ikke_listet',format: 'image/png',
transparent: 'true'}, {singleTile: true, ratio: 1, isBaseLayer:false,
visibility: false}
                        );

So what do I put in the "wms_layer" in the example above?

I tried to make a function like this:
    function CQLfilter(param){
    filter_list = []
        filter_list.append("collector LIKE '%H%' ")
        var cql = ' AND '.join(filter_list)
        gbif_ns:ikke_listet.mergeNewParams({'CQL_FILTER': "collector LIKE '%H%' "})
    }
 - I get an error -> ReferenceError: Can't find variable: ikke_rodlistet
So how do I reference the layer exactly?

Any help in the right direction is highly appreciated!
~asle

2012/4/30 Phil Scadden <[hidden email]>:

> whoops too quick with send.
> Add it in OL with
>                 filterParams["cql_filter"] = my CQL filter;
>                 layer.mergeNewParams(filterParams);
>
>
> Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Geoserver-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geoserver-users

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Filtering what markers are shown on layer depending on search params

Asle Benoni
Sorry I meant to write this:
- I get an error -> ReferenceError: Can't find variable: ikke_listet

So it does not kick on "gbif_ns" which is the namespace but on the
"ikke_listet" which is the name of the layer in GeoServer. In
GeoServer the layer shows up like this: ikke_liste and I create the
wms layer by calling the layer "gbif_ns:ikke_rodlistet". So how do I
reference it in the function with "mergeNewParams" ?
Thanks.
~asle



2012/5/9 Asle Benoni <[hidden email]>:

> Thanks for pointing me to the CQL filter. I have looked at this and
> found this page with a starter insight:
> http://www.azavea.com/blogs/labs/2011/06/using-the-cql_filter-parameter-with-openlayers-wms-layers/
>
> Still I do not know how to call this in my page. In the example above it says:
> wms_layer.mergeNewParams({'CQL_FILTER':.....
> Since I am a newbie I don't know how to call my layer. I.ex. I make a
> layer this way:
>
> var createWmsLayer = function(name, url, params, options) {
>        map.addLayer(new OpenLayers.Layer.WMS(name, url, params, options));
>    };
>
> createWmsLayer("<span class='locc'>Ikke listet</span>",
> "http://localhost/geoserver/wms",
>                {layers: 'gbif_ns:ikke_listet',format: 'image/png',
> transparent: 'true'}, {singleTile: true, ratio: 1, isBaseLayer:false,
> visibility: false}
>                        );
>
> So what do I put in the "wms_layer" in the example above?
>
> I tried to make a function like this:
>    function CQLfilter(param){
>        filter_list = []
>        filter_list.append("collector LIKE '%H%' ")
>        var cql = ' AND '.join(filter_list)
>        gbif_ns:ikke_listet.mergeNewParams({'CQL_FILTER': "collector LIKE '%H%' "})
>    }
>  - I get an error -> ReferenceError: Can't find variable: ikke_rodlistet
> So how do I reference the layer exactly?
>
> Any help in the right direction is highly appreciated!
> ~asle
>
> 2012/4/30 Phil Scadden <[hidden email]>:
>> whoops too quick with send.
>> Add it in OL with
>>                 filterParams["cql_filter"] = my CQL filter;
>>                 layer.mergeNewParams(filterParams);
>>
>>
>> Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.
>>
>>
>> ------------------------------------------------------------------------------
>> Live Security Virtual Conference
>> Exclusive live event will cover all the ways today's security and
>> threat landscape has changed and how IT managers can respond. Discussions
>> will include endpoint security, mobile security and the latest in malware
>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>> _______________________________________________
>> Geoserver-users mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/geoserver-users

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Filtering what markers are shown on layer depending on search params

Asle Benoni
In reply to this post by Asle Benoni
Thanks, I am trying to get this.
Even if I change the createLayer function I am still confused as to
the layer name:

    function createWmsLayer(name, url, params, options) {
      var layer = new OpenLayers.Layer.WMS(name, url, params, options)
      map.addLayer(layer);
      return layer;
  };

createWmsLayer("<span class='locc'>Ikke listet</span>",
"http://localhost/geoserver/wms",
                     {layers: 'gbif_ns:ikke_listet',format:
'image/png', transparent: 'true'}, {singleTile: true, ratio: 1,
isBaseLayer:false,
                      visibility: false} );


It seems the layer name is now: "<span class='locc'>Ikke
listet</span>". That is the way it is displayed and there may be a
better way to style the menu (that is why I do it that way).

If I understand you correctly I should put the filter params inside
the createWMS function? And run the create function every time I do a
search? All these layers are from one PostGIS DB and filtered in
GeoServer. How about this:

    function createWmsLayer(name, url, params, options) {
      var layer = new OpenLayers.Layer.WMS(name, url, params, options)
      map.addLayer(layer);
      return layer;
        // get search field value... var searchF =
$('#searchField').val() // query method
        // if checkbox is A then cqlParam = "collector", if checbox is
B then cqlParam ="species" ......
               filterParams = {
                    filter: null,
                    cql_filter: cqlPa LIKE '%" + search + "%' ",
                    featureId: null
                };
         };

Am I on the right path? Thanks for helping out :-)
~asle

2012/5/9 Phil Scadden <[hidden email]>:

> This is all client side stuff - you would be better placing queries like
> this on the openlayers-users mailing list.
>
> However, looking at your issue.
>> Still I do not know how to call this in my page. In the example above it says:
>> wms_layer.mergeNewParams({'CQL_FILTER':.....
>> Since I am a newbie I don't know how to call my layer. I.ex. I make a
>> layer this way:
>>
>> var createWmsLayer = function(name, url, params, options) {
>>          map.addLayer(new OpenLayers.Layer.WMS(name, url, params, options));
>>      };
>>
>> createWmsLayer("<span class='locc'>Ikke listet</span>",
>> "http://localhost/geoserver/wms",
>>                  {layers: 'gbif_ns:ikke_listet',format: 'image/png',
>> transparent: 'true'}, {singleTile: true, ratio: 1, isBaseLayer:false,
>> visibility: false}
>>                          );
>>
>> So what do I put in the "wms_layer" in the example above?
>>
>> I tried to make a function like this:
>>      function CQLfilter(param){
>>       filter_list = []
>>       filter_list.append("collector LIKE '%H%' ")
>>       var cql = ' AND '.join(filter_list)
>>       gbif_ns:ikke_listet.mergeNewParams({'CQL_FILTER': "collector LIKE '%H%' "})
>>      }
>>
>
> With your factory:
>
> var createWmsLayer = function(name, url, params, options) {
>         map.addLayer(new OpenLayers.Layer.WMS(name, url, params, options));
>     };
>
> The WMS layer is an anonymous variable. This makes it difficult to do
> other operations on.
>
> One approach would be
>
>   function createWmsLayer(name, url, params, options) {
>       var layer = new OpenLayers.Layer.WMS(name, url, params, options)
>       map.addLayer(layer);
>       return layer;
>  };
>
> You need the layer object to do other things with.
>
> The CQLfilter doesnt make much sense me. I would pass in the layer object from createWmsLayer.
>
> When I add a CQL filter, I do it with
>        filterParams = {
>                     filter: null,
>                     cql_filter: "collector LIKE '%H%' ",
>                     featureId: null
>                 };
>       layer.mergeNewParams(filterParams);
>
> where layer is what is returned from createWmsLayer. If you want to stick with anomymous layers, then you have to search the layers array of the map object for the one you want to apply the CQL too.
>
> --
> Phil Scadden, Senior Scientist GNS Science Ltd 764 Cumberland St,
> Private Bag 1930, Dunedin, New Zealand Ph +64 3 4799663, fax +64 3 477 5232
>
> Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.
>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geoserver-users