diff --git a/package-lock.json b/package-lock.json index df295f0..abfdd46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "@babel/preset-typescript": "^7.24.1", "@release-it/conventional-changelog": "^8.0.1", "@terrestris/eslint-config-typescript": "^5.0.0", - "@terrestris/ol-util": "^17.0.0", + "@terrestris/ol-util": "^18.0.0", "@testing-library/jest-dom": "^6.4.2", "@testing-library/react": "^15.0.5", "@types/jest": "^29.5.12", @@ -48,7 +48,7 @@ "watch": "^1.0.2" }, "peerDependencies": { - "@terrestris/ol-util": ">=17", + "@terrestris/ol-util": ">=18", "ol": ">=9", "ol-mapbox-style": ">=12", "react": ">=18", @@ -3673,9 +3673,9 @@ } }, "node_modules/@terrestris/ol-util": { - "version": "17.0.1", - "resolved": "https://registry.npmjs.org/@terrestris/ol-util/-/ol-util-17.0.1.tgz", - "integrity": "sha512-xnW8S/SOvG6WiQ/U+aayuMC4+7RWVS1Jy4istvqyU48nJnIYUVzo9ZES3P62A9l/gAB9DOtgVxoGmZHbSSzOOA==", + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@terrestris/ol-util/-/ol-util-18.0.0.tgz", + "integrity": "sha512-IzYcImr+SV+FB17YgedkgJkfSKX/oRt1JDVwlsayXZWrsgx2/s3lV1uxOu9dhX16DyJ0qxhRKg4LsI3UtWq96Q==", "dev": true, "dependencies": { "@mapbox/node-pre-gyp": "^1.0.11", diff --git a/package.json b/package.json index 7d6c508..3a396f6 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "@babel/preset-typescript": "^7.24.1", "@release-it/conventional-changelog": "^8.0.1", "@terrestris/eslint-config-typescript": "^5.0.0", - "@terrestris/ol-util": "^17.0.0", + "@terrestris/ol-util": "^18.0.0", "@testing-library/jest-dom": "^6.4.2", "@testing-library/react": "^15.0.5", "@types/jest": "^29.5.12", @@ -78,7 +78,7 @@ "watch": "^1.0.2" }, "peerDependencies": { - "@terrestris/ol-util": ">=17", + "@terrestris/ol-util": ">=18", "ol": ">=9", "ol-mapbox-style": ">=12", "react": ">=18", diff --git a/src/Hooks/useCoordinateInfo/useCoordinateInfo.ts b/src/Hooks/useCoordinateInfo/useCoordinateInfo.ts index 53f6e1b..bc99e09 100644 --- a/src/Hooks/useCoordinateInfo/useCoordinateInfo.ts +++ b/src/Hooks/useCoordinateInfo/useCoordinateInfo.ts @@ -1,4 +1,5 @@ import Logger from '@terrestris/base-util/dist/Logger'; +import { isWfsLayer, isWmsLayer, WfsLayer, WmsLayer } from '@terrestris/ol-util'; import _cloneDeep from 'lodash/cloneDeep'; import _groupBy from 'lodash/groupBy'; import _isNil from 'lodash/isNil'; @@ -12,7 +13,6 @@ import OlMapBrowserEvent from 'ol/MapBrowserEvent'; import { getUid } from 'ol/util'; import { useCallback, useEffect, useState } from 'react'; -import { isWfsLayer, isWmsLayer, WfsLayer, WmsLayer } from '../../Util/typeUtils'; import useMap from '../useMap/useMap'; export type FeatureMap = { diff --git a/src/Util/typeUtils.spec.tsx b/src/Util/typeUtils.spec.tsx deleted file mode 100644 index 17d85e6..0000000 --- a/src/Util/typeUtils.spec.tsx +++ /dev/null @@ -1,128 +0,0 @@ -import OlBaseLayer from 'ol/layer/Base'; -import OlGraticuleLayer from 'ol/layer/Graticule'; -import OlImageLayer from 'ol/layer/Image'; -import OlLayer from 'ol/layer/Layer'; -import OlTileLayer from 'ol/layer/Tile'; -import OlVectorLayer from 'ol/layer/Vector'; -import OlSourceCluster from 'ol/source/Cluster'; -import OlImageWMS from 'ol/source/ImageWMS'; -import OlTileWMS from 'ol/source/TileWMS'; -import OlSourceVector from 'ol/source/Vector'; -import OlSourceVectorTile from 'ol/source/VectorTile'; - -import { isWmsLayer } from './typeUtils'; - -const getWmsLikeLayers = () => { - return { - 'ol/layer/Layer': new OlLayer({}), - 'ol/layer/Image': new OlImageLayer(), - 'ol/layer/Tile': new OlTileLayer() - }; -}; - -const getWmsSources = () => { - return { - 'ol/source/ImageWMS': new OlImageWMS(), - 'ol/source/TileWMS': new OlTileWMS() - }; -}; - -const getNonWmsLikeLayers = () => { - return { - 'ol/layer/Vector': new OlVectorLayer(), - 'ol/layer/Heatmap': new OlGraticuleLayer() - }; -}; - -const getNonWmsSources = () => { - return { - 'ol/source/Vector': new OlSourceVector(), - 'ol/source/VectorTile': new OlSourceVectorTile({}), - 'ol/source/Cluster': new OlSourceCluster({}) - }; -}; - - -describe('isWmsLayer', () => { - - it('is defined', () => { - expect(isWmsLayer).not.toBeUndefined(); - }); - - it('is a function', () => { - expect(isWmsLayer).toBeInstanceOf(Function); - }); - - it('returns false for an ol base layer', () => { - const layer = new OlBaseLayer({}); - expect(isWmsLayer(layer)).toBe(false); - }); - - describe('Combinations of wms like layers with wms like sources', () => { - const layers = getWmsLikeLayers(); - const sources = getWmsSources(); - Object.keys(layers).forEach((layerClass) => { - Object.keys(sources).forEach((sourceClass) => { - const layer = layers[layerClass]; - const source = sources[sourceClass]; - layer.setSource(source); - - it(`returns true for ${layerClass} with ${sourceClass}`, () => { - expect(isWmsLayer(layer)).toBe(true); - }); - }); - }); - }); - - describe('Combinations of some non-wms like layers with some non-wms like sources', () => { - const layers = getNonWmsLikeLayers(); - const sources = getNonWmsSources(); - Object.keys(layers).forEach((layerClass) => { - Object.keys(sources).forEach((sourceClass) => { - const layer = layers[layerClass]; - const source = sources[sourceClass]; - layer.setSource(source); - - it(`returns false for ${layerClass} with ${sourceClass}`, () => { - expect(isWmsLayer(layer)).toBe(false); - }); - }); - }); - }); - - // these fail, but I fear tghey should pass… - // a ol/layer/Heatmap with ol/source/ImageWMS is not a WMS is it? - // - // describe('Combinations of some non-wms like layers with wms like sources', () => { - // const layers = getNonWmsLikeLayers(); - // const sources = getWmsSources(); - // Object.keys(layers).forEach((layerClass) => { - // Object.keys(sources).forEach((sourceClass) => { - // const layer = layers[layerClass]; - // const source = sources[sourceClass]; - // layer.setSource(source); - - // it(`returns false for ${layerClass} with ${sourceClass}`, () => { - // expect(isWmsLayer(layer)).toBe(false); - // }); - // }); - // }); - // }); - - describe('Combinations of some wms like layers with non-wms like sources', () => { - const layers = getWmsLikeLayers(); - const sources = getNonWmsSources(); - Object.keys(layers).forEach((layerClass) => { - Object.keys(sources).forEach((sourceClass) => { - const layer = layers[layerClass]; - const source = sources[sourceClass]; - layer.setSource(source); - - it(`returns false for ${layerClass} with ${sourceClass}`, () => { - expect(isWmsLayer(layer)).toBe(false); - }); - }); - }); - }); - -}); diff --git a/src/Util/typeUtils.ts b/src/Util/typeUtils.ts deleted file mode 100644 index a8bf8b0..0000000 --- a/src/Util/typeUtils.ts +++ /dev/null @@ -1,24 +0,0 @@ -import OlBaseLayer from 'ol/layer/Base'; -import OlImageLayer from 'ol/layer/Image'; -import OlLayer from 'ol/layer/Layer'; -import OlTileLayer from 'ol/layer/Tile'; -import OlVectorLayer from 'ol/layer/Vector'; -import OlImageWMS from 'ol/source/ImageWMS'; -import OlTileWMS from 'ol/source/TileWMS'; -import OlSourceVector from 'ol/source/Vector'; - -export type WmsLayer = OlImageLayer | OlTileLayer | OlLayer; - -export function isWmsLayer(layer: OlBaseLayer): layer is WmsLayer { - if (layer instanceof OlLayer) { - const source = layer.getSource(); - return source instanceof OlImageWMS || source instanceof OlTileWMS; - } - return false; -} - -export type WfsLayer = OlVectorLayer; - -export function isWfsLayer(layer: OlLayer): layer is OlVectorLayer { - return (layer instanceof OlVectorLayer && layer.getSource() instanceof OlSourceVector); -} diff --git a/src/index.ts b/src/index.ts index 27a3ad3..4f7c718 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,48 +1,21 @@ -import MapContext from './Context/MapContext/MapContext'; -import useAsyncEffect from './Hooks/useAsyncEffect/useAsyncEffect'; -import useDebouncedState from './Hooks/useDebouncedState/useDebouncedState'; -import useDraw from './Hooks/useDraw/useDraw'; -import useDropTargetMap from './Hooks/useDropTargetMap/useDropTargetMap'; -import useGeoLocation from './Hooks/useGeoLocation/useGeoLocation'; -import useMap from './Hooks/useMap/useMap'; -import useModify from './Hooks/useModify/useModify'; -import useObjectState from './Hooks/useObjectState/useObjectState'; -import useOlInteraction from './Hooks/useOlInteraction/useOlInteraction'; -import useOlLayer from './Hooks/useOlLayer/useOlLayer'; -import useOlListener from './Hooks/useOlListener/useOlListener'; -import usePermalink from './Hooks/usePermalink/usePermalink'; -import usePropOrDefault from './Hooks/usePropOrDefault/usePropOrDefault'; -import useSelectFeatures from './Hooks/useSelectFeatures/useSelectFeatures'; -import useTimeLayerAware from './Hooks/useTimeLayerAware/useTimeLayerAware'; -import ClickAwayListener from './Util/ClickAwayListener/ClickAwayListener'; -import DigitizeUtil from './Util/DigitizeUtil'; -import { InkmapPrintSpec } from './Util/InkmapTypes'; -import PrintUtil from './Util/PrintUtil'; -import { isWmsLayer, WmsLayer } from './Util/typeUtils'; -import { zoomTo } from './Util/ZoomUtil'; - -export { - ClickAwayListener, - DigitizeUtil, - InkmapPrintSpec, - isWmsLayer, - MapContext, - PrintUtil, - useAsyncEffect, - useDebouncedState, - useDraw, - useDropTargetMap, - useGeoLocation, - useMap, - useModify, - useObjectState, - useOlInteraction, - useOlLayer, - useOlListener, - usePermalink, - usePropOrDefault, - useSelectFeatures, - useTimeLayerAware, - WmsLayer, - zoomTo -}; +export { default as MapContext } from './Context/MapContext/MapContext'; +export { default as useAsyncEffect } from './Hooks/useAsyncEffect/useAsyncEffect'; +export { default as useDebouncedState } from './Hooks/useDebouncedState/useDebouncedState'; +export { default as useDraw } from './Hooks/useDraw/useDraw'; +export { default as useDropTargetMap } from './Hooks/useDropTargetMap/useDropTargetMap'; +export { default as useGeoLocation } from './Hooks/useGeoLocation/useGeoLocation'; +export { default as useMap } from './Hooks/useMap/useMap'; +export { default as useModify } from './Hooks/useModify/useModify'; +export { default as useObjectState } from './Hooks/useObjectState/useObjectState'; +export { default as useOlInteraction } from './Hooks/useOlInteraction/useOlInteraction'; +export { default as useOlLayer } from './Hooks/useOlLayer/useOlLayer'; +export { default as useOlListener } from './Hooks/useOlListener/useOlListener'; +export { default as usePermalink } from './Hooks/usePermalink/usePermalink'; +export { default as usePropOrDefault } from './Hooks/usePropOrDefault/usePropOrDefault'; +export { default as useSelectFeatures } from './Hooks/useSelectFeatures/useSelectFeatures'; +export { default as useTimeLayerAware } from './Hooks/useTimeLayerAware/useTimeLayerAware'; +export { default as ClickAwayListener } from './Util/ClickAwayListener/ClickAwayListener'; +export { default as DigitizeUtil } from './Util/DigitizeUtil'; +export { InkmapPrintSpec } from './Util/InkmapTypes'; +export { default as PrintUtil } from './Util/PrintUtil'; +export { zoomTo } from './Util/ZoomUtil';