Custom Geocoder based on WFS - geosolutions-it/MapStore GitHub Wiki
Needed Files
In order to use this plugin you need to include this files in the build.cfg:
gxp/src/script/plugins/spatialselector/GeocoderSpatialSelectorMethod.js
gxp/src/script/plugins/spatialselector/SpatialSelector.js
widgets/form/spatialselector/GeocoderSpatialSelectorMethod.js
NOTE: In the default configuration this is already done.
Plugin description
This widget is based on geocoder spatial selectors to perform simple location searches by WFS.
The plugin layout shows two WFS combo searches:
- one for the street name
- one for the street number
Configuration Example
You can configure it adding this plugin with this configuration:
{
"ptype": "gxp_spatial_selector_geocoder",
"outputTarget": "west",
"text": "Geocoder",
"layoutConfig":{
"xtype": "form",
"buttonAlign": "right",
"autoScroll":true,
"frame":true
},
"crossParameters":{
"name": {
"COD_STRADA":{
"number": "COD_STRADA"
}
}
},
"spatialSelectorsConfig":{
"name":{
"xtype": "gxp_spatial_geocoding_selector",
"showSelectionSummary": false,
"multipleSelection": false,
"searchComboOutputFormat": "json",
"wfsBaseURL": "http://geoserver.comune.genova.it/geoserver/wfs",
"geocoderTypeName": "CTC:V_ASTE_STRADALI_TOPONIMO_SUB",
"geocoderTypeRecordModel":[
{
"name":"id",
"mapping":"id"
},
{
"name":"name",
"mapping":"properties.NOMEVIA"
},
{
"name":"custom",
"mapping":"properties.COD_STRADA"
},
{
"name":"geometry",
"mapping":"geometry"
}
],
"geocoderTypeSortBy":null,
"geocoderTypeQueriableAttributes":[
"COD_STRADA", "NOMEVIA"
],
"spatialOutputCRS": "EPSG:3003",
"geocoderTypePageSize": 10,
"zoomToCurrentExtent": false
},
"number":{
"xtype": "gxp_spatial_geocoding_selector",
"showSelectionSummary": false,
"multipleSelection": false,
"searchComboOutputFormat": "json",
"wfsBaseURL": "http://geoserver.comune.genova.it/geoserver/wfs",
"geocoderTypeName": "SITGEO:CIVICI_COD_TOPON_SUB",
"geocoderTypeRecordModel":[
{
"name":"id",
"mapping":"id"
},
{
"name":"name",
"mapping":"properties.COD_STRADA"
},
{
"name":"custom",
"mapping":"properties.COD_TOPON"
},
{
"name":"geometry",
"mapping":"geometry"
}
],
"geocoderTypeSortBy":null,
"geocoderTypeQueriableAttributes":[
"COD_STRADA", "COD_TOPON"
],
"spatialOutputCRS": "EPSG:3003",
"geocoderTypePageSize": 10,
"zoomToCurrentExtent": false
}
}
}
You need to know the WFS feature model and include it on the geocoderTypeRecordModel
spatial selectors and the crossParameters
.
In this case we use two WFS combo, one for the street name:
...
"name":{
"xtype": "gxp_spatial_geocoding_selector",
"showSelectionSummary": false,
"multipleSelection": false,
"searchComboOutputFormat": "json",
"wfsBaseURL": "http://geoserver.comune.genova.it/geoserver/wfs",
"geocoderTypeName": "CTC:V_ASTE_STRADALI_TOPONIMO_SUB",
"geocoderTypeRecordModel":[
{
"name":"id",
"mapping":"id"
},
{
"name":"name",
"mapping":"properties.NOMEVIA"
},
{
"name":"custom",
"mapping":"properties.COD_STRADA"
},
{
"name":"geometry",
"mapping":"geometry"
}
],
"geocoderTypeSortBy":null,
"geocoderTypeQueriableAttributes":[
"COD_STRADA", "NOMEVIA"
],
"spatialOutputCRS": "EPSG:3003",
"geocoderTypePageSize": 10,
"zoomToCurrentExtent": false
}
...
And another one for the street number:
...
"number":{
"xtype": "gxp_spatial_geocoding_selector",
"showSelectionSummary": false,
"multipleSelection": false,
"searchComboOutputFormat": "json",
"wfsBaseURL": "http://geoserver.comune.genova.it/geoserver/wfs",
"geocoderTypeName": "SITGEO:CIVICI_COD_TOPON_SUB",
"geocoderTypeRecordModel":[
{
"name":"id",
"mapping":"id"
},
{
"name":"name",
"mapping":"properties.COD_STRADA"
},
{
"name":"custom",
"mapping":"properties.COD_TOPON"
},
{
"name":"geometry",
"mapping":"geometry"
}
],
"geocoderTypeSortBy":null,
"geocoderTypeQueriableAttributes":[
"COD_STRADA", "COD_TOPON"
],
"spatialOutputCRS": "EPSG:3003",
"geocoderTypePageSize": 10,
"zoomToCurrentExtent": false
}
...
And I link the first combo with the second one with the COD_STRADA
parameter.
...
"crossParameters":{
"name": {
"COD_STRADA":{
"number": "COD_STRADA"
}
}
}
...
You can see more options for each combo here.