Skip to content

Commit 5930aa2

Browse files
mbasasanak
authored andcommitted
added Overlay Layers
1 parent c034574 commit 5930aa2

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

src/components/gtt-client.ts

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Toggle from 'ol-ext/control/Toggle'
3232
import Button from 'ol-ext/control/Button'
3333
import TextButton from 'ol-ext/control/TextButton'
3434
import LayerPopup from 'ol-ext/control/LayerPopup'
35+
import LayerSwitcher from 'ol-ext/control/LayerSwitcher'
3536
import Popup from 'ol-ext/overlay/Popup'
3637
import { position } from 'ol-ext/control/control'
3738
import { ResizeObserver } from '@juggle/resize-observer'
@@ -46,6 +47,7 @@ interface LayerObject {
4647
type: string
4748
id: number
4849
name: string
50+
baselayer: boolean
4951
options: object
5052
}
5153

@@ -151,21 +153,45 @@ export class GttClient {
151153
const l = new Tile({
152154
visible: false,
153155
source: new (tileSource)(layer.options)
154-
})
156+
})
157+
155158
l.set('lid', layer.id)
156159
l.set('title', layer.name)
157-
l.set('baseLayer', true)
158-
l.on('change:visible', e => {
159-
const target = e.target as Tile<XYZ>
160-
if (target.getVisible()) {
161-
const lid = target.get('lid')
162-
document.cookie = `_redmine_gtt_basemap=${lid};path=/`
163-
}
164-
})
160+
l.set('baseLayer', layer.baselayer)
161+
if( layer.baselayer ) {
162+
l.on('change:visible', e => {
163+
const target = e.target as Tile<XYZ>
164+
if (target.getVisible()) {
165+
const lid = target.get('lid')
166+
document.cookie = `_redmine_gtt_basemap=${lid};path=/`
167+
}
168+
})
169+
}
165170
this.layerArray.push(l)
166-
this.map.addLayer(l)
171+
//this.map.addLayer(l)
167172
}
168173
}, this)
174+
175+
/**
176+
* Ordering the Layers for the LayerSwitcher Control.
177+
* BaseLayers are added first.
178+
*/
179+
this.layerArray.forEach( (l:Layer) => {
180+
if( l.get("baseLayer") ) {
181+
this.map.addLayer(l)
182+
}
183+
}
184+
)
185+
186+
var containsOverlay = false;
187+
188+
this.layerArray.forEach( (l:Layer) => {
189+
if( !l.get("baseLayer") ) {
190+
this.map.addLayer(l)
191+
containsOverlay = true
192+
}
193+
}
194+
)
169195
}
170196

171197
this.setBasemap()
@@ -331,7 +357,13 @@ export class GttClient {
331357
})
332358

333359
// Add LayerSwitcher Image Toolbar
334-
this.map.addControl(new LayerPopup())
360+
if( containsOverlay) {
361+
this.map.addControl(new LayerSwitcher())
362+
}
363+
else {
364+
this.map.addControl(new LayerPopup())
365+
}
366+
335367

336368
// Because Redmine filter functions are applied later, the Window onload
337369
// event provides a workaround to have filters loaded before executing

0 commit comments

Comments
 (0)