waibu-maps 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/bajo/intl/en-US.json +6 -0
  2. package/bajo/intl/id.json +14 -8
  3. package/package.json +1 -2
  4. package/waibuBootstrap/theme/component/factory/control-attribution.js +1 -1
  5. package/waibuBootstrap/theme/component/factory/control-buttons.js +1 -1
  6. package/waibuBootstrap/theme/component/factory/control-fullscreen.js +1 -1
  7. package/waibuBootstrap/theme/component/factory/control-geolocate.js +1 -1
  8. package/waibuBootstrap/theme/component/factory/control-globe.js +1 -1
  9. package/waibuBootstrap/theme/component/factory/control-group.js +3 -3
  10. package/waibuBootstrap/theme/component/factory/control-image.js +2 -2
  11. package/waibuBootstrap/theme/component/factory/control-logo.js +2 -2
  12. package/waibuBootstrap/theme/component/factory/control-mouse-pos.js +5 -5
  13. package/waibuBootstrap/theme/component/factory/control-navigation.js +1 -1
  14. package/waibuBootstrap/theme/component/factory/control-ruler.js +1 -1
  15. package/waibuBootstrap/theme/component/factory/control-scale.js +1 -1
  16. package/waibuBootstrap/theme/component/factory/control-search.js +12 -12
  17. package/waibuBootstrap/theme/component/factory/control-zbp.js +4 -4
  18. package/waibuBootstrap/theme/component/factory/control.js +1 -1
  19. package/waibuBootstrap/theme/component/factory/layer-geojson.js +1 -1
  20. package/waibuBootstrap/theme/component/factory/layer-html-cluster.js +3 -3
  21. package/waibuBootstrap/theme/component/factory/map.js +80 -84
  22. package/waibuBootstrap/theme/component/factory/script.js +2 -2
  23. package/waibuBootstrap/theme/component/wmaps-base.js +0 -9
  24. package/waibuStatic/virtual.json +0 -3
  25. package/waibuBootstrap/theme/component/factory/control-draw.js +0 -44
@@ -4,6 +4,12 @@
4
4
  "dirN": "N",
5
5
  "dirS": "S",
6
6
  "maps": "Maps",
7
+ "latLng": "latitude/Longitude",
8
+ "gotoLatLng": "Goto latitude/longitude",
9
+ "goto": "Goto",
10
+ "searchIn": "Search in",
11
+ "clearHistory": "Clear History",
12
+ "enterPhrase": "You need to enter a search phrase first",
7
13
  "mapControl": {
8
14
  "csrc": "Search",
9
15
  "navigation-control": "Navigation",
package/bajo/intl/id.json CHANGED
@@ -6,16 +6,22 @@
6
6
  "dirN": "U",
7
7
  "dirS": "S",
8
8
  "maps": "Peta",
9
+ "latLng": "Lintang/Bujur",
10
+ "gotoLatLng": "Ke lintang/bujur",
11
+ "goto": "Pergi ke",
12
+ "searchIn": "Cari di",
13
+ "clearHistory": "Hapus Jejak",
14
+ "enterPhrase": "Anda harus memasukkan frase pencarian terlebih dahulu",
9
15
  "mapControl": {
10
- "csrc": "Search",
11
- "navigation-control": "Navigation",
12
- "crlr": "Measurement",
13
- "scale-control": "Map Scale",
14
- "attribution-control": "Attribution",
15
- "fullscreen-control": "Fullscreen",
16
- "geolocate-control": "Geolocate",
16
+ "csrc": "Cari",
17
+ "navigation-control": "Navigasi",
18
+ "crlr": "Pengukuran",
19
+ "scale-control": "Skala Peta",
20
+ "attribution-control": "Atribusi",
21
+ "fullscreen-control": "Layar Penuh",
22
+ "geolocate-control": "Geolokasi",
17
23
  "globe-control": "Bola Dunia",
18
24
  "czbp": "Zoom/Bearing/Pitch",
19
- "cmp": "Mouse Position"
25
+ "cmp": "Posisi Tetikus"
20
26
  }
21
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-maps",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Maps for Waibu MPA",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,7 +28,6 @@
28
28
  },
29
29
  "homepage": "https://github.com/ardhi/waibu-maps#readme",
30
30
  "dependencies": {
31
- "@watergis/maplibre-gl-terradraw": "^1.3.8",
32
31
  "maplibre-gl": "^5.3.1"
33
32
  }
