@@ -139,16 +139,49 @@ const fetchWithTimeout = (url, options, timeout = 10000) => {
139
139
}
140
140
141
141
const fetchAddressData = ( rawSearchTerm , callResponse ) => {
142
- fetch ( `https://spatial.stockport.gov. uk/geoserver/wfs?request=getfeature&outputformat=json&typename=address:llpg_points&cql_filter=address_search%20ilike%27%25 ${ rawSearchTerm } %25%27 ` )
143
- . then ( res => res . clone ( ) . json ( ) )
142
+ fetch ( `https://api.os. uk/search/places/v1/find?query= ${ rawSearchTerm } &fq=local_custodian_code:4235&fq=CLASSIFICATION_CODE:R* CLASSIFICATION_CODE:R* CLASSIFICATION_CODE:C*&key=b8uAAAo0AA8nPPCO37NG0GPKw7g8w53G&dataset=LPI&output_srs=EPSG:4326 ` )
143
+ . then ( res => res . json ( ) )
144
144
. then ( response => {
145
- callResponse ( response . features . map ( item => {
146
- const address = item . properties . address . replace ( / \r \n / g, ', ' ) . trim ( )
147
- return { 'loc' : item . geometry . coordinates . reverse ( ) , 'title' : address }
148
- } ) )
145
+ console . log ( response )
146
+ const sortedResults = response . results
147
+ . filter ( item => item . LPI . MATCH >= 0.3 )
148
+ . sort ( ( a , b ) => {
149
+ if ( b . LPI . MATCH !== a . LPI . MATCH ) {
150
+ return b . LPI . MATCH - a . LPI . MATCH
151
+ }
152
+
153
+ if ( a . LPI . PAO_START_NUMBER !== b . LPI . PAO_START_NUMBER ) {
154
+ return a . LPI . PAO_START_NUMBER - b . LPI . PAO_START_NUMBER
155
+ }
156
+
157
+ return a . LPI . sao_start_number - b . LPI . sao_start_number
158
+ } )
159
+ . map ( item => {
160
+
161
+ const address = item . LPI . ADDRESS . replace ( / \r \n / g, ', ' ) . trim ( )
162
+ const latlng = [ item . LPI . LAT , item . LPI . LNG ]
163
+ return { loc : latlng , title : address }
164
+ } )
165
+
166
+ callResponse ( sortedResults )
167
+ } )
168
+ . catch ( error => {
169
+ console . error ( 'An error occurred on the search lookup:' , error )
149
170
} )
150
171
}
151
172
173
+ //const fetchAddressDataOLDSEARCH = (rawSearchTerm, callResponse) => {
174
+ // fetch(`https://spatial.stockport.gov.uk/geoserver/wfs?request=getfeature&outputformat=json&typename=address:llpg_points&cql_filter=address_search%20ilike%27%25${rawSearchTerm}%25%27`)
175
+ // .then(res => res.clone().json())
176
+ // .then(response => {
177
+ // console.log(rawSearchTerm)
178
+ // callResponse(response.features.map(item => {
179
+ // const address = item.properties.address.replace(/\r\n/g, ', ').trim()
180
+ // return { 'loc': item.geometry.coordinates.reverse(), 'title': address }
181
+ // }))
182
+ // })
183
+ //}
184
+
152
185
const getQueryStringParams = query => {
153
186
return query
154
187
? ( / ^ [ ? # ] / . test ( query ) ? query . slice ( 1 ) : query )
0 commit comments