diff --git a/src/app/g3w-ol/controls/geocodingcontrol.js b/src/app/g3w-ol/controls/geocodingcontrol.js index 752923226..3864b3659 100644 --- a/src/app/g3w-ol/controls/geocodingcontrol.js +++ b/src/app/g3w-ol/controls/geocodingcontrol.js @@ -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'); @@ -445,76 +449,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}`, + cssClasses, + fontIcon, + placeholder, + ctx: this + })); this.container = new GeocoderVueContainer().$mount().$el; this.lastQuery = ''; this.registeredListeners = { @@ -653,18 +594,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); } diff --git a/src/components/MapControlGeocoding.js b/src/components/MapControlGeocoding.js new file mode 100644 index 000000000..001346612 --- /dev/null +++ b/src/components/MapControlGeocoding.js @@ -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 + } + })]) + } + }; +}; diff --git a/src/components/MapControlNominatimResults.js b/src/components/MapControlNominatimResults.js new file mode 100644 index 000000000..184c1211b --- /dev/null +++ b/src/components/MapControlNominatimResults.js @@ -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}] + }) + } + }; +}; diff --git a/src/components/index.js b/src/components/index.js index b74df9142..7f70398cb 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -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'; @@ -184,6 +186,8 @@ export { Map, MapAddLayer, MapControlButton, + MapControlGeocoding, + MapControlNominatimResults, MapControlZoomHistory, MetadataLayer, MetadataProject,