Skip to content

Commit

Permalink
Fixing geocode to MapBox also in mobile client
Browse files Browse the repository at this point in the history
  • Loading branch information
uprel committed Nov 18, 2018
1 parent 4f6111c commit 8d801e7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion client_mobile/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Config.map.initialGeolocationMaxScale = 2000;
// search configuration
var sCon = projectData.geoCode ? projectData.geoCode : null;
if (sCon != null) {
Config.search = new Geocode(sCon.key, sCon.layers, sCon.sources, sCon.countryString);
Config.search = new Geocode(sCon.layers, sCon.country, 10, sCon.provider, projectData.lang);
}
if (sCon == null && projectData.wsgi) {
Config.search = new WsgiSearch("/wsgi/search.wsgi", "/wsgi/getSearchGeom.wsgi", false, projectData.wsgi.searchtables);
Expand Down
37 changes: 22 additions & 15 deletions client_mobile/src/geocode.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

function Geocode(key, layers, sources, countryString) {
function Geocode(types, country, limit, provider, lang) {

this.key = key;
this.layers = layers;
this.sources = sources;
this.countryString = countryString;
this.types = types;
this.country = country;
this.limit = limit;
this.provider = provider;
this.language = lang;
}

// inherit from Search
Expand All @@ -15,7 +16,7 @@ Geocode.prototype = new Search();
*/
Geocode.prototype.submit = function(searchParams, callback) {
var request = $.ajax({
url: "https://search.mapzen.com/v1/search",
url: "admin/proxy.php",
data: this.parseSearchParams(searchParams),
//dataType: 'jsonp',
//jsonp: 'cb',
Expand All @@ -36,12 +37,16 @@ Geocode.prototype.submit = function(searchParams, callback) {
*/
Geocode.prototype.parseSearchParams = function(searchParams) {
var query = $.trim(searchParams);
var view = Map.map.getView();
var center = ol.proj.toLonLat(view.getCenter(), view.getProjection().getCode());
return {
"api_key": this.key,
"layers": this.layers,
"sources": this.sources,
"boundary.country": this.countryString,
"text": query
"limit": this.limit,
"types": this.types,
"country": this.country,
"language": this.lang,
"provider": this.provider,
"query": query,
"proximity": center[0]+','+center[1]
};
};

Expand All @@ -63,9 +68,10 @@ Geocode.prototype.parseSearchParams = function(searchParams) {
Geocode.prototype.parseResults = function(data, status, callback) {
var results = $.map(data.features, function(value, index) {

value.properties.locality = value.properties.locality==undefined ? '' : ' '+value.properties.locality;
//value.properties.locality = value.properties.locality==undefined ? '' : ' '+value.properties.locality;

var name = value.properties.street +' '+ value.properties.housenumber + '</br>' + value.properties.postalcode + value.properties.locality+', '+value.properties.region;
//var name = value.properties.street +' '+ value.properties.housenumber + '</br>' + value.properties.postalcode + value.properties.locality+', '+value.properties.region;
var name = value.place_name;
var loc = new ol.geom.Point([value.geometry.coordinates[0],value.geometry.coordinates[1]]);
loc.transform("EPSG:4326",Map.map.getView().getProjection());
var box = loc.getExtent();
Expand All @@ -78,7 +84,8 @@ Geocode.prototype.parseResults = function(data, status, callback) {
});

callback([{
category: null,
results: results
category: null,
results: results,
total: results.length
}]);
};
13 changes: 7 additions & 6 deletions client_mobile/src/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,13 @@ Gui.showSearchResults = function (results) {
$('#searchResults').show();

// automatically jump to single result
if (results.length === 1 && result.point != null) {
Gui.jumpToSearchResult(result.point);
if (results[0].highlight != undefined) {
Config.search.highlight(results[0].highlight, Map.setHighlightLayer);
}
}
//TODO FIX this need total results length
//if (results.length === 1 && result.point != null) {
// Gui.jumpToSearchResult(result.point);
// if (results[0].highlight != undefined) {
// Config.search.highlight(results[0].highlight, Map.setHighlightLayer);
// }
//}
};

// bbox as [<minx>, <miny>, <maxx>, <maxy>]
Expand Down

0 comments on commit 8d801e7

Please sign in to comment.