-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into multilayer_active_editing
- Loading branch information
Showing
17 changed files
with
415 additions
and
10 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
Large diffs are not rendered by default.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
g3w-admin/client/static/client/geocoding-providers/bing_places.js
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 @@ | ||
/** | ||
* @file | ||
* @since 3.9.0 | ||
*/ | ||
|
||
(function() { | ||
|
||
const geocoding = initConfig.group.mapcontrols.geocoding || {}; | ||
const provider = document.currentScript.src.split('/').reverse()[0].replace('.js', '') || 'bing_places'; | ||
|
||
// skip when disabled | ||
if (!provider in geocoding.providers) { | ||
return; | ||
} | ||
|
||
/** | ||
* @example https://dev.virtualearth.net/REST/v1/LocalSearch/?query={query}&userMapView={lat,lon,lat,lon}&key={BingMapsKey} | ||
* | ||
* @see https://learn.microsoft.com/en-us/bingmaps/rest-services/locations/local-search | ||
*/ | ||
geocoding.providers[provider].fetch = async function(opts) { | ||
const { XHR } = g3wsdk.core.utils; | ||
const { vendorkeys } = g3wsdk.core.ApplicationState.keys; | ||
|
||
// fallback to generic bing vendor key | ||
vendorkeys[provider] = vendorkeys[provider] || vendorkeys.bing; | ||
|
||
const key = undefined !== vendorkeys[provider] ? vendorkeys[provider] : opts && (new URL(opts.url)).searchParams.get('key'); | ||
|
||
// whether can fetch data from Bing Local Search API | ||
if (!opts || !key) { | ||
return Promise.reject(); | ||
} | ||
|
||
const url = opts.url || 'https://dev.virtualearth.net/REST/v1/LocalSearch/'; | ||
const params = { | ||
query: opts.query, // textual search | ||
userMapView: [opts.extent[1], opts.extent[0], opts.extent[3], opts.extent[2]].join(','), | ||
}; | ||
|
||
// get fallback key from url | ||
if (undefined === vendorkeys.bing) { | ||
params.key = key; | ||
} | ||
|
||
const response = await XHR.get({ url, params }); | ||
|
||
return { | ||
provider, | ||
label: 'Bing Places', | ||
icon: undefined !== opts.icon ? opts.icon : 'poi', | ||
results: 200 === response.statusCode | ||
? response.resourceSets[0].resources | ||
.filter(({ point: { coordinates } })=> ol.extent.containsXY(opts.extent, coordinates[1], coordinates[0])) | ||
.map(result => { | ||
return { | ||
name: result.name, | ||
lon: result.point.coordinates[1], | ||
lat: result.point.coordinates[0], | ||
type: result.entityType, | ||
address: { | ||
road: result.Address.addressLine, | ||
postcode: result.Address.postalCode, | ||
city: result.Address.locality, | ||
state: result.Address.adminDistrict, | ||
country: result.Address.countryRegion, | ||
formatted: result.Address.formattedAddress, | ||
}, | ||
bing: result, | ||
}; | ||
}) | ||
: [], | ||
}; | ||
|
||
}; | ||
|
||
})(); |
76 changes: 76 additions & 0 deletions
76
g3w-admin/client/static/client/geocoding-providers/bing_streets.js
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,76 @@ | ||
/** | ||
* @file | ||
* @since 3.9.0 | ||
*/ | ||
|
||
(function() { | ||
|
||
const geocoding = initConfig.group.mapcontrols.geocoding || {}; | ||
const provider = document.currentScript.src.split('/').reverse()[0].replace('.js', '') || 'bing_streets'; | ||
|
||
// skip when disabled | ||
if (!provider in geocoding.providers) { | ||
return; | ||
} | ||
|
||
/** | ||
* @example https://dev.virtualearth.net/REST/v1/Locations/?query={query}&userMapView={lat,lon,lat,lon}&key={BingMapsKey} | ||
* | ||
* @see https://learn.microsoft.com/en-us/bingmaps/rest-services/locations/find-a-location-by-query | ||
*/ | ||
geocoding.providers[provider].fetch = async function(opts) { | ||
const { XHR } = g3wsdk.core.utils; | ||
const { vendorkeys } = g3wsdk.core.ApplicationState.keys; | ||
|
||
// fallback to generic bing vendor key | ||
vendorkeys[provider] = vendorkeys[provider] || vendorkeys.bing; | ||
|
||
const key = undefined !== vendorkeys.bing ? vendorkeys.bing : opts && (new URL(opts.url)).searchParams.get('key'); | ||
|
||
// whether can fetch data from Bing Locations API | ||
if (!opts || !key /*|| !active*/) { | ||
return Promise.reject(); | ||
} | ||
|
||
const url = opts.url || 'https://dev.virtualearth.net/REST/v1/Locations/'; | ||
const params = { | ||
query: opts.query, // textual search | ||
userMapView: [opts.extent[1], opts.extent[0], opts.extent[3], opts.extent[2]].join(','), | ||
}; | ||
|
||
// get fallback key from url | ||
if (undefined === vendorkeys.bing) { | ||
params.key = key; | ||
} | ||
|
||
const response = await XHR.get({ url, params }); | ||
|
||
return { | ||
provider, | ||
label: 'Bing Streets', | ||
icon: undefined !== opts.icon ? opts.icon : 'road', | ||
results: 200 === response.statusCode | ||
? response.resourceSets[0].resources | ||
.filter(({ point: { coordinates } })=> ol.extent.containsXY(opts.extent, coordinates[1], coordinates[0])) | ||
.map(result => { | ||
return { | ||
name: result.name, | ||
lon: result.point.coordinates[1], | ||
lat: result.point.coordinates[0], | ||
type: result.entityType, | ||
address: { | ||
road: result.address.addressLine, | ||
postcode: result.address.postalCode, | ||
city: result.address.locality, | ||
state: result.address.adminDistrict, | ||
country: result.address.countryRegion, | ||
formatted: result.address.formattedAddress, | ||
}, | ||
bing: result, | ||
}; | ||
}) | ||
: [], | ||
}; | ||
}; | ||
|
||
})(); |
87 changes: 87 additions & 0 deletions
87
g3w-admin/client/static/client/geocoding-providers/google.js
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,87 @@ | ||
/** | ||
* @file | ||
* @since 3.9.0 | ||
*/ | ||
|
||
(function() { | ||
|
||
const geocoding = initConfig.group.mapcontrols.geocoding || {}; | ||
const provider = document.currentScript.src.split('/').reverse()[0].replace('.js', '') || 'google'; | ||
|
||
// skip when disabled | ||
if (!provider in geocoding.providers) { | ||
return; | ||
} | ||
|
||
let active = true; | ||
|
||
geocoding.providers[provider].fetch = async function(opts) { | ||
|
||
const { XHR } = g3wsdk.core.utils; | ||
const { vendorkeys } = g3wsdk.core.ApplicationState.keys; | ||
|
||
// fallback to generic google vendor key | ||
vendorkeys[provider] = vendorkeys[provider] || vendorkeys.google; | ||
|
||
const key = undefined !== vendorkeys[provider] ? vendorkeys[provider] : opts && (new URL(opts.url)).searchParams.get('key'); | ||
|
||
// whether can fetch data from Google Geocode API | ||
if (!opts || !active || !key) { | ||
return Promise.reject(); | ||
} | ||
|
||
const url = opts.url || 'https://maps.googleapis.com/maps/api/geocode/json'; | ||
const params = { | ||
address: opts.query, // textual search | ||
bounds: [opts.extent[1], opts.extent[0], opts.extent[3], opts.extent[2]].join(','), | ||
language: opts.lang, | ||
}; | ||
|
||
// get fallback key from url | ||
if (undefined === vendorkeys.bing) { | ||
params.key = key; | ||
} | ||
|
||
const response = await XHR.get({ url, params }); | ||
|
||
// disable google provider on invalid API key | ||
if (response.status === 'REQUEST_DENIED') { | ||
active = false; | ||
return Promise.reject(); | ||
} | ||
|
||
return { | ||
provider, | ||
label: 'Google', | ||
icon: undefined !== opts.icon ? opts.icon : 'poi', | ||
results: 'OK' === response.status | ||
? response.results | ||
.filter(({ geometry: { location } })=> ol.extent.containsXY(opts.extent, location.lng, location.lat)) | ||
.map(result => { | ||
let name, city, country; | ||
result.address_components.forEach(({ types, long_name }) => { | ||
if (types.find(t => 'route' === t)) name = long_name; | ||
else if (types.find( t => 'locality' === t)) city = long_name; | ||
else if (types.find( t => 'country' === t)) country = long_name | ||
}); | ||
return { | ||
lon : result.geometry.location.lng, | ||
lat : result.geometry.location.lat, | ||
address: { | ||
name, | ||
road: undefined, | ||
postcode: '', | ||
city, | ||
state: undefined, | ||
country, | ||
formatted: result.display_name, | ||
}, | ||
google: result, | ||
}; | ||
}) | ||
: [], | ||
}; | ||
|
||
}; | ||
|
||
})(); |
64 changes: 64 additions & 0 deletions
64
g3w-admin/client/static/client/geocoding-providers/nominatim.js
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,64 @@ | ||
/** | ||
* @file | ||
* @since 3.9.0 | ||
*/ | ||
|
||
(function() { | ||
|
||
const geocoding = initConfig.group.mapcontrols.geocoding || {}; | ||
const provider = document.currentScript.src.split('/').reverse()[0].replace('.js', '') || 'nominatim'; | ||
|
||
// skip when disabled | ||
if (!provider in geocoding.providers) { | ||
return; | ||
} | ||
|
||
geocoding.providers[provider].fetch = async function(opts) { | ||
|
||
const { XHR } = g3wsdk.core.utils; | ||
|
||
if (!opts) { | ||
return Promise.reject(); | ||
} | ||
|
||
return { | ||
provider, | ||
label: 'Nominatim (OSM)', | ||
icon: undefined !== opts.icon ? opts.icon : 'road', | ||
results: | ||
( | ||
await XHR.get({ | ||
url: opts.url || 'https://nominatim.openstreetmap.org/search', | ||
params: { | ||
q: opts.query, // textual search | ||
format: 'json', | ||
addressdetails: 1, | ||
limit: opts.limit || 10, | ||
viewbox: opts.extent.join(','), | ||
bounded: 1, | ||
} | ||
}) | ||
) | ||
.filter(place => ol.extent.containsXY(opts.extent, place.lon, place.lat)) | ||
.map(result => ({ | ||
name: result.name, | ||
lon: result.lon, | ||
lat: result.lat, | ||
type: result.type, | ||
address: { | ||
name: result.address.neighbourhood || '', | ||
road: result.address.road || '', | ||
city: result.address.city || result.address.town, | ||
postcode: result.address.postcode, | ||
state: result.address.state, | ||
country: result.address.country, | ||
formatted: result.display_name, | ||
}, | ||
nominatim: result, | ||
}) | ||
), | ||
}; | ||
|
||
}; | ||
|
||
})(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.