diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..9ed118fea --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..f379f75a0 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,38 @@ +{ + "extends": [ + "eslint:recommended" + ], + "plugins": [], + "env": { + "browser": true, + "node": true + }, + "parser": "babel-eslint", + "globals": { + "Promise": false + }, + "rules": { + "indent": ["error", 2, { "SwitchCase": 1 }], + "linebreak-style": ["error", "unix"], + "quotes": ["error", "single", { "allowTemplateLiterals": true }], + "semi": ["error", "always"], + "one-var": ["error", "never"], + "no-confusing-arrow": "error", + "no-unused-vars": ["error", { + "ignoreRestSiblings": true + }], + "key-spacing": ["error", { + "beforeColon": false, + "afterColon": true + }], + "require-jsdoc": ["error", { + "require": { + "FunctionDeclaration": true, + "MethodDefinition": true, + "ClassDeclaration": true, + "ArrowFunctionExpression": true + } + }], + "space-infix-ops": ["error", {"int32Hint": false}] + } +} diff --git a/package.json b/package.json index 6662c0dba..f04068dee 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "description": "A set of helper classes for working with openLayers", "main": "src/index.js", "scripts": { + "lint": "eslint --ext js src/", + "pretest": "npm run lint", "test": "jest --maxWorkers=4", "test:watch": "jest --watchAll", "coveralls": "cat coverage/lcov.info | coveralls", @@ -48,13 +50,14 @@ "babel-preset-stage-0": "6.24.1", "canvas-prebuilt": "1.6.5-prerelease.1", "coveralls": "3.0.2", + "eslint": "5.0.1", "jest": "23.5.0", "node-pre-gyp": "0.11.0", "np": "3.0.4", - "ol": "4.6.5", + "ol": "5.1.3", "whatwg-fetch": "2.0.4" }, "peerDependencies": { - "ol": "~4.0" + "ol": "~5.0" } } diff --git a/src/AnimateUtil/AnimateUtil.js b/src/AnimateUtil/AnimateUtil.js index 57ea7fd3c..a45519f49 100644 --- a/src/AnimateUtil/AnimateUtil.js +++ b/src/AnimateUtil/AnimateUtil.js @@ -1,6 +1,6 @@ -import OlObservable from 'ol/observable'; -import OlGeomPoint from 'ol/geom/point'; -import OlGeomLineString from 'ol/geom/linestring'; +import OlGeomPoint from 'ol/geom/Point'; +import OlGeomLineString from 'ol/geom/LineString'; +import { unByKey } from 'ol/Observable'; /** * This class provides some static methods which might be helpful when working @@ -68,7 +68,7 @@ class AnimateUtil { } if (elapsed > duration || actualFrames >= expectedFrames) { - OlObservable.unByKey(listenerKey); + unByKey(listenerKey); resolve(featureToMove); } // tell OL3 to continue postcompose animation diff --git a/src/AnimateUtil/AnimateUtil.spec.js b/src/AnimateUtil/AnimateUtil.spec.js index c2a93709b..520741b18 100644 --- a/src/AnimateUtil/AnimateUtil.spec.js +++ b/src/AnimateUtil/AnimateUtil.spec.js @@ -1,7 +1,7 @@ /*eslint-env jest*/ -import OlGeomPoint from 'ol/geom/point'; -import OlFeature from 'ol/feature'; -import OlStyleStyle from 'ol/style/style'; +import OlGeomPoint from 'ol/geom/Point'; +import OlFeature from 'ol/Feature'; +import OlStyleStyle from 'ol/style/Style'; import AnimateUtil from '../AnimateUtil/AnimateUtil'; import TestUtil from '../TestUtil'; diff --git a/src/CapabilitiesUtil/CapabilitiesUtil.js b/src/CapabilitiesUtil/CapabilitiesUtil.js index 3a110a338..f1eff9f46 100644 --- a/src/CapabilitiesUtil/CapabilitiesUtil.js +++ b/src/CapabilitiesUtil/CapabilitiesUtil.js @@ -1,6 +1,6 @@ -import OlWMSCapabilities from 'ol/format/wmscapabilities'; -import OlSourceImageWMS from 'ol/source/imagewms'; -import OlLayerImage from 'ol/layer/image'; +import OlWMSCapabilities from 'ol/format/WMSCapabilities'; +import OlSourceImageWMS from 'ol/source/ImageWMS'; +import OlLayerImage from 'ol/layer/Image'; import get from 'lodash/get.js'; diff --git a/src/CapabilitiesUtil/CapabilitiesUtil.spec.js b/src/CapabilitiesUtil/CapabilitiesUtil.spec.js index a0e4f8c17..9b7f5f185 100644 --- a/src/CapabilitiesUtil/CapabilitiesUtil.spec.js +++ b/src/CapabilitiesUtil/CapabilitiesUtil.spec.js @@ -1,5 +1,5 @@ /*eslint-env jest*/ -import OlLayerImage from 'ol/layer/image'; +import OlLayerImage from 'ol/layer/Image'; import { CapabilitiesUtil } from '../index'; const layerTitle = 'OpenStreetMap WMS - by terrestris'; diff --git a/src/FeatureUtil/FeatureUtil.spec.js b/src/FeatureUtil/FeatureUtil.spec.js index 4ba0afdb9..dcdfaac62 100644 --- a/src/FeatureUtil/FeatureUtil.spec.js +++ b/src/FeatureUtil/FeatureUtil.spec.js @@ -1,7 +1,7 @@ /*eslint-env jest*/ -import OlFeature from 'ol/feature'; -import OlGeomPoint from 'ol/geom/point'; +import OlFeature from 'ol/Feature'; +import OlGeomPoint from 'ol/geom/Point'; import { FeatureUtil, diff --git a/src/FileUtil/FileUtil.js b/src/FileUtil/FileUtil.js index f155aaac1..be796e17f 100644 --- a/src/FileUtil/FileUtil.js +++ b/src/FileUtil/FileUtil.js @@ -1,6 +1,6 @@ -import OlFormatGeoJSON from 'ol/format/geojson'; -import OlLayerVector from 'ol/layer/vector'; -import OlSourceVector from 'ol/source/vector'; +import OlFormatGeoJSON from 'ol/format/GeoJSON'; +import OlLayerVector from 'ol/layer/Vector'; +import OlSourceVector from 'ol/source/Vector'; import shp from 'shpjs'; /** diff --git a/src/GeometryUtil/GeometryUtil.example.jsx b/src/GeometryUtil/GeometryUtil.example.jsx deleted file mode 100644 index 46cc87a1f..000000000 --- a/src/GeometryUtil/GeometryUtil.example.jsx +++ /dev/null @@ -1,190 +0,0 @@ -import React from 'react'; -import { render } from 'react-dom'; - -import OlMap from 'ol/map'; -import OlView from 'ol/view'; -import OlLayerTile from 'ol/layer/tile'; -import OlSourceOsm from 'ol/source/osm'; -import olProj from 'ol/proj'; - -import { message } from 'antd'; - -import { - DigitizeButton, - GeometryUtil, - MapUtil, - SimpleButton, - ToggleGroup -} from '../../index.js'; - - -// ***************************** SETUP ***************************************** -// -const map = new OlMap({ - layers: [ - new OlLayerTile({ - name: 'OSM', - source: new OlSourceOsm() - }) - ], - view: new OlView({ - center: olProj.fromLonLat([37.40570, 8.81566]), - zoom: 4 - }) -}); - -// -// ***************************** SETUP END ************************************* -// - -/** - * - */ -const clearDrawFeatures = () => { - const drawLayer = MapUtil.getLayerByName(map, 'drawLayer'); - drawLayer.getSource().clear(); -}; - -/** - * - */ -const clearOperationFeatures = () => { - window.setTimeout(() => { - const utilLayer = MapUtil.getLayerByName(map, 'utilLayer'); - utilLayer.getSource().clear(); - }, 10); -}; - -render( -
-
- -
- Drawing: - - - Draw polygon - - { - const drawLayer = MapUtil.getLayerByName(map, 'drawLayer'); - const source = drawLayer.getSource(); - const features = drawLayer.getSource().getFeatures(); - if (features.length !== 1) { - message.warn('Example only supports one feature!!'); - } - const line = evt.feature; - const splitFeatures = GeometryUtil.splitByLine(features[0], line); - clearDrawFeatures(); - clearOperationFeatures(); - source.addFeatures(splitFeatures); - }} - > - Split by Line - - { - const drawLayer = MapUtil.getLayerByName(map, 'drawLayer'); - const source = drawLayer.getSource(); - const features = source.getFeatures(); - if (features.length !== 1) { - message.warn('Example only supports one feature!!'); - } - const polygon = evt.feature; - const unionFeature = GeometryUtil.union([features[0], polygon]); - clearDrawFeatures(); - clearOperationFeatures(); - source.addFeature(unionFeature); - }} - > - Union - - { - const drawLayer = MapUtil.getLayerByName(map, 'drawLayer'); - const source = drawLayer.getSource(); - const features = source.getFeatures(); - if (features.length !== 1) { - message.warn('Example only supports one feature!!'); - } - const polygon = evt.feature; - const intersectionFeature = GeometryUtil.intersection(features[0], polygon); - clearDrawFeatures(); - clearOperationFeatures(); - source.addFeature(intersectionFeature); - }} - > - Intersection - - { - const drawLayer = MapUtil.getLayerByName(map, 'drawLayer'); - const source = drawLayer.getSource(); - const features = source.getFeatures(); - if (features.length !== 1) { - message.warn('Example only supports one feature!!'); - } - const polygon = evt.feature; - const differenceFeature = GeometryUtil.difference(features[0], polygon); - clearDrawFeatures(); - clearOperationFeatures(); - source.addFeature(differenceFeature); - }} - > - Difference - - -
-
- { - const drawLayer = MapUtil.getLayerByName(map, 'drawLayer'); - const source = drawLayer.getSource(); - const features = source.getFeatures(); - if (features.length !== 1) { - message.warn('Example only supports one feature!!'); - } - const bufferedFeature = GeometryUtil.addBuffer(features[0], 100000); - clearDrawFeatures(); - clearOperationFeatures(); - source.addFeature(bufferedFeature); - }} - > - Add Buffer (100 km) - -
-
, - - // Target - document.getElementById('exampleContainer'), - - // Callback - () => { - map.setTarget('map'); - } -); diff --git a/src/GeometryUtil/GeometryUtil.example.md b/src/GeometryUtil/GeometryUtil.example.md deleted file mode 100644 index e78f5c74d..000000000 --- a/src/GeometryUtil/GeometryUtil.example.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -layout: basic.hbs -title: GeometryUtil example -description: This is an example demonstrating the GeometryUtil Features. -collection: Examples ---- - -This demonstrates the GeometryUtil Features. diff --git a/src/GeometryUtil/GeometryUtil.js b/src/GeometryUtil/GeometryUtil.js index d16a3fa3c..01d0355a9 100644 --- a/src/GeometryUtil/GeometryUtil.js +++ b/src/GeometryUtil/GeometryUtil.js @@ -1,8 +1,8 @@ -import OlFeature from 'ol/feature'; -import OlGeomMultiPolygon from 'ol/geom/multipolygon'; -import OlGeomMultiPoint from 'ol/geom/multipoint'; -import OlGeomMultiLineString from 'ol/geom/multilinestring'; -import OlFormatGeoJSON from 'ol/format/geojson'; +import OlFeature from 'ol/Feature'; +import OlGeomMultiPolygon from 'ol/geom/MultiPolygon'; +import OlGeomMultiPoint from 'ol/geom/MultiPoint'; +import OlGeomMultiLineString from 'ol/geom/MultiLineString'; +import OlFormatGeoJSON from 'ol/format/GeoJSON'; import buffer from '@turf/buffer'; import difference from '@turf/difference'; @@ -61,7 +61,7 @@ class GeometryUtil { const turfLine = geoJsonFormat.writeFeatureObject(lineFeat); // This lists all the polygons in the feature and splits the Multi polygons into an array of polygons. const geometries = GeometryUtil.separateGeometries(polygonFeat.getGeometry()); - // the array containing all the split features + // the array containing all the split features let allSplitedPolygons = []; // iterates over each polygon and splits it geometries.forEach(geometry => { @@ -78,7 +78,7 @@ class GeometryUtil { turfPolygonCoordinates.slice(1, turfPolygonCoordinates.length).forEach(function (coord) { inners.push(lineString(coord)); }); - // Polygonize the holes in the polygon + // Polygonize the holes in the polygon const innerPolygon = polygonize(featureCollection(inners)); // make a lineString from the spliting line and the outer of the polygon let unionGeom = union(outer, turfLine); @@ -86,10 +86,10 @@ class GeometryUtil { const polygonizedUnionGeom = polygonize(unionGeom); // Array of the split polygons within the geometry const splitedPolygons = []; - // Iterate over each feature in the combined feature and remove sections that are outside the initial polygon and + // Iterate over each feature in the combined feature and remove sections that are outside the initial polygon and // remove the parts from the cutted polygons that are in polygon holes. featureEach(polygonizedUnionGeom, cuttedSection => { - // checks to see if segment is in polygon + // checks to see if segment is in polygon const segmentInPolygon = intersect(cuttedSection, outerPolygon); if (segmentInPolygon && segmentInPolygon.geometry.type === 'Polygon') { let polygonWithoutHoles = []; @@ -194,15 +194,15 @@ class GeometryUtil { let append; switch (geomType) { case 'Polygon': - multiGeom = new OlGeomMultiPolygon(); + multiGeom = new OlGeomMultiPolygon([]); append = multiGeom.appendPolygon.bind(multiGeom); break; case 'Point': - multiGeom = new OlGeomMultiPoint(); + multiGeom = new OlGeomMultiPoint([]); append = multiGeom.appendPoint.bind(multiGeom); break; case 'LineString': - multiGeom = new OlGeomMultiLineString(); + multiGeom = new OlGeomMultiLineString([]); append = multiGeom.appendLineString.bind(multiGeom); break; default: diff --git a/src/GeometryUtil/GeometryUtil.spec.js b/src/GeometryUtil/GeometryUtil.spec.js index 194652222..a772e7d3d 100644 --- a/src/GeometryUtil/GeometryUtil.spec.js +++ b/src/GeometryUtil/GeometryUtil.spec.js @@ -1,14 +1,14 @@ /*eslint-env jest*/ -import OlFormatGeoJSON from 'ol/format/geojson'; -import OlFeature from 'ol/feature'; -import OlGeomGeometry from 'ol/geom/geometry'; -import OlGeomPolygon from 'ol/geom/polygon'; -import OlGeomMultiPolygon from 'ol/geom/multipolygon'; -import OlGeomPoint from 'ol/geom/point'; -import OlGeomMultiPoint from 'ol/geom/multipoint'; -import OlGeomLineString from 'ol/geom/linestring'; -import OlGeomMultiLineString from 'ol/geom/multilinestring'; +import OlFormatGeoJSON from 'ol/format/GeoJSON'; +import OlFeature from 'ol/Feature'; +import OlGeomGeometry from 'ol/geom/Geometry'; +import OlGeomPolygon from 'ol/geom/Polygon'; +import OlGeomMultiPolygon from 'ol/geom/MultiPolygon'; +import OlGeomPoint from 'ol/geom/Point'; +import OlGeomMultiPoint from 'ol/geom/MultiPoint'; +import OlGeomLineString from 'ol/geom/LineString'; +import OlGeomMultiLineString from 'ol/geom/MultiLineString'; import { GeometryUtil, @@ -168,7 +168,7 @@ describe('GeometryUtil', () => { ]; expect(format.writeFeatures(got)).toEqual(format.writeFeatures(exp)); }); - + /** * +-------------------+ * | | @@ -212,7 +212,7 @@ describe('GeometryUtil', () => { }); }); }); - }); + }); describe('with ol.geom.Geometry as params', () => { /** * + @@ -357,6 +357,7 @@ describe('GeometryUtil', () => { it('can split a single ol.geom.MultiPoint into an array of ol.geom.Points', () => { const testPoint1 = new OlGeomPoint(pointCoords); const testPoint2 = new OlGeomPoint(pointCoords2); + const mergedPoint = GeometryUtil.mergeGeometries([testPoint1, testPoint2]); const separatedPoints = GeometryUtil.separateGeometries(mergedPoint); expect(Array.isArray(separatedPoints)).toBe(true); diff --git a/src/MapUtil/MapUtil.js b/src/MapUtil/MapUtil.js index f03d20a11..63d5bb119 100644 --- a/src/MapUtil/MapUtil.js +++ b/src/MapUtil/MapUtil.js @@ -1,15 +1,15 @@ -import OlMap from 'ol/map'; -import OlProjection from 'ol/proj'; -import OlSourceTileWMS from 'ol/source/tilewms'; -import OlLayerTile from 'ol/layer/tile'; -import OlLayerGroup from 'ol/layer/group'; -import OlLayerBase from 'ol/layer/base'; +import OlMap from 'ol/Map'; +import OlSourceTileWMS from 'ol/source/TileWMS'; +import OlLayerTile from 'ol/layer/Tile'; +import OlLayerGroup from 'ol/layer/Group'; +import OlLayerBase from 'ol/layer/Base'; +import { METERS_PER_UNIT } from 'ol/proj/Units'; -import FeatureUtil from '../FeatureUtil/FeatureUtil'; import { UrlUtil } from '@terrestris/base-util'; - import { Logger } from '@terrestris/base-util'; +import FeatureUtil from '../FeatureUtil/FeatureUtil'; + /** * Helper Class for the ol3 map. * @@ -84,7 +84,7 @@ export class MapUtil { */ static getResolutionForScale (scale, units) { let dpi = 25.4 / 0.28; - let mpu = OlProjection.METERS_PER_UNIT[units]; + let mpu = METERS_PER_UNIT[units]; let inchesPerMeter = 39.37; return parseFloat(scale) / (mpu * inchesPerMeter * dpi); @@ -101,7 +101,7 @@ export class MapUtil { */ static getScaleForResolution (resolution, units) { var dpi = 25.4 / 0.28; - var mpu = OlProjection.METERS_PER_UNIT[units]; + var mpu = METERS_PER_UNIT[units]; var inchesPerMeter = 39.37; return parseFloat(resolution) * mpu * inchesPerMeter * dpi; diff --git a/src/MapUtil/MapUtil.spec.js b/src/MapUtil/MapUtil.spec.js index 2d3906b73..128f14f55 100644 --- a/src/MapUtil/MapUtil.spec.js +++ b/src/MapUtil/MapUtil.spec.js @@ -1,19 +1,20 @@ /*eslint-env jest*/ -import OlInteractionDragRotateAndZoom from 'ol/interaction/dragrotateandzoom'; -import OlInteractionDraw from 'ol/interaction/draw'; -import OlLayerTile from 'ol/layer/tile'; -import OlSourceTileWMS from 'ol/source/tilewms'; -import OlSourceTileJson from 'ol/source/tilejson'; -import OlFeature from 'ol/feature'; -import OlGeomPoint from 'ol/geom/point'; -import OlLayerGroup from 'ol/layer/group'; -import OlMap from 'ol/map'; -import OlView from 'ol/view'; +import OlInteractionDragRotateAndZoom from 'ol/interaction/DragRotateAndZoom'; +import OlInteractionDraw from 'ol/interaction/Draw'; +import OlLayerTile from 'ol/layer/Tile'; +import OlSourceTileWMS from 'ol/source/TileWMS'; +import OlSourceTileJson from 'ol/source/TileJSON'; +import OlFeature from 'ol/Feature'; +import OlGeomPoint from 'ol/geom/Point'; +import OlLayerGroup from 'ol/layer/Group'; +import OlMap from 'ol/Map'; +import OlView from 'ol/View'; + +import { Logger } from '@terrestris/base-util'; import TestUtil from '../TestUtil'; -import { Logger } from '@terrestris/base-util'; import { MapUtil, } from '../index'; diff --git a/src/MeasureUtil/MeasureUtil.js b/src/MeasureUtil/MeasureUtil.js index e89bedf60..d69a0035a 100644 --- a/src/MeasureUtil/MeasureUtil.js +++ b/src/MeasureUtil/MeasureUtil.js @@ -1,5 +1,5 @@ -import OlSphere from 'ol/sphere'; -import OlProj from 'ol/proj'; + +import { getLength, getArea } from 'ol/sphere'; /** * This class provides some static methods which might be helpful when working @@ -15,27 +15,21 @@ class MeasureUtil { * @param {OlGeomLineString} line The drawn line. * @param {OlMap} map An OlMap. * @param {Boolean} geodesic Is the measurement geodesic (default is true). + * @param {Number} radius Sphere radius. By default, the radius of the earth + * is used (Clarke 1866 Authalic Sphere, 6371008.8). * - * @return {number} The length of line in meters. + * @return {Number} The length of line in meters. */ - static getLength(line, map, geodesic = true) { - let length; + static getLength(line, map, geodesic = true, radius = 6371008.8) { if (geodesic) { - const wgs84Sphere = new OlSphere(6378137); - const coordinates = line.getCoordinates(); - length = 0; - const sourceProj = map.getView().getProjection(); - for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { - const c1 = OlProj.transform( - coordinates[i], sourceProj, 'EPSG:4326'); - const c2 = OlProj.transform( - coordinates[i + 1], sourceProj, 'EPSG:4326'); - length += wgs84Sphere.haversineDistance(c1, c2); - } + const opts = { + projection: map.getView().getProjection().getCode(), + radius + }; + return getLength(line, opts); } else { - length = Math.round(line.getLength() * 100) / 100; + return Math.round(line.getLength() * 100) / 100; } - return length; } /** @@ -69,22 +63,21 @@ class MeasureUtil { * @param {OlGeomPolygon} polygon The drawn polygon. * @param {OlMap} map An OlMap. * @param {Boolean} geodesic Is the measurement geodesic (default is true). + * @param {Number} radius Sphere radius. By default, the radius of the earth + * is used (Clarke 1866 Authalic Sphere, 6371008.8). * - * @return {String} The area of the polygon in square meter. + * @return {Number} The area of the polygon in square meter. */ - static getArea(polygon, map, geodesic = true) { - let area; + static getArea(polygon, map, geodesic = true, radius = 6371008.8) { if (geodesic) { - const wgs84Sphere = new OlSphere(6378137); - const sourceProj = map.getView().getProjection(); - const geom = (polygon.clone().transform( - sourceProj, 'EPSG:4326')); - const coordinates = geom.getLinearRing(0).getCoordinates(); - area = Math.abs(wgs84Sphere.geodesicArea(coordinates)); + const opts = { + projection: map.getView().getProjection().getCode(), + radius + }; + return getArea(polygon, opts); } else { - area = polygon.getArea(); + return polygon.getArea(); } - return area; } /** diff --git a/src/MeasureUtil/MeasureUtil.spec.js b/src/MeasureUtil/MeasureUtil.spec.js index ea30dd60c..2aae8cf5d 100644 --- a/src/MeasureUtil/MeasureUtil.spec.js +++ b/src/MeasureUtil/MeasureUtil.spec.js @@ -1,7 +1,7 @@ /*eslint-env jest*/ -import OlGeomLineString from 'ol/geom/linestring'; -import OlGeomPolygon from 'ol/geom/polygon'; +import OlGeomLineString from 'ol/geom/LineString'; +import OlGeomPolygon from 'ol/geom/Polygon'; import { MeasureUtil, @@ -38,8 +38,8 @@ describe('MeasureUtil', () => { const expectedShortLength = MeasureUtil.getLength(shortLine, map); const expectedLongLength = MeasureUtil.getLength(longLine, map); - expect(expectedShortLength).toEqual(99.99999999669033); - expect(expectedLongLength).toEqual(100545.83533277796); + expect(expectedShortLength).toEqual(99.88824008937313); + expect(expectedLongLength).toEqual(100433.46540039503); TestUtil.removeMap(map); }); @@ -62,8 +62,8 @@ describe('MeasureUtil', () => { const expectedShortLength = MeasureUtil.formatLength(shortLine, map, 2); const expectedLongLength = MeasureUtil.formatLength(longLine, map, 2); - expect(expectedShortLength).toBe('100 m'); - expect(expectedLongLength).toBe('100.55 km'); + expect(expectedShortLength).toBe('99.89 m'); + expect(expectedLongLength).toBe('100.43 km'); TestUtil.removeMap(map); }); @@ -91,8 +91,8 @@ describe('MeasureUtil', () => { const expectedSmallArea = MeasureUtil.getArea(smallPoly, map); const expectedBigArea = MeasureUtil.getArea(bigPoly, map); - expect(expectedSmallArea).toBe(99.99999999454045); - expect(expectedBigArea).toBe(999999.9918059125); + expect(expectedSmallArea).toBe(99.7766050826797); + expect(expectedBigArea).toBe(997766.042705488); TestUtil.removeMap(map); }); @@ -120,7 +120,7 @@ describe('MeasureUtil', () => { const expectedSmallArea = MeasureUtil.formatArea(smallPoly, map, 2); const expectedBigArea = MeasureUtil.formatArea(bigPoly, map, 2); - expect(expectedSmallArea).toBe('100 m2'); + expect(expectedSmallArea).toBe('99.78 m2'); expect(expectedBigArea).toBe('1 km2'); TestUtil.removeMap(map); diff --git a/src/ProjectionUtil/ProjectionUtil.js b/src/ProjectionUtil/ProjectionUtil.js index df850fd5a..2aa8ff6a5 100644 --- a/src/ProjectionUtil/ProjectionUtil.js +++ b/src/ProjectionUtil/ProjectionUtil.js @@ -1,5 +1,5 @@ import proj4 from 'proj4'; -import OlProjection from 'ol/proj'; +import { register } from 'ol/proj/proj4'; /** * Helper class for ol/proj4 projection handling. @@ -17,7 +17,7 @@ export class ProjectionUtil { for (let [projCode, projDefinition] of Object.entries(proj4CrsDefinitions)) { proj4.defs(projCode, projDefinition); } - OlProjection.setProj4(proj4); + register(proj4); } /** diff --git a/src/ProjectionUtil/ProjectionUtil.spec.js b/src/ProjectionUtil/ProjectionUtil.spec.js index 8822af7f8..a31760321 100644 --- a/src/ProjectionUtil/ProjectionUtil.spec.js +++ b/src/ProjectionUtil/ProjectionUtil.spec.js @@ -1,6 +1,6 @@ /*eslint-env jest*/ import proj4 from 'proj4'; -import OlProjection from 'ol/proj'; +import * as OlProj4 from 'ol/proj/proj4'; import ProjectionUtil from './ProjectionUtil.js'; @@ -27,18 +27,15 @@ describe('ProjectionUtil', () => { expect(ProjectionUtil.initProj4Definitions).not.toBeUndefined(); }); it('it registers the given CRS definitions in proj4 and ol', () => { + OlProj4.register = jest.fn(); const proj4Spy = jest.spyOn(proj4, 'defs'); - const olSpy = jest.spyOn(OlProjection, 'setProj4'); ProjectionUtil.initProj4Definitions(testCrsDefinition); expect(proj4Spy).toHaveBeenCalled(); - expect(olSpy).toHaveBeenCalled(); + expect(OlProj4.register).toHaveBeenCalled(); proj4Spy.mockReset(); proj4Spy.mockRestore(); - olSpy.mockReset(); - olSpy.mockRestore(); - }); }); diff --git a/src/TestUtil.js b/src/TestUtil.js index 53b9953a7..fa86edbdb 100644 --- a/src/TestUtil.js +++ b/src/TestUtil.js @@ -1,11 +1,11 @@ -import OlView from 'ol/view'; -import OlMap from 'ol/map'; -import OlSourceVector from 'ol/source/vector'; -import OlLayerVector from 'ol/layer/vector'; -import OlFeature from 'ol/feature'; -import OlGeomPoint from 'ol/geom/point'; -import OlPointerPointerEvent from 'ol/pointer/pointerevent'; -import OlMapBrowserPointerEvent from 'ol/mapbrowserpointerevent'; +import OlView from 'ol/View'; +import OlMap from 'ol/Map'; +import OlSourceVector from 'ol/source/Vector'; +import OlLayerVector from 'ol/layer/Vector'; +import OlFeature from 'ol/Feature'; +import OlGeomPoint from 'ol/geom/Point'; +import OlPointerPointerEvent from 'ol/pointer/PointerEvent'; +import OlMapBrowserPointerEvent from 'ol/MapBrowserPointerEvent'; /** * A set of some useful static helper methods. diff --git a/src/WfsFilterUtil/WfsFilterUtil.js b/src/WfsFilterUtil/WfsFilterUtil.js index 694296fbf..1438f3172 100644 --- a/src/WfsFilterUtil/WfsFilterUtil.js +++ b/src/WfsFilterUtil/WfsFilterUtil.js @@ -1,4 +1,8 @@ -import OlFormatFilter from 'ol/format/filter'; +import { + equalTo, + like, + or +} from 'ol/format/filter'; /** * Helper Class for building filters to be used with WFS GetFeature requests. @@ -39,17 +43,17 @@ class WfsFilterUtil { return undefined; } if (details[attribute].exactSearch) { - return OlFormatFilter.equalTo(attribute, searchTerm, details[attribute].exactSearch); + return equalTo(attribute, searchTerm, details[attribute].exactSearch); } else { - return OlFormatFilter.like(attribute, `*${searchTerm}*`, '*', '.', '!', details[attribute].matchCase || false); + return like(attribute, `*${searchTerm}*`, '*', '.', '!', details[attribute].matchCase || false); } } else { - return OlFormatFilter.like(attribute, `*${searchTerm}*`, '*', '.', '!', false); + return like(attribute, `*${searchTerm}*`, '*', '.', '!', false); } }) .filter(filter => filter !== undefined); if (attributes.length > 1 && Object.keys(propertyFilters).length > 1) { - return OlFormatFilter.or(...propertyFilters); + return or(...propertyFilters); } else { return propertyFilters[0]; } diff --git a/src/index.js b/src/index.js index e900a6c6b..3949139b4 100644 --- a/src/index.js +++ b/src/index.js @@ -9,13 +9,13 @@ import ProjectionUtil from './ProjectionUtil/ProjectionUtil'; import WfsFilterUtil from './WfsFilterUtil/WfsFilterUtil'; export { - AnimateUtil, - CapabilitiesUtil, - FeatureUtil, - FileUtil, - GeometryUtil, - MapUtil, - MeasureUtil, - ProjectionUtil, - WfsFilterUtil + AnimateUtil, + CapabilitiesUtil, + FeatureUtil, + FileUtil, + GeometryUtil, + MapUtil, + MeasureUtil, + ProjectionUtil, + WfsFilterUtil }; \ No newline at end of file