UNPKG

waibu-maps

Version:
68 lines (61 loc) 2.34 kB
import control from './control.js' async function controlButtons () { const WmapsControl = await control.call(this) return class WmapsControlButtons extends WmapsControl { static scripts = [ ...super.scripts, 'waibuMaps.asset:/js/control-buttons.js' ] static css = [ ...super.css, 'waibuMaps.asset:/css/control-buttons.css' ] constructor (options) { super(options) this.params.noTag = true } build = async () => { const { generateId } = this.app.lib.aneka const { routePath } = this.app.waibu const { jsonStringify } = this.app.waibuMpa const { isEmpty, isString, pick, camelCase } = this.app.lib._ const { $ } = this.component const pos = this.ctrlPos.includes(this.params.attr.position) ? this.params.attr.position : 'top-right' const items = [] $(`<div>${this.params.html}</div>`).find('div').each(function () { const attrs = {} for (const k in this.attribs) { attrs[camelCase(k)] = this.attribs[k] } const opts = { id: attrs.id ?? generateId('alpha') } if (attrs.minZoom) opts.minZoom = Number(attrs.minZoom) || 0 if (attrs.class) opts.class = attrs.class if (attrs.dropdown) { opts.fn = attrs.dropdown opts.fnParams = opts.id opts.dropdown = true } else if (attrs.openTab) { opts.url = attrs.openTab opts.tab = true } else if (attrs.openUrl) { opts.url = attrs.openTab } else if (isString(attrs.dataBsTarget)) { opts.attrib = pick(attrs, ['dataBsTarget', 'dataBsToggle', 'ariaControls']) } else if (attrs.fn) { opts.fn = attrs.fn } if (isString(attrs.imageUrl)) opts.imageUrl = routePath(attrs.imageUrl) opts.icon = $(this).find('i').prop('class') items.push(opts) }) this.params.html = '' if (!isEmpty(items)) { this.addBlock('control', ` map.addControl(new ControlButtons(_.merge(${jsonStringify({ items, position: pos }, true)}, { scopeId: this.$store.map.id }))${pos ? `, '${pos}'` : ''}) `) this.params.html = this.writeBlock() } } } } export default controlButtons