From 65075870a0acb7f02ef9c17200387137eaba7a2c Mon Sep 17 00:00:00 2001 From: Daniel Koch Date: Thu, 13 Feb 2020 13:47:26 +0100 Subject: [PATCH] Remove pointermove event listener --- src/CoordinateInfo/CoordinateInfo.tsx | 46 +++++++-------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/src/CoordinateInfo/CoordinateInfo.tsx b/src/CoordinateInfo/CoordinateInfo.tsx index c0badb9ee7..b1e0e96b7d 100644 --- a/src/CoordinateInfo/CoordinateInfo.tsx +++ b/src/CoordinateInfo/CoordinateInfo.tsx @@ -8,6 +8,7 @@ import OlSourceImageWMS from 'ol/source/ImageWMS'; import OlSourceTileWMS from 'ol/source/TileWMS'; import OlFormatGeoJSON from 'ol/format/GeoJSON'; import OlMapBrowserEvent from 'ol/MapBrowserEvent'; +import OlFeature from 'ol/Feature'; import _cloneDeep from 'lodash/cloneDeep'; @@ -15,6 +16,7 @@ import UrlUtil from '@terrestris/base-util/dist/UrlUtil/UrlUtil'; import Logger from '@terrestris/base-util/dist/Logger'; import './CoordinateInfo.less'; +import { FeatureCollection } from 'geojson'; const format = new OlFormatGeoJSON(); @@ -42,7 +44,9 @@ interface DefaultProps { hitTolerance: number; /** - * The children component that should be rendered. + * The children component that should be rendered. The render prop function + * receives the state of the component (this is the clicked coordinate, the + * list of GFI features if any and the loading state). */ resultRenderer: (childrenProps: CoordinateInfoState) => React.ReactNode; } @@ -99,7 +103,6 @@ export class CoordinateInfo extends React.Component true, - { - layerFilter: this.layerFilter, - hitTolerance: hitTolerance - } - ); - - map.getTargetElement().style.cursor = hit ? 'pointer' : ''; - } - onMapClick(olEvt: OlMapBrowserEvent) { const { map, @@ -161,7 +139,7 @@ export class CoordinateInfo extends React.Component { + map.forEachLayerAtPixel(pixel, (layer: OlLayerBase) => { const layerSource = layer.getSource(); const featureInfoUrl = layerSource.getFeatureInfoUrl( coordinate, @@ -188,7 +166,7 @@ export class CoordinateInfo extends React.Component { + Object.keys(combinedFeatureInfoUrls).forEach((key: string) => { promises.push(fetch(combinedFeatureInfoUrls[key])); }); @@ -199,19 +177,19 @@ export class CoordinateInfo extends React.Component { + .then((responses: Response[]) => { this.setState({ clickCoordinate: coordinate }); const jsons = responses.map(response => response.json()); return Promise.all(jsons); }) - .then(featureCollections => { + .then((featureCollections: FeatureCollection[]) => { let features = {}; - featureCollections.forEach((featureCollection) => { + featureCollections.forEach((featureCollection: FeatureCollection) => { const fc = format.readFeatures(featureCollection); - fc.forEach(feature => { + fc.forEach((feature: OlFeature) => { const featureTypeName = feature.getId().split('.')[0]; if (!features[featureTypeName]) { @@ -225,7 +203,7 @@ export class CoordinateInfo extends React.Component { + .catch((error: Error) => { Logger.error(error); }) .finally(() => {