-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrastertilelayer.ts
124 lines (112 loc) · 3.69 KB
/
rastertilelayer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { DOMWidgetModel, ISerializers } from '@jupyter-widgets/base';
import WebGLTileLayer from 'ol/layer/WebGLTile.js';
import XYZ from 'ol/source/XYZ.js';
import { MODULE_NAME, MODULE_VERSION } from './version';
import { MapView } from './widget';
import { LayerModel, LayerView } from './layer';
/*
type WebGLEvent = {
context: WebGLRenderingContext;
};
*/
export class RasterTileLayerModel extends LayerModel {
defaults() {
return {
...super.defaults(),
_model_name: RasterTileLayerModel.model_name,
_model_module: RasterTileLayerModel.model_module,
_model_module_version: RasterTileLayerModel.model_module_version,
_view_name: RasterTileLayerModel.view_name,
_view_module: RasterTileLayerModel.view_module,
_view_module_version: RasterTileLayerModel.view_module_version,
layers: [],
url: '',
attributions: [],
tileSize: 256,
max_zoom: 19,
min_zoom: 0,
};
}
static serializers: ISerializers = {
...DOMWidgetModel.serializers,
// Add any extra serializers ici
};
static model_name = 'RasterTileLayerModel';
static model_module = MODULE_NAME;
static model_module_version = MODULE_VERSION;
static view_name = 'RasterTileLayerView';
static view_module = MODULE_NAME;
static view_module_version = MODULE_VERSION;
}
export class RasterTileLayerView extends LayerView {
map_view: MapView;
tileLayer: WebGLTileLayer;
/*
private prerenderListener: (event: WebGLEvent) => void;
private postrenderListener: (event: WebGLEvent) => void;
private previousSwipePosition: number | undefined;
constructor(options: any) {
super(options);
this.map_view = options.options.map_view;
this.prerenderListener = this.map_view.handlePrerender.bind(this.map_view);
this.postrenderListener = this.map_view.handlePostrender.bind(
this.map_view,
);
this.previousSwipePosition = undefined;
}*/
render() {
super.render();
this.urlChanged();
this.model.on('change:url', this.urlChanged, this);
/*this.model.on(
'change:swipe_position',
this.handleSwipePositionChanged,
this,
);*/
//this.updateEventListeners();
}
create_obj() {
this.obj = this.tileLayer = new WebGLTileLayer({
source: new XYZ({
url: this.model.get('url'),
attributions: this.model.get('attributions'),
tileSize: this.model.get('tileSize'),
maxZoom: this.model.get('max_zoom'),
minZoom: this.model.get('min_zoom'),
}),
});
}
urlChanged() {
const newUrl = this.model.get('url');
if (newUrl) {
const newSource = new XYZ({
url: newUrl,
attributions: this.model.get('attributions'),
tileSize: this.model.get('tileSize'),
maxZoom: this.model.get('max_zoom'),
minZoom: this.model.get('min_zoom'),
});
this.tileLayer.setSource(newSource);
}
}
/*handleSwipePositionChanged() {
const swipePosition = this.model.get('swipe_position');
console.log('Swipe Position Changed:', swipePosition);
if (this.previousSwipePosition !== swipePosition) {
this.previousSwipePosition = swipePosition;
this.updateEventListeners();
this.map_view.map.render();
}
}
updateEventListeners() {
console.log('Updating event listeners');
const swipePosition = this.model.get('swipe_position');
(this.tileLayer as any).un('precompose', this.prerenderListener);
(this.tileLayer as any).un('postcompose', this.postrenderListener);
if (swipePosition >= 0) {
(this.tileLayer as any).on('precompose', this.prerenderListener);
(this.tileLayer as any).on('postcompose', this.postrenderListener);
}
console.log('Event listeners updated');
}*/
}