UNPKG

geospatialdraw

Version:
132 lines 6.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var chai_1 = require("chai"); var utilities_1 = require("./utilities"); describe('geometry', function () { describe('makeGeometry', function () { it('basic line', function () { var geometry = (0, utilities_1.makeGeometry)('identifier', { type: 'LineString', coordinates: [ [10, 30], [15, 40], [20, 25], ], }, 'purple', 'Line'); (0, chai_1.expect)(geometry.type).to.equal('Feature'); (0, chai_1.expect)(geometry.properties.id).to.equal('identifier'); (0, chai_1.expect)(geometry.properties.color).to.equal('purple'); (0, chai_1.expect)(geometry.properties.shape).to.equal('Line'); (0, chai_1.expect)(geometry.properties.buffer).to.equal(0); (0, chai_1.expect)(geometry.properties.bufferUnit).to.equal('meters'); (0, chai_1.expect)(geometry.geometry.type).to.equal('LineString'); (0, chai_1.expect)(geometry.geometry.coordinates).to.deep.equal([ [10, 30], [15, 40], [20, 25], ]); (0, chai_1.expect)(geometry.bbox).to.deep.equal([10, 25, 20, 40]); }); it('buffered line', function () { var geometry = (0, utilities_1.makeGeometry)('identifier', { type: 'LineString', coordinates: [ [10, 30], [15, 40], [20, 25], ], }, 'purple', 'Line', 50, 'miles'); (0, chai_1.expect)(geometry.type).to.equal('Feature'); (0, chai_1.expect)(geometry.properties.id).to.equal('identifier'); (0, chai_1.expect)(geometry.properties.color).to.equal('purple'); (0, chai_1.expect)(geometry.properties.shape).to.equal('Line'); (0, chai_1.expect)(geometry.properties.buffer).to.equal(50); (0, chai_1.expect)(geometry.properties.bufferUnit).to.equal('miles'); (0, chai_1.expect)(geometry.geometry.type).to.equal('LineString'); (0, chai_1.expect)(geometry.geometry.coordinates).to.deep.equal([ [10, 30], [15, 40], [20, 25], ]); (0, chai_1.expect)(geometry.bbox[0]).to.be.below(10); (0, chai_1.expect)(geometry.bbox[1]).to.be.below(25); (0, chai_1.expect)(geometry.bbox[2]).to.be.above(20); (0, chai_1.expect)(geometry.bbox[3]).to.be.above(40); }); it('buffered point', function () { var geometry = (0, utilities_1.makeGeometry)('identifier', { type: 'Point', coordinates: [10, 30], }, 'purple', 'Point Radius', 50, 'miles'); (0, chai_1.expect)(geometry.type).to.equal('Feature'); (0, chai_1.expect)(geometry.properties.id).to.equal('identifier'); (0, chai_1.expect)(geometry.properties.color).to.equal('purple'); (0, chai_1.expect)(geometry.properties.shape).to.equal('Point Radius'); (0, chai_1.expect)(geometry.properties.buffer).to.equal(50); (0, chai_1.expect)(geometry.properties.bufferUnit).to.equal('miles'); (0, chai_1.expect)(geometry.geometry.type).to.equal('Point'); (0, chai_1.expect)(geometry.bbox[0]).to.be.below(10); (0, chai_1.expect)(geometry.bbox[1]).to.be.below(30); (0, chai_1.expect)(geometry.bbox[2]).to.be.above(10); (0, chai_1.expect)(geometry.bbox[3]).to.be.above(30); }); it('buffered tiny point', function () { var geometry = (0, utilities_1.makeGeometry)('identifier', { type: 'Point', coordinates: [10, 30], }, 'purple', 'Point Radius', Number.MIN_VALUE, 'feet'); (0, chai_1.expect)(geometry.type).to.equal('Feature'); (0, chai_1.expect)(geometry.properties.id).to.equal('identifier'); (0, chai_1.expect)(geometry.properties.color).to.equal('purple'); (0, chai_1.expect)(geometry.properties.shape).to.equal('Point Radius'); (0, chai_1.expect)(geometry.properties.buffer).to.equal(Number.MIN_VALUE); (0, chai_1.expect)(geometry.properties.bufferUnit).to.equal('feet'); (0, chai_1.expect)(geometry.geometry.type).to.equal('Point'); (0, chai_1.expect)(geometry.bbox[0]).to.equal(10); (0, chai_1.expect)(geometry.bbox[1]).to.equal(30); (0, chai_1.expect)(geometry.bbox[2]).to.equal(10); (0, chai_1.expect)(geometry.bbox[3]).to.equal(30); }); }); describe('adjustGeoCoordsForAntimeridian', function () { it('adjusts LineStrings that cross the antimeridian', function () { var geometry = (0, utilities_1.makeGeometry)('identifier', { type: 'LineString', coordinates: [ [170, 0], [-170, 0], ], }, 'purple', 'Line'); (0, utilities_1.adjustGeoCoordsForAntimeridian)(geometry); (0, chai_1.expect)(geometry.geometry.coordinates).to.deep.equal([ [170, 0], [190, 0], ]); }); it('adjusts Polygons that cross the antimeridian', function () { var geometry = (0, utilities_1.makeGeometry)('identifier', { type: 'Polygon', coordinates: [ [ [170, 0], [170, 10], [-170, 10], [-170, 0], [170, 0], ], ], }, 'purple', 'Polygon'); (0, utilities_1.adjustGeoCoordsForAntimeridian)(geometry); (0, chai_1.expect)(geometry.geometry.coordinates).to.deep.equal([ [ [170, 0], [170, 10], [190, 10], [190, 0], [170, 0], ], ]); }); }); }); //# sourceMappingURL=utilities.spec.js.map