-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start working on imageservicelayer function
throttle updates on move try adding initimage
- Loading branch information
1 parent
74e40a3
commit bbc108c
Showing
6 changed files
with
191 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
const proj = require('./projections.js'); | ||
|
||
L.ImageServiceLayer = L.ImageOverlay.extend({ | ||
options: { | ||
// image server url | ||
url: '', | ||
// response format | ||
f: 'image', | ||
// output image format | ||
format: 'png', | ||
// data type of the raster image | ||
pixel_type: 'F32', | ||
// pixel value or list of pixel values representing no data | ||
no_data: [], | ||
// how to interpret no data values | ||
no_data_interpretation: '', | ||
// resampling process for interpolating the pixel values | ||
interpolation: '', | ||
// lossy quality for image compression | ||
compression_quality: '', | ||
// order of bands to export for multiple band images | ||
band_ids: [], | ||
// time instance or extent for image | ||
time: [], | ||
// rules for rendering | ||
rendering_rule: {}, | ||
// rules for mosaicking | ||
mosaic_rule: {}, | ||
// image transparency | ||
transparent: false, | ||
// coordinate reference system | ||
crs: null, | ||
// update interval for panning | ||
updateInterval: 200 | ||
}, | ||
|
||
initialize: function(options) { | ||
this._url = this.get('url') + '/exportImage' + _buildParams(); | ||
this._bounds = this._getBounds(); | ||
L.Util.setOptions(this, options); | ||
L.ImageOverlay.prototype.initialize.call(this._url, this._bounds); | ||
}, | ||
|
||
updateUrl: function() { | ||
this._url = this.get('url') + '/exportImage' + _buildParams(); | ||
this._bounds = this._getBounds(); | ||
L.ImageOverlay.prototype.setUrl.call(this._url); | ||
L.ImageOverlay.prototype.setBounds.call(this._bounds); | ||
}, | ||
|
||
onAdd: function (map) { | ||
this._map = map; | ||
this.updateUrl(); | ||
if (!this._image) { | ||
this._initImage(); | ||
} | ||
this._map.on('moveend', () => { | ||
L.Util.throttle(this.updateUrl(),this.options.updateInterval,this); | ||
L.ImageOverlay.prototype._reset.call(this); | ||
}); | ||
L.ImageOverlay.prototype.onAdd.call(this); | ||
}, | ||
|
||
onRemove: function (map) { | ||
L.ImageOverlay.prototype.onRemove.call(this, map); | ||
}, | ||
|
||
bringToFront: function () { | ||
L.ImageOverlay.prototype.bringToFront.call(this); | ||
return this; | ||
}, | ||
|
||
bringToBack: function () { | ||
L.ImageOverlay.prototype.bringToBack.call(this); | ||
return this; | ||
}, | ||
|
||
setUrl: function (url) { | ||
this._url = url; | ||
L.ImageOverlay.prototype.setUrl.call(this._url); | ||
return this; | ||
}, | ||
|
||
setBounds: function (bounds) { | ||
this._bounds = bounds; | ||
L.ImageOverlay.prototype.setBounds.call(this._bounds); | ||
return this; | ||
}, | ||
|
||
getBounds: function () { | ||
return this._bounds; | ||
}, | ||
|
||
_getBBox: function() { | ||
// get the bounding box of the current map formatted for exportImage | ||
var pixelbounds = this._map.getPixelBounds(); | ||
var sw = map.unproject(pixelbounds.getBottomLeft()); | ||
var ne = map.unproject(pixelbounds.getTopRight()); | ||
return [this._map.options.crs.project(ne),this._map.options.crs.project(sw)]; | ||
}, | ||
|
||
_getBounds: function() { | ||
// get the bounds of the current map for the ImageOverlay | ||
return [[this._map.getBounds().getSouth(),this._map.getBounds().getWest()], | ||
[this._map.getBounds().getNorth(),this._map.getBounds().getEast()]]; | ||
}, | ||
|
||
_getSize: function() { | ||
// get the size of the current map | ||
var size = this._map.getSize(); | ||
return [size.x, size.y]; | ||
}, | ||
|
||
_getEPSG: function() { | ||
// get the EPSG code of the current map | ||
var crs = proj.getProjection(this.model.get('crs')); | ||
var spatial_reference = parseInt(crs.code.split(':')[1], 10); | ||
return spatial_reference; | ||
}, | ||
|
||
_buildParams: function() { | ||
// parameters for image server query | ||
var params = { | ||
bbox: this._getBBox(), | ||
size: this._getSize(), | ||
bboxSR: this._getEPSG(), | ||
imageSR: this._getEPSG(), | ||
...this.get_options() | ||
}; | ||
// merge list parameters | ||
if (params['noData']) { | ||
params['noData'] = params['noData'].join(','); | ||
} | ||
if (params['bandIds']) { | ||
params['bandIds'] = params['bandIds'].join(','); | ||
} | ||
if (params['time']) { | ||
params['time'] = params['time'].join(','); | ||
} | ||
// convert dictionary parameters to JSON | ||
if (params['renderingRule']) { | ||
params['renderingRule'] = JSON.stringify(params['renderingRule']); | ||
} | ||
if (params['mosaicRule']) { | ||
params['mosaicRule'] = JSON.stringify(params['mosaicRule']); | ||
} | ||
// return the formatted query string | ||
return L.Util.getParamString(params); | ||
}, | ||
|
||
_initImage: function () { | ||
var img = this._image = L.DomUtil.create('img'); | ||
L.DomUtil.addClass(img, 'leaflet-image-layer'); | ||
if (this._zoomAnimated) { L.DomUtil.addClass(img, 'leaflet-zoom-animated'); } | ||
img.onselectstart = L.Util.falseFn; | ||
img.onmousemove = L.Util.falseFn; | ||
img.onload = L.Util.bind(this.fire, this, 'load'); | ||
img.src = this._url; | ||
img.alt = this.options.alt; | ||
}, | ||
|
||
_reset: function () { | ||
L.ImageOverlay.prototype._reset.call(this); | ||
}, | ||
|
||
}); | ||
|
||
L.imageServiceLayer = function (options) { | ||
return new L.ImageServiceLayer(options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters