Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding isNaN to noValueData min/max filter #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dist/leaflet-geotiff-plotty.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
getColorbarOptions: function getColorbarOptions() {
return Object.keys(plotty.colorscales);
},
getColourbarDataUrl: function getColourbarDataUrl(paletteName) {
addColorScale: function addColorScale(name, colors, positions) {
plotty.addColorScale(name, colors, positions);
},
getColorbarDataUrl: function getColorbarDataUrl(paletteName) {
var canvas = document.createElement("canvas");
var plot = new plotty.plot({
canvas: canvas,
Expand All @@ -58,7 +61,7 @@
clampLow: true,
clampHigh: true
});
dataUrl = plot.colorScaleCanvas.toDataURL();
var dataUrl = plot.colorScaleCanvas.toDataURL();
canvas.remove();
return dataUrl;
},
Expand Down
4 changes: 2 additions & 2 deletions dist/leaflet-geotiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@

this._reset();

this.min = this.raster.data[0].filter(val => val !== this.options.noDataValue).reduce((a, b) => Math.min(a, b));
this.max = this.raster.data[0].filter(val => val !== this.options.noDataValue).reduce((a, b) => Math.max(a, b));
this.min = this.raster.data[0].filter(val => !isNaN(val) && val !== this.options.noDataValue).reduce((a, b) => Math.min(a, b));
this.max = this.raster.data[0].filter(val => !isNaN(val) && val !== this.options.noDataValue).reduce((a, b) => Math.max(a, b));
}
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "leaflet-geotiff-2",
"description": "A LeafletJS plugin for displaying geoTIFF raster data.",
"version": "0.5.0",
"version": "0.5.1",
"license": "MIT",
"author": "[email protected]",
"contributors": [
Expand Down
22 changes: 13 additions & 9 deletions src/leaflet-geotiff-plotty.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ L.LeafletGeotiff.Plotty = L.LeafletGeotiffRenderer.extend({
noDataValue: -9999,
},

initialize: function(options) {
initialize: function (options) {
if (typeof plotty === "undefined") {
throw new Error("plotty not defined");
}
Expand All @@ -23,18 +23,18 @@ L.LeafletGeotiff.Plotty = L.LeafletGeotiffRenderer.extend({
this._preLoadColorScale();
},

setColorScale: function(colorScale) {
setColorScale: function (colorScale) {
this.options.colorScale = colorScale;
this.parent._reset();
},

setDisplayRange: function(min, max) {
setDisplayRange: function (min, max) {
this.options.displayMin = min;
this.options.displayMax = max;
this.parent._reset();
},

setClamps: function(clampLow, clampHigh) {
setClamps: function (clampLow, clampHigh) {
this.options.clampLow = clampLow;
this.options.clampHigh = clampHigh;
this.parent._reset();
Expand All @@ -44,7 +44,11 @@ L.LeafletGeotiff.Plotty = L.LeafletGeotiffRenderer.extend({
return Object.keys(plotty.colorscales);
},

getColourbarDataUrl(paletteName) {
addColorScale(name, colors, positions) {
plotty.addColorScale(name, colors, positions);
},

getColorbarDataUrl(paletteName) {
const canvas = document.createElement("canvas");
const plot = new plotty.plot({
canvas,
Expand All @@ -56,12 +60,12 @@ L.LeafletGeotiff.Plotty = L.LeafletGeotiffRenderer.extend({
clampLow: true,
clampHigh: true
});
dataUrl = plot.colorScaleCanvas.toDataURL();
var dataUrl = plot.colorScaleCanvas.toDataURL();
canvas.remove();
return dataUrl;
},

_preLoadColorScale: function() {
_preLoadColorScale: function () {
var canvas = document.createElement("canvas");
var plot = new plotty.plot({
canvas: canvas,
Expand All @@ -76,7 +80,7 @@ L.LeafletGeotiff.Plotty = L.LeafletGeotiffRenderer.extend({
this.colorScaleData = plot.colorScaleCanvas.toDataURL();
},

render: function(raster, canvas, ctx, args) {
render: function (raster, canvas, ctx, args) {
var plottyCanvas = document.createElement("canvas");
var plot = new plotty.plot({
data: raster.data[0], // fix for use with rgb conversion (appending alpha channel)
Expand All @@ -102,6 +106,6 @@ L.LeafletGeotiff.Plotty = L.LeafletGeotiffRenderer.extend({
}
});

L.LeafletGeotiff.plotty = function(options) {
L.LeafletGeotiff.plotty = function (options) {
return new L.LeafletGeotiff.Plotty(options);
};
4 changes: 2 additions & 2 deletions src/leaflet-geotiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ L.LeafletGeotiff = L.ImageOverlay.extend({
this._reset();

this.min = this.raster.data[0]
.filter((val) => val !== this.options.noDataValue)
.filter((val) => !isNaN(val) && val !== this.options.noDataValue)
.reduce((a, b) => Math.min(a, b));
this.max = this.raster.data[0]
.filter((val) => val !== this.options.noDataValue)
.filter((val) => !isNaN(val) && val !== this.options.noDataValue)
.reduce((a, b) => Math.max(a, b));
}
},
Expand Down