Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add src/components/MapControlGeocoding.js and src/components/MapControlNominatimResults.js #330

Merged
merged 14 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 14 additions & 83 deletions src/app/g3w-ol/controls/geocodingcontrol.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import ApplicationState from "store/application-state";
import ApplicationState from 'store/application-state';
import GUI from 'services/gui';

import MapControlGeocoding from 'components/MapControlGeocoding';
import MapControlNominatimResults from 'components/MapControlNominatimResults';

const Control = require('./control');
const { toRawType, XHR } = require('core/utils/utils');
const Projections = require('g3w-ol/projection/projections');
Expand Down Expand Up @@ -400,6 +404,7 @@ function GeocodingControl(options={}) {
debug: false,
viewbox: options.bbox,
bounded: 1,
classMobile: options.isMobile ? 'nominatim-mobile' : '',
volterra79 marked this conversation as resolved.
Show resolved Hide resolved
Raruto marked this conversation as resolved.
Show resolved Hide resolved
mapCrs: options.mapCrs,
fontIcon: GUI.getFontClass('search')
};
Expand Down Expand Up @@ -445,76 +450,13 @@ function GeocodingControl(options={}) {

this.projection;

const containerClass = `${cssClasses.namespace} ${cssClasses.inputText.container}`;
const self = this;

const GeocoderVueContainer = Vue.extend({
functional: true,
render(h){
return h('div', {class: {[containerClass]: true}}, [
h('div', {
class: {
[cssClasses.inputText.control]: true,
}
}, [
h('input', {
attrs: {
type: 'text',
id: cssClasses.inputQueryId,
autocomplete: 'off'
},
class:{
[cssClasses.inputText.input]: true
},
directives:[
{
name: 't-placeholder',
value: placeholder
}
]
}),
h('button', {
attrs: {
type: 'button',
id: 'search_nominatim'
},
class:{
btn: true
},
on: {
click() {
const value = $(`input.${cssClasses.inputText.input}`).val();
self.query(value);
}
}
}, [h('i', {
attrs: {
'aria-hidden': true
},
style: {
color:'#ffffff'
},
class: {
[fontIcon]: true
}
})]),
h('button', {
attrs: {
type: 'button',
id: cssClasses.inputResetId
},
class: {
[`${cssClasses.inputText.reset} ${cssClasses.hidden}`]: true
}
}),
]),
h('ul', {
class: {
[cssClasses.inputText.result]: true
}
})])
}
});
const GeocoderVueContainer = Vue.extend(MapControlGeocoding({
containerClass: `${cssClasses.namespace} ${cssClasses.inputText.container} ${this.options.classMobile}`,
Raruto marked this conversation as resolved.
Show resolved Hide resolved
cssClasses,
fontIcon,
placeholder,
ctx: this
}));
this.container = new GeocoderVueContainer().$mount().$el;
this.lastQuery = '';
this.registeredListeners = {
Expand Down Expand Up @@ -653,18 +595,7 @@ function GeocodingControl(options={}) {
ul.appendChild(li);
});
} else {
const {noresults} = this.options;
const elementVue = Vue.extend({
functional: true,
render(h){
return h('li', {
class: {
'nominatim-noresult': true
},
directives:[{name: 't', value: noresults}]
})
}
});
const elementVue = Vue.extend(MapControlNominatimResults({noresults: this.options.noresults}));
const li = new elementVue().$mount().$el;
ul.appendChild(li);
}
Expand Down
73 changes: 73 additions & 0 deletions src/components/MapControlGeocoding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @file
* @since v3.9
*/

export default function({containerClass, cssClasses, fontIcon, placeholder, ctx}) {
return {
functional: true,
render(h){
return h('div', {class: {[containerClass]: true}}, [
h('div', {
class: {
[cssClasses.inputText.control]: true,
}
}, [
h('input', {
attrs: {
type: 'text',
id: cssClasses.inputQueryId,
autocomplete: 'off'
},
class:{
[cssClasses.inputText.input]: true
},
directives:[
{
name: 't-placeholder',
value: placeholder
}
]
}),
h('button', {
attrs: {
type: 'button',
id: 'search_nominatim'
},
class:{
btn: true
},
on: {
click() {
ctx.query($(`input.${cssClasses.inputText.input}`).val());
}
}
}, [h('i', {
attrs: {
'aria-hidden': true
},
style: {
color:'#ffffff'
},
class: {
[fontIcon]: true
}
})]),
h('button', {
attrs: {
type: 'button',
id: cssClasses.inputResetId
},
class: {
[`${cssClasses.inputText.reset} ${cssClasses.hidden}`]: true
}
}),
]),
h('ul', {
class: {
[cssClasses.inputText.result]: true
}
})])
}
};
};
18 changes: 18 additions & 0 deletions src/components/MapControlNominatimResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @file
* @since 3.9
*/

export default function({ noresults }) {
return {
functional: true,
render(h){
return h('li', {
class: {
'nominatim-noresult': true
},
directives:[{name: 't', value: noresults}]
})
}
};
};
4 changes: 4 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import LayerOpacityPicker from './LayerOpacityPicker.vue';
import Map from './Map.vue';
import MapAddLayer from './MapAddLayer.vue';
import MapControlButton from './MapControlButton.js';
import MapControlGeocoding from './MapControlGeocoding.js';
import MapControlNominatimResults from './MapControlNominatimResults.js';
import MapControlZoomHistory from './MapControlZoomHistory.vue';
import MetadataLayer from './MetadataLayer.vue';
import MetadataProject from './MetadataProject.vue';
Expand Down Expand Up @@ -184,6 +186,8 @@ export {
Map,
MapAddLayer,
MapControlButton,
MapControlGeocoding,
MapControlNominatimResults,
MapControlZoomHistory,
MetadataLayer,
MetadataProject,
Expand Down