Skip to content

Commit 508837a

Browse files
committed
convert bounds and size to lists
start working on imageservicelayer function
1 parent 74e40a3 commit 508837a

File tree

5 files changed

+74
-17
lines changed

5 files changed

+74
-17
lines changed

ipyleaflet/leaflet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ class VideoOverlay(RasterLayer):
760760
attribution = Unicode().tag(sync=True, o=True)
761761

762762

763-
class ImageServiceLayer(ImageOverlay):
763+
class ImageServiceLayer(RasterLayer):
764764
"""ImageServiceLayer class
765765
766766
Image Service layer for raster data served through a web service

js/src/jupyter-leaflet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export * from './layers/TileLayer.js';
1212
export * from './layers/VectorTileLayer.js';
1313
export * from './layers/LocalTileLayer.js';
1414
export * from './layers/WMSLayer.js';
15-
export * from './layers/ImageServiceLayer.js';
1615
export * from './layers/MagnifyingGlass.js';
1716
export * from './layers/ImageOverlay.js';
1817
export * from './layers/VideoOverlay.js';
18+
export * from './layers/ImageServiceLayer.js';
1919
export * from './layers/Velocity.js';
2020
export * from './layers/Heatmap.js';
2121
export * from './layers/VectorLayer.js';

js/src/layers/ImageServiceLayer.js

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Distributed under the terms of the Modified BSD License.
33

44
const L = require('../leaflet.js');
5-
const imageoverlay = require('./ImageOverlay.js');
5+
const rasterlayer = require('./RasterLayer.js');
66
const proj = require('../projections.js');
77

8-
export class LeafletImageServiceLayerModel extends imageoverlay.LeafletImageOverlayModel {
8+
export class LeafletImageServiceLayerModel extends rasterlayer.LeafletRasterLayerModel {
99
defaults() {
1010
return {
1111
...super.defaults(),
@@ -19,21 +19,21 @@ export class LeafletImageServiceLayerModel extends imageoverlay.LeafletImageOver
1919
// data type of the raster image
2020
pixel_type: 'F32',
2121
// pixel value or list of pixel values representing no data
22-
no_data: null,
22+
no_data: [],
2323
// how to interpret no data values
2424
no_data_interpretation: '',
2525
// resampling process for interpolating the pixel values
2626
interpolation: '',
2727
// lossy quality for image compression
2828
compression_quality: '',
2929
// order of bands to export for multiple band images
30-
band_ids: null,
30+
band_ids: [],
3131
// time instance or extent for image
32-
time: null,
32+
time: [],
3333
// rules for rendering
34-
rendering_rule: null,
34+
rendering_rule: {},
3535
// rules for mosaicking
36-
mosaic_rule: null,
36+
mosaic_rule: {},
3737
// image transparency
3838
transparent: false,
3939
// coordinate reference system
@@ -44,10 +44,10 @@ export class LeafletImageServiceLayerModel extends imageoverlay.LeafletImageOver
4444
}
4545
}
4646

47-
export class LeafletImageServiceLayerView extends imageoverlay.LeafletImageOverlayView {
47+
export class LeafletImageServiceLayerView extends rasterlayer.LeafletRasterLayerView {
4848
create_obj() {
4949
this.model._url = this.model.get('url') + '/exportImage' + this.buildParams()
50-
this.model._bounds = this._map.getBounds()
50+
this.model._bounds = this.get_bounds()
5151
this.obj = L.ImageOverlay(this.model._url, this.model._bounds)
5252
}
5353

@@ -56,13 +56,38 @@ export class LeafletImageServiceLayerView extends imageoverlay.LeafletImageOverl
5656
for (var option in this.get_options()) {
5757
this._map.on('change:' + option, () => {
5858
this.model._url = this.model.get('url') + '/exportImage' + this.buildParams()
59-
this.model._bounds = this._map.getBounds()
59+
this.model._bounds = this.get_bounds()
60+
this.obj.setUrl(this.model._url);
61+
this.obj.setBounds(this.model._bounds);
6062
this.refresh();
6163
});
62-
}
64+
};
65+
this._map.on('moveend', () => {
66+
this.model._url = this.model.get('url') + '/exportImage' + this.buildParams()
67+
this.model._bounds = this.get_bounds()
68+
this.obj.setUrl(this.model._url);
69+
this.obj.setBounds(this.model._bounds);
70+
this.refresh();
71+
})
72+
}
73+
74+
get_bbox () {
75+
return [this._map.getBounds().getWest(),
76+
this._map.getBounds().getSouth(),
77+
this._map.getBounds().getEast(),
78+
this._map.getBounds().getNorth()]
79+
}
80+
81+
get_bounds () {
82+
return [[map.getBounds().getSouth(),map.getBounds().getWest()],
83+
[map.getBounds().getNorth(),map.getBounds().getEast()]]
84+
}
85+
86+
get_size () {
87+
return [this._map.getSize().x, this._map.getSize().y]
6388
}
6489

65-
model_epsg() {
90+
get_epsg() {
6691
// get the EPSG code of the current map
6792
var crs = proj.getProjection(this.model.get('crs'))
6893
var spatial_reference = parseInt(crs.code.split(':')[1], 10);
@@ -72,10 +97,10 @@ export class LeafletImageServiceLayerView extends imageoverlay.LeafletImageOverl
7297
buildParams () {
7398
// parameters for image server query
7499
var params = {
75-
bbox: this._map.getBounds(),
76-
size: this._map.getSize(),
100+
bbox: this.get_bbox(),
101+
size: this.get_size(),
77102
bboxSR: 4326,
78-
imageSR: this.model_epsg(),
103+
imageSR: this.get_epsg(),
79104
...this.get_options()
80105
};
81106
// merge list parameters

js/src/leaflet-imageservice.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
// Copyright (c) Jupyter Development Team.
3+
// Distributed under the terms of the Modified BSD License.
4+
5+
L.ImageServiceLayer = L.RasterLayer.extend({
6+
options: {
7+
url: '',
8+
f: 'image',
9+
format: 'png',
10+
pixel_type: 'F32',
11+
no_data: [],
12+
no_data_interpretation: '',
13+
interpolation: '',
14+
compression_quality: '',
15+
band_ids: [],
16+
time: [],
17+
rendering_rule: {},
18+
mosaic_rule: {},
19+
transparent: false,
20+
crs: null
21+
},
22+
23+
initialize: function(options) {
24+
L.Util.setOptions(this, options);
25+
},
26+
27+
})
28+
29+
L.imageServiceLayer = function (options) {
30+
return new L.ImageServiceLayer(options);
31+
};

js/src/leaflet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require('leaflet.markercluster');
99
require('leaflet-velocity');
1010
require('leaflet-measure');
1111
require('./leaflet-heat.js');
12+
require('./leaflet-imageservice.js');
1213
require('./leaflet-magnifyingglass.js');
1314
require('leaflet-rotatedmarker');
1415
require('leaflet-fullscreen');

0 commit comments

Comments
 (0)