-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from theduckylittle/search-all-fields
Improvements to search
- Loading branch information
Showing
5 changed files
with
121 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # How-to let the user choose a search layer | ||
|
|
||
| Sometimes data is stored across multiple layers and writing | ||
| multiple instances of the Search service is too laborious for | ||
| both the administrator and the user. This is an example | ||
| configuration that will allow searching two different layers, | ||
| with two different field names, from the same text box. | ||
|
|
||
| ## Code | ||
|
|
||
| This example refers to the `firestations-wfs` layer. This is used in other | ||
| tutorials and the data is included in the gm3-demo-data repository. | ||
|
|
||
| ```xml | ||
| <map-source name="firestations-wfs" type="mapserver-wfs"> | ||
| <file>./demo/firestations/firestations.map</file> | ||
| <param name="typename" value="ms:fire_stations" /> | ||
| <layer name="fire_stations" selectable="true" title="Firestations"> | ||
| <template name="select"><![CDATA[ | ||
| <div class="result-item"> | ||
| <div class="result-title"> | ||
| Firestation | ||
| </div> | ||
| <b>Station City:</b> {{ properties.Dak_GIS__4 }}<br> | ||
| <b>Station Number:</b> {{ properties.Dak_GIS__5 }}<br> | ||
| <div> | ||
| ]]></template> | ||
| <template name="search" alias="select" /> | ||
| </layer> | ||
| </map-source> | ||
| ``` | ||
|
|
||
| ### In app.js | ||
|
|
||
| ```javascript | ||
| app.registerService('super-search', SearchService, { | ||
| fields: [ | ||
| { | ||
| type: 'select', | ||
| name: 'layer', | ||
| options: [ | ||
| {value: 'vector-parcels/parcels', label: 'Parcel Owners'}, | ||
| {value: 'firestations-wfs/fire_stations', label: 'Firestations'} | ||
| ] | ||
| }, { | ||
| type: 'text', | ||
| name: 'search-value', | ||
| } | ||
| ], | ||
| prepareFields: function(fields) { | ||
| var values = getFieldValues(fields); | ||
| var field_name = { | ||
| 'vector-parcels/parcels' : 'OWNER_NAME', | ||
| 'firestations-wfs/fire_stations' : 'Dak_GIS__4' | ||
| }; | ||
| return [{ | ||
| comparitor: 'ilike', | ||
| name: field_name[values['layer']], | ||
| value: values['search-value'] | ||
| }]; | ||
| }, | ||
| getSearchLayers: function(searchLayers, fields) { | ||
| console.log(getFieldValues(fields)); | ||
| return [getFieldValues(fields)['layer']]; | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| ### In the catalog | ||
|
|
||
| ```xml | ||
| <toolbar> | ||
| ... | ||
| <tool name="super-search" title="Super Search" type="service"/> | ||
| ... | ||
| </toolbar> | ||
| ``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters