georaster-layer-for-leaflet
Version:
Display GeoTIFFs and soon other types of raster on your Leaflet Map
1,304 lines (1,082 loc) • 137 kB
JavaScript
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = function (module) {
if (!module.webpackPolyfill) {
module.deprecate = function () {};
module.paths = []; // module.parent = undefined by default
if (!module.children) module.children = [];
Object.defineProperty(module, "loaded", {
enumerable: true,
get: function get() {
return module.l;
}
});
Object.defineProperty(module, "id", {
enumerable: true,
get: function get() {
return module.i;
}
});
module.webpackPolyfill = 1;
}
return module;
};
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* WEBPACK VAR INJECTION */(function(module) {/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_regenerator_runtime_runtime__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_regenerator_runtime_runtime___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_regenerator_runtime_runtime__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_chroma_js__ = __webpack_require__(4);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_chroma_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_chroma_js__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_utm_utils_src_isUTM__ = __webpack_require__(5);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_utm_utils_src_isUTM___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_utm_utils_src_isUTM__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_utm_utils_src_getProjString__ = __webpack_require__(6);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_utm_utils_src_getProjString___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_utm_utils_src_getProjString__);
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/* global L, proj4 */
var EPSG4326 = 4326;
var PROJ4_SUPPORTED_PROJECTIONS = new Set([3857, 4269]);
var MAX_NORTHING = 1000;
var MAX_EASTING = 1000;
var ORIGIN = [0, 0];
var GeoRasterLayer = L.GridLayer.extend({
initialize: function initialize(options) {
var _this = this;
try {
if (options.georasters) {
this.georasters = options.georasters;
} else if (options.georaster) {
this.georasters = [options.georaster];
} else {
throw new Error("You must initialize a GeoRasterLayer with a georaster or georasters value");
}
/*
Unpacking values for use later.
We do this in order to increase speed.
*/
var keys = ["height", "width", "noDataValue", "palette", "pixelHeight", "pixelWidth", "projection", "sourceType", "xmin", "xmax", "ymin", "ymax"];
if (this.georasters.length > 1) {
keys.forEach(function (key) {
if (_this.same(_this.georasters, key)) {
_this[key] = _this.georasters[0][key];
} else {
throw new Error("all GeoRasters must have the same " + key);
}
});
} else if (this.georasters.length === 1) {
keys.forEach(function (key) {
_this[key] = _this.georasters[0][key];
});
} // used later if simple projection
this.ratio = this.height / this.width;
if (this.sourceType === "url") {
if (!options.updateWhenIdle) options.updateWhenIdle = false;
if (!options.updateWhenZooming) options.updateWhenZooming = true;
if (!options.keepBuffer) options.keepBuffer = 16;
}
if (!("debugLevel" in options)) options.debugLevel = 1;
if (!options.keepBuffer) options.keepBuffer = 25;
if (!options.resolution) options.resolution = Math.pow(2, 5);
if (options.updateWhenZooming === undefined) options.updateWhenZooming = false;
this.debugLevel = options.debugLevel;
if (this.debugLevel >= 1) console.log("georaster:", options);
if (this.georasters.every(function (georaster) {
return _typeof(georaster.values) === "object";
})) {
this.rasters = this.georasters.reduce(function (result, georaster) {
result = result.concat(georaster.values);
return result;
}, []);
if (this.debugLevel > 1) console.log("this.rasters:", this.rasters);
}
this.chroma = __WEBPACK_IMPORTED_MODULE_1_chroma_js___default.a;
this.scale = __WEBPACK_IMPORTED_MODULE_1_chroma_js___default.a.scale();
L.setOptions(this, options);
/*
Caching the constant tile size, so we don't recalculate everytime we
create a new tile
*/
var tileSize = this.getTileSize();
this.tileHeight = tileSize.y;
this.tileWidth = tileSize.x;
if (this.georasters.length > 1 && !options.pixelValuesToColorFn) {
throw "you must pass in a pixelValuesToColorFn if you are combining rasters";
}
if (this.georasters.length === 1 && this.georasters[0].sourceType === "url" && this.georasters[0].numberOfRasters === 1 && !options.pixelValuesToColorFn) {
// For COG, we can't determine a data min max for color scaling,
// so pixelValuesToColorFn is required.
throw "pixelValuesToColorFn is a required option for single-band rasters initialized via URL";
}
} catch (error) {
console.error("ERROR initializing GeoTIFFLayer", error);
}
},
getRasters: function getRasters(options) {
var _this2 = this;
var tileNwPoint = options.tileNwPoint,
heightOfSampleInScreenPixels = options.heightOfSampleInScreenPixels,
widthOfSampleInScreenPixels = options.widthOfSampleInScreenPixels,
coords = options.coords,
numberOfSamplesAcross = options.numberOfSamplesAcross,
numberOfSamplesDown = options.numberOfSamplesDown,
ymax = options.ymax,
xmin = options.xmin;
if (this.debugLevel >= 1) console.log("starting getRasters with options:", options); // called if georaster was constructed from URL and we need to get
// data separately for each tile
// aka 'COG mode'
/*
This function takes in coordinates in the rendered image tile and
returns the y and x values in the original raster
*/
var rasterCoordsForTileCoords = function rasterCoordsForTileCoords(h, w) {
var xCenterInMapPixels = tileNwPoint.x + (w + 0.5) * widthOfSampleInScreenPixels;
var yCenterInMapPixels = tileNwPoint.y + (h + 0.5) * heightOfSampleInScreenPixels;
var mapPoint = L.point(xCenterInMapPixels, yCenterInMapPixels);
if (_this2.debugLevel >= 1) console.log("mapPoint:", mapPoint);
var _this2$getMap$unproje = _this2.getMap().unproject(mapPoint, coords.z),
lat = _this2$getMap$unproje.lat,
lng = _this2$getMap$unproje.lng;
if (_this2.projection === EPSG4326) {
return {
y: Math.floor((ymax - lat) / _this2.pixelHeight),
x: Math.floor((lng - xmin) / _this2.pixelWidth)
};
} else if (_this2.getProjector()) {
/* source raster doesn't use latitude and longitude,
so need to reproject point from lat/long to projection of raster
*/
var _this2$getProjector$i = _this2.getProjector().inverse([lng, lat]),
_this2$getProjector$i2 = _slicedToArray(_this2$getProjector$i, 2),
x = _this2$getProjector$i2[0],
y = _this2$getProjector$i2[1];
if (x === Infinity || y === Infinity) {
if (_this2.debugLevel >= 1) console.error("projector converted", [lng, lat], "to", [x, y]);
}
return {
y: Math.floor((ymax - y) / _this2.pixelHeight),
x: Math.floor((x - xmin) / _this2.pixelWidth)
};
}
}; // careful not to flip min_y/max_y here
var topLeft = rasterCoordsForTileCoords(0, 0);
var bottomRight = rasterCoordsForTileCoords(numberOfSamplesDown - 1, numberOfSamplesAcross - 1);
var getValuesOptions = {
bottom: bottomRight.y,
height: numberOfSamplesDown,
left: topLeft.x,
right: bottomRight.x,
top: topLeft.y,
width: numberOfSamplesAcross
};
if (!Object.values(getValuesOptions).every(isFinite)) {
console.error("getRasters failed because not all values are finite:", getValuesOptions);
} else {
return Promise.all(this.georasters.map(function (georaster) {
return georaster.getValues(getValuesOptions);
})).then(function (valuesByGeoRaster) {
return valuesByGeoRaster.reduce(function (result, values) {
result = result.concat(values);
return result;
}, []);
});
}
},
createTile: function createTile(coords, done) {
var _this3 = this;
var error;
var inSimpleCRS = this.getMap().options.crs === L.CRS.Simple; // Unpacking values for increased speed
var rasters = this.rasters,
xmin = this.xmin,
ymax = this.ymax;
var rasterHeight = this.height;
var rasterWidth = this.width;
var pixelHeight = inSimpleCRS ? this.getBounds()._northEast.lat / rasterHeight : this.pixelHeight;
var pixelWidth = inSimpleCRS ? this.getBounds()._northEast.lng / rasterWidth : this.pixelWidth; // these values are used, so we don't try to sample outside of the raster
var xMinOfLayer = this.xMinOfLayer,
xMaxOfLayer = this.xMaxOfLayer,
yMinOfLayer = this.yMinOfLayer,
yMaxOfLayer = this.yMaxOfLayer;
/* This tile is the square piece of the Leaflet map that we draw on */
var tile = L.DomUtil.create("canvas", "leaflet-tile");
tile.height = this.tileHeight;
tile.width = this.tileWidth;
var context = tile.getContext("2d");
var boundsOfTile = this._tileCoordsToBounds(coords);
var xMinOfTileInMapCRS = boundsOfTile.getWest();
var xMaxOfTileInMapCRS = boundsOfTile.getEast();
var yMinOfTileInMapCRS = boundsOfTile.getSouth();
var yMaxOfTileInMapCRS = boundsOfTile.getNorth();
var rasterPixelsAcross, rasterPixelsDown;
if (inSimpleCRS || this.projection === EPSG4326) {
// width of the Leaflet tile in number of pixels from original raster
rasterPixelsAcross = Math.ceil((xMaxOfTileInMapCRS - xMinOfTileInMapCRS) / pixelWidth);
rasterPixelsDown = Math.ceil((yMaxOfTileInMapCRS - yMinOfTileInMapCRS) / pixelHeight);
} else if (this.getProjector()) {
var projector = this.getProjector(); // convert extent of Leaflet tile to projection of the georaster
var topLeft = projector.inverse({
x: xMinOfTileInMapCRS,
y: yMaxOfTileInMapCRS
});
var topRight = projector.inverse({
x: xMaxOfTileInMapCRS,
y: yMaxOfTileInMapCRS
});
var bottomLeft = projector.inverse({
x: xMinOfTileInMapCRS,
y: yMinOfTileInMapCRS
});
var bottomRight = projector.inverse({
x: xMaxOfTileInMapCRS,
y: yMinOfTileInMapCRS
});
rasterPixelsAcross = Math.ceil(Math.max(topRight.x - topLeft.x, bottomRight.x - bottomLeft.x) / pixelWidth);
rasterPixelsDown = Math.ceil(Math.max(topLeft.y - bottomLeft.y, topRight.y - bottomRight.y) / pixelHeight);
}
var resolution = this.options.resolution; // prevent sampling more times than number of pixels to display
var numberOfSamplesAcross = Math.min(resolution, rasterPixelsAcross);
var numberOfSamplesDown = Math.min(resolution, rasterPixelsDown); // set how large to display each sample in screen pixels
var heightOfSampleInScreenPixels = this.tileHeight / numberOfSamplesDown;
var heightOfSampleInScreenPixelsInt = Math.ceil(heightOfSampleInScreenPixels);
var widthOfSampleInScreenPixels = this.tileWidth / numberOfSamplesAcross;
var widthOfSampleInScreenPixelsInt = Math.ceil(widthOfSampleInScreenPixels);
var map = this.getMap();
var tileSize = this.getTileSize(); // this converts tile coordinates (how many tiles down and right)
// to pixels from left and top of tile pane
var tileNwPoint = coords.scaleBy(tileSize); // render asynchronously so tiles show up as they finish instead of all at once (which blocks the UI)
setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
var tileRasters, _loop, h, _ret;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (rasters) {
_context.next = 4;
break;
}
_context.next = 3;
return _this3.getRasters({
tileNwPoint: tileNwPoint,
heightOfSampleInScreenPixels: heightOfSampleInScreenPixels,
widthOfSampleInScreenPixels: widthOfSampleInScreenPixels,
coords: coords,
pixelHeight: pixelHeight,
pixelWidth: pixelWidth,
numberOfSamplesAcross: numberOfSamplesAcross,
numberOfSamplesDown: numberOfSamplesDown,
ymax: ymax,
xmin: xmin
});
case 3:
tileRasters = _context.sent;
case 4:
_loop = function _loop(h) {
var yCenterInMapPixels = tileNwPoint.y + (h + 0.5) * heightOfSampleInScreenPixels;
var latWestPoint = L.point(tileNwPoint.x, yCenterInMapPixels);
var _map$unproject = map.unproject(latWestPoint, coords.z),
lat = _map$unproject.lat;
if (lat > yMinOfLayer && lat < yMaxOfLayer) {
var _ret2 = function () {
var yInTilePixels = Math.round(h * heightOfSampleInScreenPixels);
var yInRasterPixels;
if (inSimpleCRS || _this3.projection === EPSG4326) {
yInRasterPixels = Math.floor((yMaxOfLayer - lat) / pixelHeight);
} else {
yInRasterPixels = null;
}
var _loop2 = function _loop2(w) {
var latLngPoint = L.point(tileNwPoint.x + (w + 0.5) * widthOfSampleInScreenPixels, yCenterInMapPixels);
var _map$unproject2 = map.unproject(latLngPoint, coords.z),
xOfLayer = _map$unproject2.lng;
if (xOfLayer > xMinOfLayer && xOfLayer < xMaxOfLayer) {
var xInRasterPixels;
if (inSimpleCRS || _this3.projection === EPSG4326) {
xInRasterPixels = Math.floor((xOfLayer - xMinOfLayer) / pixelWidth);
} else if (_this3.getProjector()) {
var inverted = _this3.getProjector().inverse({
x: xOfLayer,
y: lat
});
var yInSrc = inverted.y;
yInRasterPixels = Math.floor((ymax - yInSrc) / pixelHeight);
if (yInRasterPixels < 0 || yInRasterPixels >= rasterHeight) return "continue";
var xInSrc = inverted.x;
xInRasterPixels = Math.floor((xInSrc - xmin) / pixelWidth);
if (xInRasterPixels < 0 || xInRasterPixels >= rasterWidth) return "continue";
}
var values = null;
if (tileRasters) {
// get value from array specific to this tile
values = tileRasters.map(function (band) {
return band[h][w];
});
} else if (rasters) {
// get value from array with data for entire raster
values = rasters.map(function (band) {
return band[yInRasterPixels][xInRasterPixels];
});
} else {
done("no rasters are available for, so skipping value generation");
return {
v: {
v: {
v: void 0
}
}
};
} // x-axis coordinate of the starting point of the rectangle representing the raster pixel
var x = Math.round(w * widthOfSampleInScreenPixels); // y-axis coordinate of the starting point of the rectangle representing the raster pixel
var y = yInTilePixels; // how many real screen pixels does a pixel of the sampled raster take up
var width = widthOfSampleInScreenPixelsInt;
var height = heightOfSampleInScreenPixelsInt;
if (_this3.options.customDrawFunction) {
_this3.options.customDrawFunction({
values: values,
context: context,
x: x,
y: y,
width: width,
height: height,
rasterX: xInRasterPixels,
rasterY: yInRasterPixels,
sampleX: w,
sampleY: h,
sampledRaster: tileRasters
});
} else {
var color = _this3.getColor(values);
if (color) {
context.fillStyle = color;
context.fillRect(x, y, width, height);
}
}
}
};
for (var w = 0; w < numberOfSamplesAcross; w++) {
var _ret3 = _loop2(w);
if (_ret3 === "continue") continue;
if (_typeof(_ret3) === "object") return _ret3.v;
}
}();
if (_typeof(_ret2) === "object") return _ret2.v;
}
};
h = 0;
case 6:
if (!(h < numberOfSamplesDown)) {
_context.next = 13;
break;
}
_ret = _loop(h);
if (!(_typeof(_ret) === "object")) {
_context.next = 10;
break;
}
return _context.abrupt("return", _ret.v);
case 10:
h++;
_context.next = 6;
break;
case 13:
done(error, tile);
case 14:
case "end":
return _context.stop();
}
}
}, _callee);
})), 0); // return the tile so it can be rendered on screen
return tile;
},
// method from https://github.com/Leaflet/Leaflet/blob/bb1d94ac7f2716852213dd11563d89855f8d6bb1/src/layer/ImageOverlay.js
getBounds: function getBounds() {
this.initBounds();
return this._bounds;
},
getMap: function getMap() {
return this._map || this._mapToAdd;
},
_isValidTile: function _isValidTile(coords) {
var crs = this.getMap().options.crs;
if (!crs.infinite) {
// don't load tile if it's out of bounds and not wrapped
var globalBounds = this._globalTileRange;
if (!crs.wrapLng && (coords.x < globalBounds.min.x || coords.x > globalBounds.max.x) || !crs.wrapLat && (coords.y < globalBounds.min.y || coords.y > globalBounds.max.y)) {
return false;
}
}
var bounds = this.getBounds();
if (!bounds) {
return true;
}
var x = coords.x,
y = coords.y,
z = coords.z;
var layerBounds = L.latLngBounds(bounds);
var boundsOfTile = this._tileCoordsToBounds(coords); // check given tile coordinates
if (layerBounds.overlaps(boundsOfTile)) return true; // if not within the original confines of the earth return false
// we don't want wrapping if using Simple CRS
if (crs === L.CRS.Simple) return false; // width of the globe in tiles at the given zoom level
var width = Math.pow(2, z); // check one world to the left
var leftCoords = L.point(x - width, y);
leftCoords.z = z;
if (layerBounds.overlaps(this._tileCoordsToBounds(leftCoords))) return true; // check one world to the right
var rightCoords = L.point(x + width, y);
rightCoords.z = z;
if (layerBounds.overlaps(this._tileCoordsToBounds(rightCoords))) return true;
return false;
},
getColor: function getColor(values) {
var _this4 = this;
if (this.options.pixelValuesToColorFn) {
return this.options.pixelValuesToColorFn(values);
} else {
var numberOfValues = values.length;
var haveDataForAllBands = values.every(function (value) {
return value !== undefined && value !== _this4.noDataValue;
});
if (haveDataForAllBands) {
if (numberOfValues == 1) {
var _this$georasters$ = this.georasters[0],
mins = _this$georasters$.mins,
ranges = _this$georasters$.ranges;
var value = values[0];
if (this.palette) {
var _this$palette$value = _slicedToArray(this.palette[value], 4),
r = _this$palette$value[0],
g = _this$palette$value[1],
b = _this$palette$value[2],
a = _this$palette$value[3];
return "rgba(".concat(r, ",").concat(g, ",").concat(b, ",").concat(a / 255, ")");
} else {
return this.scale((values[0] - mins[0]) / ranges[0]).hex();
}
} else if (numberOfValues === 2) {
return "rgb(".concat(values[0], ",").concat(values[1], ",0)");
} else if (numberOfValues === 3) {
return "rgb(".concat(values[0], ",").concat(values[1], ",").concat(values[2], ")");
} else if (numberOfValues === 4) {
return "rgba(".concat(values[0], ",").concat(values[1], ",").concat(values[2], ",").concat(values[3] / 255, ")");
}
}
}
},
isSupportedProjection: function isSupportedProjection(projection) {
if (!projection) projection = this.projection;
return __WEBPACK_IMPORTED_MODULE_2_utm_utils_src_isUTM___default()(projection) || PROJ4_SUPPORTED_PROJECTIONS.has(projection);
},
getProjectionString: function getProjectionString(projection) {
if (__WEBPACK_IMPORTED_MODULE_2_utm_utils_src_isUTM___default()(projection)) {
return __WEBPACK_IMPORTED_MODULE_3_utm_utils_src_getProjString___default()(projection);
}
return "EPSG:".concat(projection);
},
initBounds: function initBounds() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options;
if (!this._bounds) {
var debugLevel = this.debugLevel,
height = this.height,
width = this.width,
projection = this.projection,
xmin = this.xmin,
xmax = this.xmax,
ymin = this.ymin,
ymax = this.ymax; // check if map using Simple CRS
if (this.getMap().options.crs === L.CRS.Simple) {
if (height === width) {
this._bounds = L.latLngBounds([ORIGIN, [MAX_NORTHING, MAX_EASTING]]);
} else if (height > width) {
this._bounds = L.latLngBounds([ORIGIN, [MAX_NORTHING, MAX_EASTING / this.ratio]]);
} else if (width > height) {
this._bounds = L.latLngBounds([ORIGIN, [MAX_NORTHING * this.ratio, MAX_EASTING]]);
}
} else if (projection === EPSG4326) {
if (debugLevel >= 1) console.log("georaster projection is in ".concat(EPSG4326));
var minLatWest = L.latLng(ymin, xmin);
var maxLatEast = L.latLng(ymax, xmax);
this._bounds = L.latLngBounds(minLatWest, maxLatEast);
} else if (this.getProjector()) {
if (debugLevel >= 1) console.log("projection is UTM or supported by proj4");
var bottomLeft = this.getProjector().forward({
x: xmin,
y: ymin
});
var _minLatWest = L.latLng(bottomLeft.y, bottomLeft.x);
var topRight = this.getProjector().forward({
x: xmax,
y: ymax
});
var _maxLatEast = L.latLng(topRight.y, topRight.x);
this._bounds = L.latLngBounds(_minLatWest, _maxLatEast);
} else {
throw "georaster-layer-for-leaflet does not support rasters with the projection ".concat(projection);
} // these values are used so we don't try to sample outside of the raster
this.xMinOfLayer = this._bounds.getWest();
this.xMaxOfLayer = this._bounds.getEast();
this.yMaxOfLayer = this._bounds.getNorth();
this.yMinOfLayer = this._bounds.getSouth();
options.bounds = this._bounds;
}
},
getProjector: function getProjector() {
if (this.isSupportedProjection(this.projection)) {
if (!proj4) {
throw "proj4 must be found in the global scope in order to load a raster that uses a UTM projection";
}
if (!this._projector) {
this._projector = proj4(this.getProjectionString(this.projection), "EPSG:".concat(EPSG4326));
if (this.debugLevel >= 1) console.log("projector set");
}
return this._projector;
}
},
same: function same(array, key) {
return new Set(array.map(function (item) {
return item[key];
})).size === 1;
}
});
if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
module.exports = GeoRasterLayer;
}
if (typeof window !== "undefined") {
window["GeoRasterLayer"] = GeoRasterLayer;
} else if (typeof self !== "undefined") {
self["GeoRasterLayer"] = GeoRasterLayer; // jshint ignore:line
}
/* WEBPACK VAR INJECTION */}.call(__webpack_exports__, __webpack_require__(2)(module)))
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = function (originalModule) {
if (!originalModule.webpackPolyfill) {
var module = Object.create(originalModule); // module.parent = undefined by default
if (!module.children) module.children = [];
Object.defineProperty(module, "loaded", {
enumerable: true,
get: function get() {
return module.l;
}
});
Object.defineProperty(module, "id", {
enumerable: true,
get: function get() {
return module.i;
}
});
Object.defineProperty(module, "exports", {
enumerable: true
});
module.webpackPolyfill = 1;
}
return module;
};
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var runtime = function (exports) {
"use strict";
var Op = Object.prototype;
var hasOwn = Op.hasOwnProperty;
var undefined; // More compressible than void 0.
var $Symbol = typeof Symbol === "function" ? Symbol : {};
var iteratorSymbol = $Symbol.iterator || "@@iterator";
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function define(obj, key, value) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
return obj[key];
}
try {
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
define({}, "");
} catch (err) {
define = function define(obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
var generator = Object.create(protoGenerator.prototype);
var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
// .throw, and .return methods.
generator._invoke = makeInvokeMethod(innerFn, self, context);
return generator;
}
exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
// record like context.tryEntries[i].completion. This interface could
// have been (and was previously) designed to take a closure to be
// invoked without arguments, but in all the cases we care about we
// already have an existing method we want to call, so there's no need
// to create a new function object. We can even get away with assuming
// the method takes exactly one argument, since that happens to be true
// in every case, so we don't have to touch the arguments object. The
// only additional allocation required is the completion record, which
// has a stable shape and so hopefully should be cheap to allocate.
function tryCatch(fn, obj, arg) {
try {
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return {
type: "throw",
arg: err
};
}
}
var GenStateSuspendedStart = "suspendedStart";
var GenStateSuspendedYield = "suspendedYield";
var GenStateExecuting = "executing";
var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
// breaking out of the dispatch switch statement.
var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
// .constructor.prototype properties for functions that return Generator
// objects. For full spec compliance, you may wish to configure your
// minifier not to mangle the names of these two functions.
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
// don't natively support it.
var IteratorPrototype = {};
IteratorPrototype[iteratorSymbol] = function () {
return this;
};
var getProto = Object.getPrototypeOf;
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
// This environment has a native %IteratorPrototype%; use it instead
// of the polyfill.
IteratorPrototype = NativeIteratorPrototype;
}
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
GeneratorFunctionPrototype.constructor = GeneratorFunction;
GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
// Iterator interface in terms of a single ._invoke method.
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);
});
});
}
exports.isGeneratorFunction = function (genFun) {
var ctor = typeof genFun === "function" && genFun.constructor;
return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
// do is to check its .name property.
(ctor.displayName || ctor.name) === "GeneratorFunction" : false;
};
exports.mark = function (genFun) {
if (Object.setPrototypeOf) {
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
} else {
genFun.__proto__ = GeneratorFunctionPrototype;
define(genFun, toStringTagSymbol, "GeneratorFunction");
}
genFun.prototype = Object.create(Gp);
return genFun;
}; // Within the body of any async function, `await x` is transformed to
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
// `hasOwn.call(value, "__await")` to determine if the yielded value is
// meant to be awaited.
exports.awrap = function (arg) {
return {
__await: arg
};
};
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if (record.type === "throw") {
reject(record.arg);
} else {
var result = record.arg;
var value = result.value;
if (value && _typeof(value) === "object" && hasOwn.call(value, "__await")) {
return PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
});
}
return PromiseImpl.resolve(value).then(function (unwrapped) {
// When a yielded Promise is resolved, its final value becomes
// the .value of the Promise<{value,done}> result for the
// current iteration.
result.value = unwrapped;
resolve(result);
}, function (error) {
// If a rejected Promise was yielded, throw the rejection back
// into the async generator function so it can be handled there.
return invoke("throw", error, resolve, reject);
});
}
}
var previousPromise;
function enqueue(method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return previousPromise = // If enqueue has been called before, then we want to wait until
// all previous Promises have been resolved before calling invoke,
// so that results are always delivered in the correct order. If
// enqueue has not been called before, then it is important to
// call invoke immediately, without waiting on a callback to fire,
// so that the async generator function has the opportunity to do
// any necessary setup in a predictable way. This predictability
// is why the Promise constructor synchronously invokes its
// executor callback, and why async functions synchronously
// execute code before the first await. Since we implement simple
// async functions in terms of async generators, it is especially
// important to get this right, even though it requires care.
previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
// invocations of the iterator.
callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
} // Define the unified helper method that is used to implement .next,
// .throw, and .return (see defineIteratorMethods).
this._invoke = enqueue;
}
defineIteratorMethods(AsyncIterator.prototype);
AsyncIterator.prototype[asyncIteratorSymbol] = function () {
return this;
};
exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
// AsyncIterator objects; they just return a Promise for the value of
// the final result produced by the iterator.
exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
if (PromiseImpl === void 0) PromiseImpl = Promise;
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
: iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
};
function makeInvokeMethod(innerFn, self, context) {
var state = GenStateSuspendedStart;
return function invoke(method, arg) {
if (state === GenStateExecuting) {
throw new Error("Generator is already running");
}
if (state === GenStateCompleted) {
if (method === "throw") {
throw arg;
} // Be forgiving, per 25.3.3.3.3 of the spec:
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
return doneResult();
}
context.method = method;
context.arg = arg;
while (true) {
var delegate = context.delegate;
if (delegate) {
var delegateResult = maybeInvokeDelegate(delegate, context);
if (delegateResult) {
if (delegateResult === ContinueSentinel) continue;
return delegateResult;
}
}
if (context.method === "next") {
// Setting context._sent for legacy support of Babel's
// function.sent implementation.
context.sent = context._sent = context.arg;
} else if (context.method === "throw") {
if (state === GenStateSuspendedStart) {
state = GenStateCompleted;
throw context.arg;
}
context.dispatchException(context.arg);
} else if (context.method === "return") {
context.abrupt("return", context.arg);
}
state = GenStateExecuting;
var record = tryCatch(innerFn, self, context);
if (record.type === "normal") {
// If an exception is thrown from innerFn, we leave state ===
// GenStateExecuting and loop back for another invocation.
state = context.done ? GenStateCompleted : GenStateSuspendedYield;
if (record.arg === ContinueSentinel) {
continue;
}
return {
value: record.arg,
done: context.done
};
} else if (record.type === "throw") {
state = GenStateCompleted; // Dispatch the exception by looping back around to the
// context.dispatchException(context.arg) call above.
context.method = "throw";
context.arg = record.arg;
}
}
};
} // Call delegate.iterator[context.method](context.arg) and handle the
// result, either by returning a { value, done } result from the
// delegate iterator, or by modifying context.method and context.arg,
// setting context.delegate to null, and returning the ContinueSentinel.
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
if (method === undefined) {
// A .throw or .return when the delegate iterator has no .throw
// method always terminates the yield* loop.
context.delegate = null;
if (context.method === "throw") {
// Note: ["return"] must be used for ES3 parsing compatibility.
if (delegate.iterator["return"]) {
// If the delegate iterator has a return method, give it a
// chance to clean up.
context.method = "return";
context.arg = undefined;
maybeInvokeDelegate(delegate, context);
if (context.method === "throw") {
// If maybeInvokeDelegate(context) changed context.method from
// "return" to "throw", let that override the TypeError below.
return ContinueSentinel;
}
}
context.method = "throw";
context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
return ContinueSentinel;
}
var record = tryCatch(method, delegate.iterator, context.arg);
if (record.type === "throw") {
context.method = "throw";
context.arg = record.arg;
context.delegate = null;
return ContinueSentinel;
}
var info = record.arg;
if (!info) {
context.method = "throw";
context.arg = new TypeError("iterator result is not an object");
context.delegate = null;
return ContinueSentinel;
}
if (info.done) {
// Assign the result of the finished delegate to the temporary
// variable specified by delegate.resultName (see delegateYield).
context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
// exception, let the outer generator proceed normally. If
// context.method was "next", forget context.arg since it has been
// "consumed" by the delegate iterator. If context.method was
// "return", allow the original .return call to continue in the
// outer generator.
if (context.method !== "return") {
context.method = "next";
context.arg = undefined;
}
} else {
// Re-yield the result returned by the delegate method.
return info;
} // The delegate iterator is finished, so forget it and continue with
// the outer generator.
context.delegate = null;
return ContinueSentinel;
} // Define Generator.prototype.{next,throw,return} in terms of the
// unified ._invoke helper method.
defineIteratorMethods(Gp);
define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
// @@iterator function is called on it. Some browsers' implementations of the
// iterator prototype chain incorrectly implement this, causing the Generator
// object to not be returned from this call. This ensures that doesn't happen.
// See https://github.com/facebook/regenerator/issues/274 for more details.
Gp[iteratorSymbol] = function () {
return this;
};
Gp.toString = function () {
return "[object Generator]";
};
function pushTryEntry(locs) {
var entry = {
tryLoc: locs[0]
};
if (1 in locs) {
entry.catchLoc = locs[1];
}
if (2 in locs) {
entry.finallyLoc = locs[2];
entry.afterLoc = locs[3];
}
this.tryEntries.push(entry);
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal";
delete record.arg;
entry.completion = record;
}
function Context(tryLocsList) {
// The root entry object (effectively a try statement without a catch
// or a finally block) gives us a place to store values thrown from
// locations where there is no enclosing try statement.
this.tryEntries = [{
tryLoc: "root"
}];
tryLocsList.forEach(pushTryEntry, this);
this.reset(true);
}
exports.keys = function (object) {
var keys = [];
for (var key in object) {
keys.push(key);
}
keys.reverse(); // Rather than returning an object with a next method, we keep
// things simple and return the next function itself.
return function next() {
while (keys.length) {
var key = keys.pop();
if (key in object) {
next.value = key;
next.done = false;
return next;
}
} // To avoid creating an additional object, we just hang the .value
// and .done properties off the next function object itself. This
// also ensures that the minifier will not anonymize the function.
next.done = true;
return next;
};
};
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) {
return iteratorMethod.call(iterable);
}
if (typeof iterable.next === "function") {
return iterable;
}
if (!isNaN(iterable.length)) {
var i = -1,
next = function next() {
while (++i < iterable.length) {
if (hasOwn.call(iterable, i)) {
next.value = iterable[i];
next.done = false;
return next;
}
}
next.value = undefined;
next.done = true;
return next;
};
return next.next = next;
}
} // Return an iterator with no values.
return {
next: doneResult
};
}
exports.values = values;
function doneResult() {
return {
value: undefined,
done: true
};
}
Context.prototype = {
constructor: Context,
reset: function reset(skipTempReset) {
this.prev = 0;
this.next = 0; // Resetting context._sent for legacy support of Babel's
// function.sent implementation.
this.sent = this._sent = undefined;
this.done = false;
this.delegate = null;
this.method = "next";
this.arg = undefined;
this.tryEntries.forEach(resetTryEntry);
if (!skipTempRese