Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from Pedrazl/master
Browse files Browse the repository at this point in the history
Fix cell size issue on ScalarField
  • Loading branch information
Pedrazl authored Jun 21, 2019
2 parents 7c861b2 + 19f9c5e commit f6ff195
Show file tree
Hide file tree
Showing 9 changed files with 2,802 additions and 2,999 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ jspm_packages

# Linked library (/dist)
# /docs/dist/leaflet.canvaslayer.field.js
.vscode/settings.json
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@

* Added new method `multipleFromGeoTIFF` to `ScalarField` to return all bands from a GeoTIFF raster file as an array of `ScalarField`, thanks to @santiquetzal (#16).
* Added compatibility with ASCII Grid files using XLLCENTER and YLLCENTER, as suggested in #17

#v1.4.2

* Fix Cell Size issue pointed by @nzahasan in #29
* Update some dependencies (security updates)
2 changes: 1 addition & 1 deletion dist/leaflet.canvaslayer.field.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/leaflet.canvaslayer.field.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/dist/leaflet.canvaslayer.field.js

Large diffs are not rendered by default.

5,748 changes: 2,774 additions & 2,974 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "leaflet-canvaslayer-field",
"version": "1.4.1",
"description":
"A set of layers using canvas to draw ASCIIGrid or GeoTIFF files. This includes a basic raster layer (*ScalaField*) and an animated layer for vector fields, such as wind or currents (*VectorFieldAnim*)",
"version": "1.4.2",
"description": "A set of layers using canvas to draw ASCIIGrid or GeoTIFF files. This includes a basic raster layer (*ScalaField*) and an animated layer for vector fields, such as wind or currents (*VectorFieldAnim*)",
"main": "index.js",
"dependencies": {
"npm": "^3.10.7",
Expand All @@ -13,7 +12,7 @@
"@turf/inside": "^4.7.3"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-core": "^6.26.3",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"eslint": "^3.19.0",
Expand Down
28 changes: 15 additions & 13 deletions src/ScalarField.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export default class ScalarField extends Field {
items.forEach(it => {
let floatItem = parseFloat(it);
let v =
floatItem !== header.noDataValue
? floatItem * scaleFactor
: null;
floatItem !== header.noDataValue ?
floatItem * scaleFactor :
null;
zs.push(v);
});
}
Expand All @@ -51,7 +51,9 @@ export default class ScalarField extends Field {
var items = line.split(' ').filter(i => i != '');
var param = items[0].trim().toUpperCase();
var value = parseFloat(items[1].trim());
return { [param]: value };
return {
[param]: value
};
});

const usesCorner = 'XLLCORNER' in headerItems[2];
Expand All @@ -60,12 +62,12 @@ export default class ScalarField extends Field {
const header = {
nCols: parseInt(headerItems[0]['NCOLS']),
nRows: parseInt(headerItems[1]['NROWS']),
xllCorner: usesCorner
? headerItems[2]['XLLCORNER']
: headerItems[2]['XLLCENTER'] - cellSize,
yllCorner: usesCorner
? headerItems[3]['YLLCORNER']
: headerItems[3]['YLLCENTER'] - cellSize,
xllCorner: usesCorner ?
headerItems[2]['XLLCORNER'] :
headerItems[2]['XLLCENTER'] - cellSize / 2,
yllCorner: usesCorner ?
headerItems[3]['YLLCORNER'] :
headerItems[3]['YLLCENTER'] - cellSize / 2,
cellXSize: cellSize,
cellYSize: cellSize,
noDataValue: headerItems[5]['NODATA_VALUE']
Expand Down Expand Up @@ -107,14 +109,14 @@ export default class ScalarField extends Field {
}

let scalarFields = [];
scalarFields = bandIndexes.map(function(bandIndex) {
scalarFields = bandIndexes.map(function (bandIndex) {
let zs = rasters[bandIndex]; // left-right and top-down order

if (fileDirectory.GDAL_NODATA) {
let noData = parseFloat(fileDirectory.GDAL_NODATA);
// console.log(noData);
let simpleZS = Array.from(zs); // to simple array, so null is allowed | TODO efficiency??
zs = simpleZS.map(function(z) {
zs = simpleZS.map(function (z) {
return z === noData ? null : z;
});
}
Expand Down Expand Up @@ -211,4 +213,4 @@ export default class ScalarField extends Field {
var ry = 1 - y;
return g00 * rx * ry + g10 * x * ry + g01 * rx * y + g11 * x * y;
}
}
}
6 changes: 1 addition & 5 deletions src/_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@ require('./layer/L.CanvasLayer.ScalarField.js');
require('./layer/L.CanvasLayer.VectorFieldAnim.js');

// control
require('./control/L.Control.ColorBar.js');

/* eslint-disable no-console */
console.log('leaflet.canvaslayer.field v1.4.1');
/* eslint-enable no-console */
require('./control/L.Control.ColorBar.js');

0 comments on commit f6ff195

Please sign in to comment.