34
33
  }
@@ -18,7 +18,7 @@ async function controlAttribution () {
18
18
  if (isString(this.params.attr.text)) opts.customAttribution = this.params.attr.text
19
19
  opts.position = this.ctrlPos.includes(this.params.attr.position) ? this.params.attr.position : 'bottom-right'
20
20
  opts.classSelector = 'maplibregl-ctrl-attrib'
21
- this.block.control.push(`
21
+ this.addBlock('control', `
22
22
  await wmaps.createControlNative('AttributionControl', ${jsonStringify(opts, true)})
23
23
  `)
24
24
  this.params.html = this.writeBlock()
@@ -55,7 +55,7 @@ async function controlButtons () {
55
55
  })
56
56
  this.params.html = ''
57
57
  if (!isEmpty(items)) {
58
- this.block.control.push(`
58
+ this.addBlock('control', `
59
59
  map.addControl(new ControlButtons(_.merge(${jsonStringify({ items, position: pos }, true)}, { scopeId: this.$store.map.id }))${pos ? `, '${pos}'` : ''})
60
60
  `)
61
61
  this.params.html = this.writeBlock()
@@ -15,7 +15,7 @@ async function controlFullscreen () {
15
15
  const opts = {}
16
16
  if (isString(this.params.attr.container)) opts.container = this.params.attr.container
17
17
  opts.position = this.ctrlPos.includes(this.params.attr.position) ? this.params.attr.position : 'bottom-right'
18
- this.block.control.push(`
18
+ this.addBlock('control', `
19
19
  await wmaps.createControlNative('FullscreenControl', ${jsonStringify(opts, true)})
20
20
  `)
21
21
  this.params.html = this.writeBlock()
@@ -16,7 +16,7 @@ async function controlGeolocate () {
16
16
  if (this.params.attr.highAccuracy) set(opts, 'positionOptions.enableHighAccuracy', true)
17
17
  if (this.params.attr.trackUserLocation) opts.trackUserLocation = true
18
18
  opts.position = this.ctrlPos.includes(this.params.attr.position) ? this.params.attr.position : 'bottom-right'
19
- this.block.control.push(`
19
+ this.addBlock('control', `
20
20
  await wmaps.createControlNative('GeolocateControl', ${jsonStringify(opts, true)})
21
21
  `)
22
22
  this.params.html = this.writeBlock()
@@ -15,7 +15,7 @@ async function controlGlobe () {
15
15
  const opts = {}
16
16
  if (isString(this.params.attr.container)) opts.container = this.params.attr.container
17
17
  opts.position = this.ctrlPos.includes(this.params.attr.position) ? this.params.attr.position : 'bottom-right'
18
- this.block.mapStyle.push(`
18
+ this.addBlock('mapStyle', `
19
19
  await wmaps.createControlNative('GlobeControl', ${jsonStringify(opts, true)})
20
20
  `)
21
21
  this.params.html = this.writeBlock()
@@ -45,7 +45,7 @@ async function controlGroup () {
45
45
  items[idx] = await minify(items[idx])
46
46
  }
47
47
  this.readBlock()
48
- this.block.reactive.push(`
48
+ this.addBlock('reactive', [`
49
49
  ${prefix}MenuTpl: _.template('${tpl}')
50
50
  `, `
51
51
  async ${prefix}Trigger (evt) {
@@ -77,8 +77,8 @@ async function controlGroup () {
77
77
  }
78
78
  return items
79
79
  }
80
- `)
81
- this.block.control.push({
80
+ `])
81
+ this.addBlock('control', {
82
82
  id,
83
83
  group: true,
84
84
  content: `
@@ -22,7 +22,7 @@ async function controlImage () {
22
22
  const url = isString(this.params.attr.url) ? routePath(this.params.attr.url) : null
23
23
  let animate = '@mouseenter="$el.style.opacity = 1" @mouseleave="$el.style.opacity = 0.3" '
24
24
  if (this.params.attr.noAnimate) animate = ''
25
- this.block.reactive.push(`
25
+ this.addBlock('reactive', `
26
26
  async ${prefix}Builder () {
27
27
  const body = ['<c:${url ? `a url="${url}"` : 'div'}><c:img ${attribsStringify(img)} ']
28
28
  body.push('${animate}')
@@ -31,7 +31,7 @@ async function controlImage () {
31
31
  }
32
32
  `)
33
33
 
34
- this.block.control.push(`
34
+ this.addBlock('control', `
35
35
  await wmaps.createControl(_.merge(${jsonStringify(opts, true)}, { builder: this.${prefix}Builder }))
36
36
  `)
37
37
 
@@ -39,7 +39,7 @@ async function controlLogo () {
39
39
  img.style = img.style ?? {}
40
40
  img.style.opacity = img.opacity
41
41
  }
42
- this.block.reactive.push(`
42
+ this.addBlock('reactive', `
43
43
  async ${prefix}Builder () {
44
44
  const body = ['<c:a href="#" @click="wbs.appLauncher(\\'fullscreen darkmode language\\', \\'${this.params.attr.menu}\\')">']
45
45
  body.push('<c:img ${attribsStringify(img)} ${animate} />')
@@ -48,7 +48,7 @@ async function controlLogo () {
48
48
  }
49
49
  `)
50
50
 
51
- this.block.control.push(`
51
+ this.addBlock('control', `
52
52
  await wmaps.createControl(_.merge(${jsonStringify(opts, true)}, { builder: this.${prefix}Builder }))
53
53
  `)
54
54
 
@@ -28,14 +28,14 @@ async function controlMousePos () {
28
28
  <c:grid-col col="6" t:content="Latitude" />
29
29
  </c:grid-row>
30
30
  `))
31
- this.block.dataInit.push(`
31
+ this.addBlock('dataInit', `
32
32
  this.$watch('$store.map.center', val => {
33
33
  if (!this.${prefix}TrackCenter) return
34
34
  this.${prefix}Pos = [...val]
35
35
  })
36
36
  this.$watch('${prefix}Pos', this.${prefix}Update.bind(this))
37
37
  `)
38
- this.block.reactive.push(`
38
+ this.addBlock('reactive', [`
39
39
  ${prefix}Tpl: _.template('${tpl}')
40
40
  `, `
41
41
  ${prefix}Pos: [0, 0]
@@ -58,8 +58,8 @@ async function controlMousePos () {
58
58
  const body = '<c:div id="${id}" margin="x-2 top-1" text="align:center nowrap"/>'
59
59
  return await wmpa.createComponent(body)
60
60
  }
61
- `)
62
- this.block.run.push(`
61
+ `])
62
+ this.addBlock('run', `
63
63
  map.on('mousemove', evt => {
64
64
  if (this.${prefix}TrackCenter) return
65
65
  const coord = evt.lngLat.wrap()
@@ -68,7 +68,7 @@ async function controlMousePos () {
68
68
  if (this.${prefix}TrackCenter && this.$store.map.center) this.${prefix}Pos = [...this.$store.map.center]
69
69
  `)
70
70
 
71
- this.block.control.push(`
71
+ this.addBlock('control', `
72
72
  await wmaps.createControl(_.merge(${jsonStringify(options, true)}, { builder: this.${prefix}Builder, firstCall: this.${prefix}Update }))
73
73
  `)
74
74
 
@@ -18,7 +18,7 @@ async function controlNavigation () {
18
18
  opts.classSelector = 'maplibregl-ctrl-zoom-in'
19
19
  opts.classGroup = true
20
20
  opts.position = this.ctrlPos.includes(this.params.attr.position) ? this.params.attr.position : 'bottom-right'
21
- this.block.control.push(`
21
+ this.addBlock('control', `
22
22
  await wmaps.createControlNative('NavigationControl', ${jsonStringify(opts, true)})
23
23
  `)
24
24
  this.params.html = this.writeBlock()
@@ -27,7 +27,7 @@ async function controlRuler () {
27
27
  const opts = {
28
28
  imageUrl: routePath('waibuMaps.asset:/image/ruler.svg')
29
29
  }
30
- this.block.control.push(`
30
+ this.addBlock('control', `
31
31
  const rulerCtrl = new ControlRuler(${jsonStringify(opts, true)})
32
32
  map.addControl(rulerCtrl${pos ? `, '${pos}'` : ''})
33
33
  if (this.$store.mapControl) {
@@ -16,7 +16,7 @@ async function controlScale () {
16
16
  if (['imperial', 'metric', 'nautical'].includes(this.params.attr.unit)) opts.unit = this.params.attr.unit
17
17
  if (isString(this.params.attr.maxWidth) && Number(this.params.attr.maxWidth)) opts.maxWidth = Number(this.params.attr.maxWidth)
18
18
  opts.position = this.ctrlPos.includes(this.params.attr.position) ? this.params.attr.position : 'bottom-left'
19
- this.block.control.push(`
19
+ this.addBlock('control', `
20
20
  await wmaps.createControlNative('ScaleControl', ${jsonStringify(opts, true)})
21
21
  `)
22
22
  this.params.html = this.writeBlock()
@@ -18,12 +18,12 @@ async function controlSearch () {
18
18
  const opts = {}
19
19
  opts.position = this.ctrlPos.includes(this.params.attr.position) ? this.params.attr.position : 'top-left'
20
20
  opts.class = prefix + ' maplibregl-ctrl-group'
21
- this.block.control.push(`
21
+ this.addBlock('control', `
22
22
  await wmaps.createControl(_.merge(${jsonStringify(opts, true)}, { builder: this.${prefix}Builder }))
23
23
  `)
24
- this.block.dataInit.push(`
24
+ this.addBlock('dataInit', `
25
25
  this.$watch('$store.mapSearch.value', async val => {
26
- if (_.isEmpty(val)) return wbs.notify('You need to enter a search phrase first', { type: 'danger' })
26
+ if (_.isEmpty(val)) return wbs.notify('enterPhrase', { type: 'danger' })
27
27
  const html = await ${this.params.attr.method}(val, this.$store.mapSearch.feed)
28
28
  this.$store.mapSearch.recent = html ?? ''
29
29
  this.$store.mapSearch.busy = false
@@ -44,10 +44,10 @@ async function controlSearch () {
44
44
  el.disabled = !!val
45
45
  })
46
46
  `)
47
- this.block.mapLoad.push(`
47
+ this.addBlock('mapLoad', `
48
48
  await this.${prefix}Populate()
49
49
  `)
50
- this.block.reactive.push(`
50
+ this.addBlock('reactive', `
51
51
  async ${prefix}Builder (params) {
52
52
  const body = [
53
53
  '<c:button dim="height:100" flex="align-items:center justify-content:center" open="${id}">',
@@ -58,9 +58,9 @@ async function controlSearch () {
58
58
  },
59
59
  async ${prefix}Populate () {
60
60
  const feeds = await ${this.params.attr.feed}() ?? []
61
- feeds.unshift({ code: 'latLng', name: 'Goto Latitude/Longitude', feed: { id: 'latLng', label: 'Latitude/Longitude' } })
61
+ feeds.unshift({ code: 'latLng', name: 'gotoLatLng', feed: { id: 'latLng', label: 'latLng' } })
62
62
  this.$store.mapSearch.feeds = feeds
63
- const body = feeds.map(feed => '<c:dropdown-item :class="$store.mapSearch.feed === $el.getAttribute(\\'data-code-feedid\\') ? \\'active\\' : \\'\\'" data-code-feedid="' + feed.code + ':' + feed.feed.id + '" content="' + feed.feed.label + '" @click="$store.mapSearch.feed = \\'' + feed.code + ':' + feed.feed.id + '\\'"/>')
63
+ const body = feeds.map(feed => '<c:dropdown-item :class="$store.mapSearch.feed === $el.getAttribute(\\'data-code-feedid\\') ? \\'active\\' : \\'\\'" data-code-feedid="' + feed.code + ':' + feed.feed.id + '" t:content="' + feed.feed.label + '" @click="$store.mapSearch.feed = \\'' + feed.code + ':' + feed.feed.id + '\\'"/>')
64
64
  await wmpa.addComponent(body, '#${id} .input-group .dropdown-menu', 'div')
65
65
  if (!this.$store.mapSearch.feed) this.$store.mapSearch.feed = feeds[0].code + ':' + feeds[0].feed.id
66
66
  const html = this.$store.mapSearch.recent ?? ''
@@ -118,16 +118,16 @@ async function controlSearch () {
118
118
  </c:form-input>
119
119
  <c:div margin="top-2" flex="justify-content:between">
120
120
  <div>
121
- <template x-if="feedCode !== 'latLng'"><span><c:t>Search in:</c:t> <strong><span x-html="feedName" /></strong></span></template>
122
- <template x-if="feedCode === 'latLng'"><span><c:t>Goto:</c:t> <strong><span><c:t>Latitude/Longitude</c:t></span></strong></span></template>
121
+ <template x-if="feedCode !== 'latLng'"><span><c:t>searchIn</c:t>: <strong><span x-html="feedName" /></strong></span></template>
122
+ <template x-if="feedCode === 'latLng'"><span><c:t>goto</c:t>: <strong><span><c:t>latLng</c:t></span></strong></span></template>
123
123
  </div>
124
- <c:btn x-show="feedCode !== 'latLng'" size="sm" color="link" t:content="Clear History" @click="clearHistory()" />
124
+ <c:btn x-show="feedCode !== 'latLng'" size="sm" color="link" t:content="clearHistory" @click="clearHistory()" />
125
125
  </c:div>
126
126
  <c:div margin="top-3" class="result"><div></div></c:div>
127
127
  </c:modal>
128
128
  </div>
129
129
  `)
130
- this.block.dataInit.push(`
130
+ this.addBlock('dataInit', `
131
131
  this.$watch('$store.mapSearch.select', async val => {
132
132
  if (_.isEmpty(val)) return
133
133
  const [source, feedId] = (this.$store.mapSearch.feed ?? '').split(':')
@@ -140,7 +140,7 @@ async function controlSearch () {
140
140
  if (fn) await fn.call(scope, val, feedId)
141
141
  })
142
142
  `)
143
- this.block.initializing.push(`
143
+ this.component.addScriptBlock('alpineInitializing', `
144
144
  Alpine.store('mapSearch', {
145
145
  feed: Alpine.$persist('latLng:latLng').as('mapSearchFeed'),
146
146
  recent: Alpine.$persist('').as('mapSearchRecent'),
@@ -30,10 +30,10 @@ async function controlZbp () {
30
30
  <c:grid-col style="cursor:pointer" @click="reset" col="4" t:content="Pitch" />
31
31
  </c:grid-row>
32
32
  `))
33
- this.block.dataInit.push(`
33
+ this.addBlock('dataInit', `
34
34
  this.$watch('$store.map.zoom, $store.map.bearing, $store.map.pitch', this.${prefix}Update.bind(this))
35
35
  `)
36
- this.block.reactive.push(`
36
+ this.addBlock('reactive', [`
37
37
  ${prefix}Tpl: _.template('${tpl}')
38
38
  `, `
39
39
  ${prefix}Update () {
@@ -56,9 +56,9 @@ async function controlZbp () {
56
56
  ]
57
57
  return await wmpa.createComponent(body)
58
58
  }
59
- `)
59
+ `])
60
60
 
61
- this.block.control.push(`
61
+ this.addBlock('control', `
62
62
  await wmaps.createControl(_.merge(${jsonStringify(options, true)}, { builder: this.${prefix}Builder, firstCall: this.${prefix}Update }))
63
63
  `)
64
64
 
@@ -19,7 +19,7 @@ async function control () {
19
19
  this.readBlock()
20
20
  // persisting
21
21
  if (this.params.attr.persist) {
22
- this.block.initializing.push(`
22
+ this.component.addScriptBlock('alpineInitializing', `
23
23
  Alpine.store('mapControl', {
24
24
  attrib: Alpine.$persist(true).as('mapControlAttrib'),
25
25
  centerPos: Alpine.$persist(true).as('mapControlCenterPos'),
@@ -90,7 +90,7 @@ async function layerGeojson () {
90
90
  if (isString(group.cluster.maxZoom)) cluster.push('data.clusterMaxZoom = ' + Number(group.cluster.maxZoom))
91
91
  }
92
92
 
93
- this.block.mapLoad.push(`
93
+ this.addBlock('mapLoad', `
94
94
  ${this.params.attr.srcImages ? (await buildSrcImages.call(this, this.params)) : buildImage.call(this, this.params)}
95
95
  ${buildSource.call(this, this.params, cluster)}
96
96
  ${buildLayers.call(this, this.params)}
@@ -85,7 +85,7 @@ async function layerHtmlCluster () {
85
85
  extra.push(`${key}: ['+', ['case', this.filter.${key}, 1, 0]],`)
86
86
  }
87
87
  extra.push('}')
88
- this.block.mapLoad.push(`
88
+ this.addBlock('mapLoad', `
89
89
  ${buildSource.call(this, this.params, extra)}
90
90
  map.addLayer(
91
91
  ${createLayerCircle.call(this, this.params, filters)}
@@ -100,7 +100,7 @@ async function layerHtmlCluster () {
100
100
  updateMarkers()
101
101
  })
102
102
  `)
103
- this.block.reactive.push(
103
+ this.addBlock('reactive', [
104
104
  `colors: ${jsonStringify(colors, true)}`,
105
105
  `filter: ${jsonStringify(filters, true)}`,
106
106
  `updateMarkers () {
@@ -115,7 +115,7 @@ async function layerHtmlCluster () {
115
115
  }
116
116
  })
117
117
  }`
118
- )
118
+ ])
119
119
  this.params.html = this.writeBlock()
120
120
  }
121
121
  }
@@ -32,7 +32,7 @@ async function map () {
32
32
  this.params.attr['@keyup'] = 'onKeyup'
33
33
  const mapOptions = await options.call(this, this.params)
34
34
  const projection = this.params.attr.projection ?? 'mercator'
35
- this.block.reactive.push(`
35
+ this.addBlock('reactive', `
36
36
  async windowLoad () {
37
37
  const mapOpts = ${jsonStringify(mapOptions, true)}
38
38
  ${this.block.mapOptions.join('\n')}
@@ -40,95 +40,91 @@ async function map () {
40
40
  }
41
41
  `)
42
42
  this.params.attr['@load.window'] = 'await windowLoad()'
43
- this.params.append = `<script>
44
- document.addEventListener('alpine:init', () => {
45
- Alpine.data('${this.params.attr.id}', () => {
46
- let map
47
- let wmaps
48
- let projection = { type: '${projection}' }
49
- ${this.block.nonReactive.join('\n')}
50
- return {
51
- init () {
52
- ${this.block.dataInit.join('\n')}
53
- this.$watch('$store.wmpa.reqAborted', val => {
54
- if (!val) return
55
- const text = _.get(wmpa, 'fetchingApi.' + val + '.status')
56
- if (text.startsWith('abort:')) {
57
- const [, msg] = text.split(':')
58
- wbs.notify(msg, { type: 'warning' }).then()
59
- }
60
- })
61
- },
62
- ${this.block.reactive.join(',\n')},
63
- async onMapLoad (evt) {
64
- ${this.block.mapLoad.join('\n')}
65
- this.onMapStyle()
66
- },
67
- async onMapStyle () {
68
- map.setProjection(projection)
69
- ${this.block.mapStyle.join('\n')}
70
- },
71
- async onMissingImage (evt) {
72
- ${this.block.missingImage.join('\n')}
73
- },
74
- onLayerVisibility (layerId, shown) {
75
- if (!shown) {
76
- if (wmaps.popup) {
77
- const el = wmaps.popup.getElement()
78
- if (el && el.classList.contains('popup-layer-' + layerId)) wmaps.popup.remove()
79
- }
43
+ this.component.addScriptBlock('alpineInit', `
44
+ Alpine.data('${this.params.attr.id}', () => {
45
+ let map
46
+ let wmaps
47
+ let projection = { type: '${projection}' }
48
+ ${(this.block.nonReactive ?? []).join('\n')}
49
+ return {
50
+ init () {
51
+ ${(this.block.dataInit ?? []).join('\n')}
52
+ this.$watch('$store.wmpa.reqAborted', val => {
53
+ if (!val) return
54
+ const text = _.get(wmpa, 'fetchingApi.' + val + '.status')
55
+ if (text.startsWith('abort:')) {
56
+ const [, msg] = text.split(':')
57
+ wbs.notify(msg, { type: 'warning' }).then()
80
58
  }
81
- ${this.block.layerVisibility.join('\n')}
82
- },
83
- async onKeyup (evt) {
84
- if (evt.key === 'Escape') {
85
- if (wmaps.popup) wmaps.popup.remove()
59
+ })
60
+ },
61
+ ${(this.block.reactive ?? []).join(',\n')},
62
+ async onMapLoad (evt) {
63
+ ${(this.block.mapLoad ?? []).join('\n')}
64
+ this.onMapStyle()
65
+ },
66
+ async onMapStyle () {
67
+ map.setProjection(projection)
68
+ ${(this.block.mapStyle ?? []).join('\n')}
69
+ },
70
+ async onMissingImage (evt) {
71
+ ${(this.block.missingImage ?? []).join('\n')}
72
+ },
73
+ onLayerVisibility (layerId, shown) {
74
+ if (!shown) {
75
+ if (wmaps.popup) {
76
+ const el = wmaps.popup.getElement()
77
+ if (el && el.classList.contains('popup-layer-' + layerId)) wmaps.popup.remove()
86
78
  }
87
- ${this.block.keyup.join('\n')}
88
- },
89
- async run (instance) {
90
- map = instance
91
- wmapsUtil.setMap(map, projection)
92
- wmaps = new WaibuMaps(instance, this)
93
- map.on('moveend', evt => {
94
- Alpine.store('map').center = evt.target.getCenter().toArray()
95
- Alpine.store('map').zoom = evt.target.getZoom()
96
- Alpine.store('map').bearing = evt.target.getBearing()
97
- Alpine.store('map').pitch = evt.target.getPitch()
98
- })
99
- ${this.block.mapExtend.join('\n')}
100
- ${this.block.control.join('\n')}
101
- ${this.block.run.join('\n')}
102
- map.on('styledataloading', () => {
103
- map.once('styledata', this.onMapStyle.bind(this))
104
- })
105
- map.on('styleimagemissing', this.onMissingImage.bind(this))
106
- map.on('load', this.onMapLoad.bind(this))
107
79
  }
80
+ ${(this.block.layerVisibility ?? []).join('\n')}
81
+ },
82
+ async onKeyup (evt) {
83
+ if (evt.key === 'Escape') {
84
+ if (wmaps.popup) wmaps.popup.remove()
85
+ }
86
+ ${(this.block.keyup ?? []).join('\n')}
87
+ },
88
+ async run (instance) {
89
+ map = instance
90
+ wmapsUtil.setMap(map, projection)
91
+ wmaps = new WaibuMaps(instance, this)
92
+ map.on('moveend', evt => {
93
+ Alpine.store('map').center = evt.target.getCenter().toArray()
94
+ Alpine.store('map').zoom = evt.target.getZoom()
95
+ Alpine.store('map').bearing = evt.target.getBearing()
96
+ Alpine.store('map').pitch = evt.target.getPitch()
97
+ })
98
+ ${(this.block.mapExtend ?? []).join('\n')}
99
+ ${(this.block.control ?? []).join('\n')}
100
+ ${(this.block.run ?? []).join('\n')}
101
+ map.on('styledataloading', () => {
102
+ map.once('styledata', this.onMapStyle.bind(this))
103
+ })
104
+ map.on('styleimagemissing', this.onMissingImage.bind(this))
105
+ map.on('load', this.onMapLoad.bind(this))
108
106
  }
109
- })
110
- ${this.block.init.join('\n')}
111
- })
112
- document.addEventListener('alpine:initializing', () => {
113
- const props = {
114
- id: '${this.params.attr.id}',
115
- degree: Alpine.$persist('DMS').as('mapDegree'),
116
- measure: Alpine.$persist('nautical').as('mapMeasure'),
117
- zoomScrollCenter: Alpine.$persist(false).as('mapZoomScrollCenter'),
118
- noMapRotate: Alpine.$persist(false).as('mapNoMapRotate'),
119
- center: Alpine.$persist(null).as('mapCenter'),
120
- zoom: Alpine.$persist(null).as('mapZoom'),
121
- bearing: Alpine.$persist(null).as('mapBearing'),
122
- pitch: Alpine.$persist(null).as('mapPitch')
123
107
  }
124
- for (const ctrl of ${jsonStringify(WmapsBase.controls, true)}) {
125
- const name = 'ctrl' + wmpa.pascalCase(ctrl)
126
- props[name] = Alpine.$persist(true).as('map' + _.upperFirst(name))
127
- }
128
- Alpine.store('map', props)
129
- ${this.block.initializing.join('\n')}
130
108
  })
131
- </script>`
109
+ `)
110
+ this.component.addScriptBlock('alpineInitializing', `
111
+ const props = {
112
+ id: '${this.params.attr.id}',
113
+ degree: Alpine.$persist('DMS').as('mapDegree'),
114
+ measure: Alpine.$persist('nautical').as('mapMeasure'),
115
+ zoomScrollCenter: Alpine.$persist(false).as('mapZoomScrollCenter'),
116
+ noMapRotate: Alpine.$persist(false).as('mapNoMapRotate'),
117
+ center: Alpine.$persist(null).as('mapCenter'),
118
+ zoom: Alpine.$persist(null).as('mapZoom'),
119
+ bearing: Alpine.$persist(null).as('mapBearing'),
120
+ pitch: Alpine.$persist(null).as('mapPitch')
121
+ }
122
+ for (const ctrl of ${jsonStringify(WmapsBase.controls, true)}) {
123
+ const name = 'ctrl' + wmpa.pascalCase(ctrl)
124
+ props[name] = Alpine.$persist(true).as('map' + _.upperFirst(name))
125
+ }
126
+ Alpine.store('map', props)
127
+ `)
132
128
  const html = []
133
129
  $(`<div>${this.params.html}</div>`).find('.childmap').each(function () {
134
130
  html.push($(this).prop('outerHTML'))
@@ -10,8 +10,8 @@ async function script () {
10
10
  }
11
11
 
12
12
  build = async () => {
13
- const type = WmapsBase.blockTypes.includes(this.params.attr.type) ? this.params.attr.type : 'run'
14
- this.block[type].push(this.params.html)
13
+ const type = this.params.attr.type ?? 'run'
14
+ this.addBlock(type, this.params.html)
15
15
  this.params.html = this.writeBlock()
16
16
  }
17
17
  }
@@ -12,15 +12,6 @@ async function wmapsBase () {
12
12
  'waibuMaps.asset:/css/wmaps.css'
13
13
  ]
14
14
 
15
- constructor (options) {
16
- super(options)
17
- this.blockTypes = [...this.blockTypes,
18
- 'mapLoad', 'control', 'mapOptions', 'mapStyle', 'layerVisibility', 'missingImage',
19
- 'mapExtend'
20
- ]
21
- this.init()
22
- }
23
-
24
15
  static controls = ['csrc', 'navigation-control', 'crlr', 'scale-control', 'attribution-control',
25
16
  // 'fullscreen-control', 'geolocate-control', 'czbp', 'cmp', 'globe-control']
26
17
  'fullscreen-control', 'geolocate-control', 'czbp', 'cmp']
@@ -1,7 +1,4 @@
1
1
  [{
2
2
  "prefix": "maplibre",
3
3
  "root": "maplibre-gl:/dist"
4
- }, {
5
- "prefix": "draw-ctrl",
6
- "root": "@watergis/maplibre-gl-terradraw:/dist"
7
4
  }]
@@ -1,44 +0,0 @@
1
- import control from './control.js'
2
-
3
- async function controlDraw () {
4
- const WmapsControl = await control.call(this)
5
-
6
- return class WmapsControlDraw extends WmapsControl {
7
- static scripts = [
8
- ...super.scripts,
9
- 'waibuMaps.virtual:/draw-ctrl/maplibre-gl-terradraw.umd.js'
10
- ]
11
-
12
- static css = [
13
- ...super.css,
14
- 'waibuMaps.virtual:/draw-ctrl/maplibre-gl-terradraw.css'
15
- ]
16
-
17
- constructor (options) {
18
- super(options)
19
- this.params.noTag = true
20
- }
21
-
22
- build = async () => {
23
- const { jsonStringify, attrToArray } = this.plugin.app.waibuMpa
24
- const opts = {}
25
- if (['imperial', 'metric', 'nautical'].includes(this.params.attr.unit)) opts.unit = this.params.attr.unit
26
- const pos = this.ctrlPos.includes(this.params.attr.position) ? this.params.attr.position : 'top-left'
27
- let modes = ['point', 'linestring', 'polygon', 'rectangle', 'circle', 'freehand', 'angled-rectangle', 'sensor', 'sector', 'select', 'delete-selection', 'delete', 'render', 'download']
28
- if (this.params.attr.modes) modes = attrToArray(this.params.attr.modes)
29
- this.block.control.push(`
30
- draw = new MaplibreTerradrawControl.MaplibreTerradrawControl({
31
- modes: ${jsonStringify(modes, true)},
32
- open: true,
33
- })
34
- map.addControl(draw, '${pos}')
35
- `)
36
- this.block.nonReactive.push(`
37
- let draw
38
- `)
39
- this.params.html = this.writeBlock()
40
- }
41
- }
42
- }
43
-
44
- export default controlDraw