Skip to content

Commit

Permalink
Merge d2da8da into 14f8532
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Jan 25, 2016
2 parents 14f8532 + d2da8da commit 3a4a3f0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
42 changes: 34 additions & 8 deletions contribs/gmf/src/directives/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ gmfModule.directive('gmfSearch', gmf.searchDirective);
* @constructor
* @param {angular.Scope} $scope The directive's scope.
* @param {angular.$compile} $compile Angular compile service.
* @param {angularGettext.Catalog} gettextCatalog Gettext catalog.
* @param {ngeo.CreateGeoJSONBloodhound} ngeoCreateGeoJSONBloodhound The ngeo
* create GeoJSON Bloodhound service.
* @param {ngeo.FeatureOverlayMgr} ngeoFeatureOverlayMgr The ngeo feature
Expand All @@ -100,7 +101,7 @@ gmfModule.directive('gmfSearch', gmf.searchDirective);
* @ngdoc controller
* @ngname GmfSearchController
*/
gmf.SearchController = function($scope, $compile,
gmf.SearchController = function($scope, $compile, gettextCatalog,
ngeoCreateGeoJSONBloodhound, ngeoFeatureOverlayMgr) {

/**
Expand All @@ -115,6 +116,12 @@ gmf.SearchController = function($scope, $compile,
*/
this.compile_ = $compile;

/**
* @type {angularGettext.Catalog}
* @private
*/
this.gettextCatalog_ = gettextCatalog;

/**
* @type {ngeo.CreateGeoJSONBloodhound}
* @private
Expand Down Expand Up @@ -297,20 +304,39 @@ gmf.SearchController.prototype.filterLayername_ = function(groupsKey,
gmf.SearchController.prototype.createAndInitBloodhound_ = function(config,
opt_filter) {
var mapProjectionCode = this.map_.getView().getProjection().getCode();
var queryOptions = {
param: 'query',
xhrFields: {
withCredentials: true
}
};
var remoteOptions = this.getBloodhoudRemoteOptions_();
var bloodhound = this.ngeoCreateGeoJSONBloodhound_(config.url, opt_filter,
ol.proj.get(mapProjectionCode), ol.proj.get(config.projection),
config.bloodhoundOptions, queryOptions);
config.bloodhoundOptions, remoteOptions);
bloodhound.initialize();
return bloodhound;
};


/**
* @return {BloodhoundRemoteOptions}
* @private
*/
gmf.SearchController.prototype.getBloodhoudRemoteOptions_ = function() {
var gettextCatalog = this.gettextCatalog_;
return {
prepare: function(query, settings) {
var url = settings.url;
var lang = gettextCatalog.currentLanguage;
var interfaceName = 'mobile'; // FIXME dynamic interface
url = goog.uri.utils.setParam(url, 'query', query);
url = goog.uri.utils.setParam(url, 'lang', lang);
url = goog.uri.utils.setParam(url, 'interface', interfaceName);
settings.xhrFields = {
withCredentials: true
};
settings.url = url;
return settings;
}
};
};


/**
* @private
*/
Expand Down
20 changes: 2 additions & 18 deletions externs/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var BloodhoundDatum;

/**
* @typedef {{
* url: string,
* url: (string|undefined),
* wildcard: (string|undefined),
* rateLimitBy: (string|undefined),
* rateLimitWait: (number|undefined),
Expand All @@ -25,7 +25,7 @@ var BloodhoundRemoteOptions;

/**
* @typedef {{
* url: string,
* url: (string|undefined),
* cache: (boolean|undefined),
* ttl: (number|undefined),
* cacheKey: (string|undefined),
Expand All @@ -34,22 +34,6 @@ var BloodhoundRemoteOptions;
*/
var BloodhoundPrefetchOptions;

/**
* @typedef {{
* withCredentials: (boolean|undefined)
* }}
*/
var BloodhoundQueryXhrfieldsOptions;

/**
* @typedef {{
* dataType: (string|undefined),
* param: (string|undefined),
* xhrFields: (BloodhoundQueryXhrfieldsOptions|undefined)
* }}
*/
var BloodhoundQueryOptions;

/**
* @typedef {{
* datumTokenizer: function(BloodhoundDatum):Array.<string>,
Expand Down
23 changes: 8 additions & 15 deletions src/services/creategeojsonbloodhound.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ goog.require('ol.format.GeoJSON');
*
* @typedef {function(string, (function(GeoJSONFeature): boolean)=,
* ol.proj.Projection=, ol.proj.Projection=, BloodhoundOptions=,
* BloodhoundQueryOptions=):Bloodhound}
* BloodhoundRemoteOptions=):Bloodhound}
* @ngdoc service
* @ngname ngeoCreateGeoJSONBloodhound
*/
Expand All @@ -53,29 +53,19 @@ ngeo.CreateGeoJSONBloodhound;
* @param {ol.proj.Projection=} opt_dataProjection Data projection.
* @param {BloodhoundOptions=} opt_options optional Bloodhound options. If
* undefined, the default Bloodhound config will be used.
* @param {BloodhoundQueryOptions=} opt_query optional Bloodhound query options.
* Effective only if `remote`is not defined in `opt_options`.
* @param {BloodhoundRemoteOptions=} opt_remoteOptions optional Bloodhound
* remote options. Effective only if `remote` is not defined in `opt_options`.
* @return {Bloodhound} The Bloodhound object.
*/
ngeo.createGeoJSONBloodhound = function(url, opt_filter, opt_featureProjection,
opt_dataProjection, opt_options, opt_query) {
opt_dataProjection, opt_options, opt_remoteOptions) {
var geojsonFormat = new ol.format.GeoJSON();
var bloodhoundOptions = /** @type {BloodhoundOptions} */ ({
remote: {
url: url,
rateLimitWait: 50,
prepare: function(query, settings) {
if (settings.url.indexOf('%QUERY') >= 0) {
settings.url = settings.url.replace('%QUERY', query);
}
else {
var lastChar = settings.url.slice(-1);
if (lastChar != '&' && lastChar != '?') {
settings.url += settings.url.indexOf('?') < 0 ? '?' : '&';
}
settings.url += opt_query.param + '=' + query;
}
goog.object.extend(settings, opt_query);
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
transform: function(parsedResponse) {
Expand Down Expand Up @@ -103,6 +93,9 @@ ngeo.createGeoJSONBloodhound = function(url, opt_filter, opt_featureProjection,
if (opt_options) {
goog.object.extend(bloodhoundOptions, opt_options);
}
if (opt_remoteOptions) {
goog.object.extend(bloodhoundOptions.remote, opt_remoteOptions);
}
return new Bloodhound(bloodhoundOptions);
};

Expand Down

0 comments on commit 3a4a3f0

Please sign in to comment.