Skip to content

Commit c3439e2

Browse files
authored
Merge pull request #96 from gtt-project/fix/xyz-tile
Fixed XYZ tile issue
2 parents 5f40797 + 9cc7d18 commit c3439e2

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/components/gtt-client.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'ol-ext/filter/Base'
55
import { Geometry, Point } from 'ol/geom'
66
import { GeoJSON, WKT } from 'ol/format'
77
import { Layer, Tile, Vector as VectorLayer } from 'ol/layer'
8-
import { Tile as TileSource, OSM } from 'ol/source'
8+
import { OSM, XYZ } from 'ol/source'
99
import { Style, Fill, Stroke, Circle } from 'ol/style'
1010
import { OrderFunction } from 'ol/render'
1111
import {
@@ -139,22 +139,25 @@ export class GttClient {
139139
const layers = JSON.parse(this.contents.layers) as [LayerObject]
140140
layers.forEach((layer) => {
141141
const s = layer.type.split('.')
142-
const l = new Tile({
143-
visible: true,
144-
source: new (getTileSource(s[1], s[2]))(layer.options)
145-
})
146-
l.set('lid', layer.id)
147-
l.set('title', layer.name)
148-
l.set('baseLayer', true)
149-
l.on('change:visible', e => {
150-
const target = e.target as Tile
151-
if (target.getVisible()) {
152-
const lid = target.get('lid')
153-
document.cookie = `_redmine_gtt_basemap=${lid};path=/`
154-
}
155-
})
156-
this.layerArray.push(l)
157-
this.map.addLayer(l)
142+
const tileSource = getTileSource(s[1], s[2])
143+
if (tileSource) {
144+
const l = new Tile({
145+
visible: false,
146+
source: new (tileSource)(layer.options)
147+
})
148+
l.set('lid', layer.id)
149+
l.set('title', layer.name)
150+
l.set('baseLayer', true)
151+
l.on('change:visible', e => {
152+
const target = e.target as Tile
153+
if (target.getVisible()) {
154+
const lid = target.get('lid')
155+
document.cookie = `_redmine_gtt_basemap=${lid};path=/`
156+
}
157+
})
158+
this.layerArray.push(l)
159+
this.map.addLayer(l)
160+
}
158161
}, this)
159162
}
160163

@@ -1138,9 +1141,11 @@ const getTileSource = (source: string, class_name: string): any => {
11381141
if (source === 'source') {
11391142
if (class_name === 'OSM') {
11401143
return OSM
1144+
} else if (class_name === 'XYZ') {
1145+
return XYZ
11411146
}
11421147
}
1143-
return TileSource
1148+
return undefined
11441149
}
11451150

11461151
const getCookie = (cname:string):string => {

0 commit comments

Comments
 (0)