Skip to content

Commit

Permalink
map.json configurable FeatureClasses for Gazetteer process (#1185)
Browse files Browse the repository at this point in the history
* configurable geoname feature class

* fix featureclass value return, throw error if featureFilters not configured properly

* formatting
  • Loading branch information
alexgao1 authored Sep 11, 2023
1 parent d2c2f6c commit e980853
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
20 changes: 18 additions & 2 deletions nunaliit2-js/src/main/js/nunaliit2/n2.GeoNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var FeatureClass = {
,SPOT: 'S' // spot, building, farm
,MOUNTAINS: 'T' // mountain, hill, rock
,UNDERSEA: 'U' // undersea
,FOREST: 'V' // forest,heath,...
};

//===================================
Expand All @@ -61,12 +62,14 @@ var AutoComplete = $n2.Class({
service: null
,input: null
,autocomplete: null
,featureFilter: null
},opts_);

var _this = this;

this.service = opts.service;

this.featureFilter = opts.featureFilter

var $input = null;
if( typeof(opts.input) === 'string' ) {
$input = $('#'+opts.input);
Expand All @@ -90,6 +93,11 @@ var AutoComplete = $n2.Class({
if( 'service' === key ){
} else if( 'input' === key ){
} else if( 'autocomplete' === key ){
} else if( 'featureFilter' === key ){
this.options.featureClass = opts[key]
.filter(key => { return key in FeatureClass })
.map(fKey => { return FeatureClass[fKey] })
if (!this.options.featureClass.length) this.options.featureClass = FeatureClass.PLACES
} else {
this.options[key] = opts[key];
};
Expand All @@ -98,7 +106,8 @@ var AutoComplete = $n2.Class({
// Install autocomplete
var autocompleteOptions = $n2.extend(
{
minLength: 3
minLength: 3,
delay: 500
}
,opts.autocomplete
,{
Expand Down Expand Up @@ -301,6 +310,13 @@ var GeoNameService = $n2.Class({
if( opts.style ){
data.style = opts.style;
};

if (opts.featureFilter) {
data.featureClass = opts.featureFilter
.filter(key => { return key in FeatureClass })
.map(fKey => { return FeatureClass[fKey] })
if (!data.featureClass.length) data.featureClass = opts.featureClass
}
},

_getGeoNames: function(method, data, success, error) {
Expand Down
5 changes: 5 additions & 0 deletions nunaliit2-js/src/main/js/nunaliit2/n2.couchModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@ var ModuleDisplay = $n2.Class({
suppress: false
,initiallyOpened: false
}
,gazetteerFeatureFilter: ['PLACES']
};

// Layer selector
Expand Down Expand Up @@ -1301,6 +1302,10 @@ var ModuleDisplay = $n2.Class({
};
};

if (mapInfo && mapInfo.gazetteerFeatureFilter) {
mapOptions.gazetteerFeatureFilter = mapInfo.gazetteerFeatureFilter
}

if( mapInfo
&& mapInfo.coordinates
&& mapInfo.coordinates.autoInitialBounds ){
Expand Down
14 changes: 10 additions & 4 deletions nunaliit2-js/src/main/js/nunaliit2/n2.mapAndControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,15 @@ function HandleWidgetDisplayRequests(m){
var GazetteerProcess = $n2.Class({

geoNamesService: null,

featureFilter: null,
inputId: null,

initialize: function(geoNamesService_){
initialize: function(geoNamesService_, featureFilter){
this.geoNamesService = geoNamesService_;
this.featureFilter = featureFilter
if (!Array.isArray(this.featureFilter) || !this.featureFilter.every(v => typeof v === "string")) {
$n2.reportErrorForced("featureFilter must be an array of strings")
}
},

initiateCapture: function(mapControl){
Expand Down Expand Up @@ -381,7 +385,8 @@ var GazetteerProcess = $n2.Class({
var $input = $('#'+this.inputId);

this.geoNamesService.installAutoComplete({
input: $input
input: $input,
featureFilter: this.featureFilter
});

var request = {
Expand Down Expand Up @@ -434,6 +439,7 @@ var GazetteerProcess = $n2.Class({

this.geoNamesService.getName({
name: request.name
,featureFilter: this.featureFilter
,featureClass: $n2.GeoNames.FeatureClass.PLACES
,maxRows: 25
,countryBias: countryBias
Expand Down Expand Up @@ -1734,7 +1740,7 @@ var MapAndControls = $n2.Class('MapAndControls',{
&& this.options.directory
&& this.options.directory.geoNamesService ) {
var geoNamesService = this.options.directory.geoNamesService;
var gazetteerProcess = new GazetteerProcess(geoNamesService);
var gazetteerProcess = new GazetteerProcess(geoNamesService, this.options.gazetteerFeatureFilter);
var control = new OpenLayers.Control.NunaliitGazetteer({
activateListener: function(){
gazetteerProcess.initiateCapture(_this);
Expand Down

0 comments on commit e980853

Please sign in to comment.