Skip to content

Commit

Permalink
fix: enable noImplicitAny
Browse files Browse the repository at this point in the history
  • Loading branch information
simonseyock committed Mar 14, 2022
1 parent b6b5587 commit d18624e
Show file tree
Hide file tree
Showing 24 changed files with 267 additions and 239 deletions.
20 changes: 16 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"@fortawesome/react-fontawesome": "^0.1.17",
"@terrestris/base-util": "^1.0.1",
"@terrestris/ol-util": "^5.1.0",
"@terrestris/ol-util": "^6.0.0",
"@types/geojson": "^7946.0.8",
"@types/lodash": "^4.14.179",
"@types/moment": "^2.13.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Button/CopyButton/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const CopyButton: React.FC<CopyButtonProps> = ({

const feat = event.selected[0];

if (!feat || !layers) {
if (!feat || !layers || !map) {
return;
}

Expand Down
68 changes: 31 additions & 37 deletions src/Button/DigitizeButton/DigitizeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import OlStyleFill from 'ol/style/Fill';
import OlStyleCircle from 'ol/style/Circle';
import OlStyleText from 'ol/style/Text';
import OlInteractionDraw, { createBox, DrawEvent as OlDrawEvent} from 'ol/interaction/Draw';
import OlInteractionSelect from 'ol/interaction/Select';
import OlInteractionModify from 'ol/interaction/Modify';
import OlInteractionTranslate from 'ol/interaction/Translate';
import OlInteractionSelect, { SelectEvent as OlSelectEvent } from 'ol/interaction/Select';
import OlInteractionModify, { ModifyEvent as OlModifyEvent } from 'ol/interaction/Modify';
import OlInteractionTranslate, { TranslateEvent as OlTranslateEvent } from 'ol/interaction/Translate';
import OlFeature from 'ol/Feature';
import * as OlEventConditions from 'ol/events/condition';
import OlGeometry from 'ol/geom/Geometry';
import OlMapBrowserEvent from 'ol/MapBrowserEvent';

import _isFunction from 'lodash/isFunction';
import _isArray from 'lodash/isArray';
Expand All @@ -30,6 +31,7 @@ import AnimateUtil from '@terrestris/ol-util/dist/AnimateUtil/AnimateUtil';
import Logger from '@terrestris/base-util/dist/Logger';

import { CSS_PREFIX } from '../../constants';
import { ChangeEvent } from 'react';

interface DefaultProps {
/**
Expand Down Expand Up @@ -524,7 +526,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
map
} = this.props;

let digitizeLayer = MapUtil.getLayerByName(map, digitizeLayerName);
let digitizeLayer = digitizeLayerName ? MapUtil.getLayerByName(map, digitizeLayerName) : null;

if (!digitizeLayer) {
digitizeLayer = new OlLayerVector({
Expand Down Expand Up @@ -552,20 +554,21 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
* @param feature The feature which is being styled.
* @return The style to use.
*/
digitizeStyleFunction = feature => {
digitizeStyleFunction = (feature: OlFeature<OlGeometry>) => {
const {
drawStyle,
} = this.props;

if (!feature.getGeometry()) {
return null;
const geometry = feature.getGeometry();
if (!geometry) {
return undefined;
}

if (drawStyle) {
return _isFunction(drawStyle) ? drawStyle(feature) : drawStyle;
}

switch (feature.getGeometry().getType()) {
switch (geometry.getType()) {
case DigitizeButton.POINT_DRAW_TYPE: {
if (!feature.get('isLabel')) {
return new OlStyleStyle({
Expand Down Expand Up @@ -617,7 +620,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
});
}
default:
return null;
return undefined;
}
};

Expand Down Expand Up @@ -690,9 +693,6 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
/**
* Creates a correctly configured OL draw interaction depending on given
* drawType and adds this to the map.
*
* @param pressed Whether the digitize button is pressed or not.
* Will be used to handle active state of the draw interaction.
*/
createDrawInteraction = () => {
const {
Expand All @@ -708,7 +708,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
}

const drawInteractionName = `react-geo-draw-interaction-${drawType}`;
let drawInteraction = MapUtil.getInteractionsByName(map, drawInteractionName)[0];
let drawInteraction = MapUtil.getInteractionsByName(map, drawInteractionName)[0] as OlInteractionDraw;

if (!drawInteraction) {
let type = drawType;
Expand All @@ -735,18 +735,12 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
drawInteraction.on('drawend', this.handleTextAdding);
}

drawInteraction.on('drawend', (evt) => {
const onDrawEnd = this.getOnDrawEnd();
if (onDrawEnd) {
onDrawEnd(evt);
}
drawInteraction.on('drawend', (evt: OlDrawEvent) => {
this.getOnDrawEnd()?.(evt);
});

drawInteraction.on('drawstart', (evt) => {
const onDrawStart = this.getOnDrawStart();
if (onDrawStart) {
onDrawStart(evt);
}
drawInteraction.on('drawstart', (evt: OlDrawEvent) => {
this.getOnDrawStart()?.(evt);
});

drawInteraction.setActive(false);
Expand Down Expand Up @@ -774,7 +768,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
}

const selectInteractionName = `react-geo-select-interaction-${editType}`;
let selectInteraction: OlInteractionSelect = MapUtil.getInteractionsByName(map, selectInteractionName)[0];
let selectInteraction = MapUtil.getInteractionsByName(map, selectInteractionName)[0] as OlInteractionSelect;

if (!selectInteraction) {
selectInteraction = new OlInteractionSelect({
Expand Down Expand Up @@ -819,7 +813,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
}

const modifyInteractionName = `react-geo-modify-interaction-${editType}`;
let modifyInteraction = MapUtil.getInteractionsByName(map, modifyInteractionName)[0];
let modifyInteraction = MapUtil.getInteractionsByName(map, modifyInteractionName)[0] as OlInteractionModify;

if (!modifyInteraction) {
modifyInteraction = new OlInteractionModify({
Expand Down Expand Up @@ -857,7 +851,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
}

const translateInteractionName = `react-geo-translate-interaction-${editType}`;
let translateInteraction = MapUtil.getInteractionsByName(map, translateInteractionName)[0];
let translateInteraction = MapUtil.getInteractionsByName(map, translateInteractionName)[0] as OlInteractionTranslate;

if (!translateInteraction) {
translateInteraction = new OlInteractionTranslate({
Expand Down Expand Up @@ -885,7 +879,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
*
* @param evt The interaction event.
*/
onFeatureRemove = evt => {
onFeatureRemove = (evt: OlSelectEvent) => {
const {
onFeatureRemove,
onFeatureSelect
Expand Down Expand Up @@ -919,7 +913,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
*
* @param evt The interaction event.
*/
onFeatureCopy = evt => {
onFeatureCopy = (evt: OlSelectEvent) => {
const {
map,
onFeatureCopy,
Expand All @@ -928,7 +922,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton

const feat = evt.selected[0];

if (!feat || !this._digitizeFeatures) {
if (!feat || !this._digitizeFeatures || !this._digitizeLayer) {
return;
}

Expand Down Expand Up @@ -962,7 +956,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
*
* @param evt The interaction event.
*/
onModifyStart = evt => {
onModifyStart = (evt: OlModifyEvent) => {
const {
onModifyStart
} = this.props;
Expand All @@ -971,7 +965,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
onModifyStart(evt);
}

const feature = evt.features.getArray()[0];
const feature = evt.features.getArray()[0] as OlFeature<OlGeometry>;

if (feature.get('isLabel')) {
this._digitizeTextFeature = feature;
Expand All @@ -997,7 +991,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
*
* @param evt The interaction event.
*/
onModifyEnd = evt => {
onModifyEnd = (evt: OlModifyEvent) => {
const {
onModifyEnd
} = this.props;
Expand All @@ -1012,7 +1006,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
*
* @param evt The interaction event.
*/
onTranslateStart = evt => {
onTranslateStart = (evt: OlTranslateEvent) => {
const {
onTranslateStart
} = this.props;
Expand All @@ -1027,7 +1021,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
*
* @param evt The interaction event.
*/
onTranslateEnd = evt => {
onTranslateEnd = (evt: OlTranslateEvent) => {
const {
onTranslateEnd
} = this.props;
Expand All @@ -1042,7 +1036,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
*
* @param evt The interaction event.
*/
onTranslating = evt => {
onTranslating = (evt: OlTranslateEvent) => {
const {
onTranslating
} = this.props;
Expand Down Expand Up @@ -1146,7 +1140,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
* @param evt Input event containing new text value to be set as
* textLabel.
*/
onLabelChange = evt => {
onLabelChange = (evt: ChangeEvent<HTMLTextAreaElement>) => {
this.setState({
textLabel: evt.target.value
});
Expand All @@ -1158,7 +1152,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
*
* @param evt The `pointermove` event.
*/
onPointerMove = evt => {
onPointerMove = (evt: OlMapBrowserEvent<PointerEvent>) => {
if (evt.dragging) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Button/DrawButton/DrawButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { CSS_PREFIX } from '../../constants';
import { useMap } from '../../Hook/useMap';
import { DigitizeUtil } from '../../Util/DigitizeUtil';
import { FeatureLabelModal } from '../../FeatureLabelModal/FeatureLabelModal';
import { EventsKey } from 'ol/events';

type DrawType = 'Point' | 'LineString' | 'Polygon' | 'Circle' | 'Rectangle' | 'Text';

Expand Down Expand Up @@ -165,7 +166,7 @@ const DrawButton: React.FC<DrawButtonProps> = ({

setDrawInteraction(newInteraction);

let key;
let key: EventsKey;

if (drawType === 'Text') {
key = newInteraction.on('drawend', evt => {
Expand Down
12 changes: 5 additions & 7 deletions src/Button/GeoLocationButton/GeoLocationButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,30 +273,28 @@ class GeoLocationButton extends React.Component<GeoLocationButtonProps> {

// recenters the view by putting the given coordinates at 3/4 from the top or
// the screen
getCenterWithHeading = (position, rotation, resolution) => {
getCenterWithHeading = (position: [number, number], rotation: number, resolution: number) => {
const size = this.props.map.getSize() ?? [0, 0];
const height = size[1];

return [
position[0] - Math.sin(rotation) * height * resolution * 1 / 4,
position[1] + Math.cos(rotation) * height * resolution * 1 / 4
position[0] - Math.sin(rotation) * height * resolution / 4,
position[1] + Math.cos(rotation) * height * resolution / 4
];
};

updateView = () => {
const view = this.props.map.getView();
const deltaMean = 500; // the geolocation sampling period mean in ms
let previousM = 0;
// use sampling period to get a smooth transition
let m = Date.now() - deltaMean * 1.5;
m = Math.max(m, previousM);
m = Math.max(m, 0);

previousM = m;
// interpolate position along positions LineString
const c = this._positions.getCoordinateAtM(m, true);
if (c) {
if (this.props.follow) {
view.setCenter(this.getCenterWithHeading(c, -c[2], view.getResolution()));
view.setCenter(this.getCenterWithHeading([c[0], c[1]], -c[2], view.getResolution() ?? 0));
view.setRotation(-c[2]);
}
if (this.props.showMarker) {
Expand Down
14 changes: 7 additions & 7 deletions src/Button/MeasureButton/MeasureButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,8 @@ class MeasureButton extends React.Component<MeasureButtonProps> {

/**
* Called if the current geometry of the draw interaction has changed.
*
* @param evt The generic change event.
*/
onDrawInteractionGeometryChange(/* evt*/) {
onDrawInteractionGeometryChange() {
this.updateMeasureTooltip();
}

Expand Down Expand Up @@ -608,8 +606,8 @@ class MeasureButton extends React.Component<MeasureButtonProps> {
}

const value = measureType === 'line' ?
MeasureUtil.formatLength(geom, map, decimalPlacesInTooltips, geodesic) :
MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic);
MeasureUtil.formatLength(geom as OlGeomLineString, map, decimalPlacesInTooltips, geodesic) :
MeasureUtil.formatArea(geom as OlGeomPolygon, map, decimalPlacesInTooltips, geodesic);

if (parseInt(value, 10) > 0) {
const div = document.createElement('div');
Expand Down Expand Up @@ -843,13 +841,15 @@ class MeasureButton extends React.Component<MeasureButtonProps> {
if (measureType === 'line') {
output = MeasureUtil.formatLength(geom, map, decimalPlacesInTooltips, geodesic);
} else if (measureType === 'angle') {
output = MeasureUtil.formatAngle(geom, map, decimalPlacesInTooltips);
output = MeasureUtil.formatAngle(geom, 0);
}
} else {
return;
}

this._measureTooltipElement.innerHTML = output;
if (output) {
this._measureTooltipElement.innerHTML = output;
}
this._measureTooltip?.setPosition(measureTooltipCoord);
}
}
Expand Down
Loading

0 comments on commit d18624e

Please sign in to comment.