Skip to content

Commit

Permalink
fix: Fix strict null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlkoch committed Mar 1, 2022
1 parent bae1d9a commit 3c731b6
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Button/CopyButton/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const CopyButton: React.FC<CopyButtonProps> = ({

const copy = feat.clone();

layers[0].getSource().addFeature(copy);
layers[0].getSource()?.addFeature(copy);

AnimateUtil.moveFeature(
map,
Expand Down
2 changes: 1 addition & 1 deletion src/Button/DeleteButton/DeleteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
const onFeatureSelect = (event: OlSelectEvent) => {
onFeatureRemove?.(event);
const feat = event.selected[0];
layers[0].getSource().removeFeature(feat);
layers[0].getSource()?.removeFeature(feat);
};

const finalClassName = className
Expand Down
7 changes: 4 additions & 3 deletions src/Button/DigitizeButton/DigitizeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as OlEventConditions from 'ol/events/condition';
import OlGeometry from 'ol/geom/Geometry';

import _isFunction from 'lodash/isFunction';
import _isArray from 'lodash/isArray';

import ToggleButton, { ToggleButtonProps } from '../ToggleButton/ToggleButton';
import MapUtil from '@terrestris/ol-util/dist/MapUtil/MapUtil';
Expand Down Expand Up @@ -901,7 +902,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
}

if (this._digitizeLayer) {
this._digitizeLayer.getSource().removeFeature(feat);
this._digitizeLayer.getSource()?.removeFeature(feat);
}

if (_isFunction(onFeatureRemove)) {
Expand Down Expand Up @@ -974,7 +975,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton

if (feature.get('isLabel')) {
this._digitizeTextFeature = feature;
let textLabel = '';
let textLabel: string | string[] = '';

const featureStyle = this.digitizeStyleFunction(feature);

Expand All @@ -986,7 +987,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton

this.setState({
showLabelPrompt: true,
textLabel
textLabel: _isArray(textLabel) ? textLabel.join(' ') : textLabel
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/Button/DrawButton/DrawButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const DrawButton: React.FC<DrawButtonProps> = ({
}

const newInteraction = new OlInteractionDraw({
source: layer.getSource(),
source: layer.getSource() || undefined,
type: type,
geometryFunction: geometryFunction,
style: drawStyle ?? DigitizeUtil.defaultDigitizeStyleFunction,
Expand Down Expand Up @@ -227,7 +227,7 @@ const DrawButton: React.FC<DrawButtonProps> = ({

const onModalLabelCancelInternal = () => {
onModalLabelCancel?.();
layer.getSource().removeFeature(digitizeTextFeature);
layer.getSource()?.removeFeature(digitizeTextFeature);
setDigitizeTextFeature(null);
};

Expand Down
10 changes: 5 additions & 5 deletions src/Button/GeoLocationButton/GeoLocationButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class GeoLocationButton extends React.Component<GeoLocationButtonProps> {

if (showMarker) {
this._markerFeature = new OlFeature();
this._geoLocationLayer.getSource().addFeature(this._markerFeature);
this._geoLocationLayer.getSource()?.addFeature(this._markerFeature);
}
}

Expand All @@ -151,7 +151,7 @@ class GeoLocationButton extends React.Component<GeoLocationButtonProps> {

if (showMarker && !this._markerFeature) {
this._markerFeature = new OlFeature();
this._geoLocationLayer.getSource().addFeature(this._markerFeature);
this._geoLocationLayer.getSource()?.addFeature(this._markerFeature);
}
}

Expand Down Expand Up @@ -241,7 +241,7 @@ class GeoLocationButton extends React.Component<GeoLocationButtonProps> {
}
if (this._markerFeature) {
this._markerFeature = null;
this._geoLocationLayer.getSource().clear();
this._geoLocationLayer.getSource()?.clear();
}
return;
}
Expand All @@ -257,8 +257,8 @@ class GeoLocationButton extends React.Component<GeoLocationButtonProps> {
if (!this._markerFeature) {
this._markerFeature = new OlFeature();
}
if (!this._geoLocationLayer.getSource().getFeatures().includes(this._markerFeature)) {
this._geoLocationLayer.getSource().addFeature(this._markerFeature);
if (!this._geoLocationLayer.getSource()?.getFeatures().includes(this._markerFeature)) {
this._geoLocationLayer.getSource()?.addFeature(this._markerFeature);
}
const heading = this._geoLocation.getHeading() || 0;
const speed = this._geoLocation.getSpeed() || 0;
Expand Down
10 changes: 6 additions & 4 deletions src/Button/MeasureButton/MeasureButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class MeasureButton extends React.Component<MeasureButtonProps> {
const drawType = measureType === 'polygon' ? OlGeometryType.MULTI_POLYGON : OlGeometryType.MULTI_LINE_STRING;

const drawInteraction = new OlInteractionDraw({
source: this._measureLayer.getSource(),
source: this._measureLayer.getSource() || undefined,
type: drawType,
maxPoints: maxPoints,
style: new OlStyleStyle({
Expand Down Expand Up @@ -513,15 +513,17 @@ class MeasureButton extends React.Component<MeasureButtonProps> {

this._eventKeys.click = map.on('click', (e: OlMapBrowserEvent<MouseEvent>) => this.onMapClick(e));

if (!multipleDrawing && source.getFeatures().length > 0) {
const features = source?.getFeatures();

if (!multipleDrawing && features && features.length > 0) {
this.cleanupTooltips();
this.createMeasureTooltip();

if (showHelpTooltip) {
this.createHelpTooltip();
}

source.clear();
source?.clear();
}
}

Expand Down Expand Up @@ -755,7 +757,7 @@ class MeasureButton extends React.Component<MeasureButtonProps> {
this.cleanupTooltips();

if (this._measureLayer) {
this._measureLayer.getSource().clear();
this._measureLayer.getSource()?.clear();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Button/ModifyButton/ModifyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export const ModifyButton: React.FC<ModifyButtonProps> = ({
const onFeatureSelect = (event: OlSelectEvent) => {
if (editLabel) {
const labeled = event.selected.find(f => f.get('isLabel'));
setEditLabelFeature(labeled);
setEditLabelFeature(labeled || null);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class AddWmsLayerEntry extends React.Component<AddWmsLayerEntryProps, Add
super(props);
// TODO: getAttributions is not @api and returns a function in v6.5
this.state = {
copyright: props.wmsLayer.getSource().getAttributions(),
copyright: props.wmsLayer.getSource()?.getAttributions() || null,
queryable: props.wmsLayer.get('queryable')
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/HigherOrderComponent/TimeLayerAware/TimeLayerAware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export function timeLayerAware<P>(WrappedComponent: React.ComponentType<P>, laye
timeChanged = newValues => {
layers.forEach(config => {
if (config.isWmsTime) {
const parms = config.layer.getSource().getParams();
const parms = config.layer.getSource()?.getParams();
const timeParam = findTimeParam(parms);
if (_isArray(newValues)) {
parms[timeParam] = `${newValues[0]}/${newValues[1]}`;
} else {
parms[timeParam] = `${newValues}`;
}
config.layer.getSource().updateParams(parms);
config.layer.getSource()?.updateParams(parms);
}
if (config.customHandler) {
config.customHandler(newValues);
Expand Down
2 changes: 1 addition & 1 deletion src/LayerSwitcher/LayerSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class LayerSwitcher extends React.Component<LayerSwitcherProps, LayerSwit
});
} else {
layerClone = new OlLayerTile({
source: layer.getSource(),
source: layer.getSource() || undefined,
properties: {
originalLayer: layer
},
Expand Down
4 changes: 2 additions & 2 deletions src/Panel/TimeLayerSliderPanel/TimeLayerSliderPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class TimeLayerSliderPanel extends React.Component<TimeLayerSliderPanelPr
wmsTimeHandler = (value?: any) => {
this._wmsTimeLayers.forEach(config => {
if (config.layer && config.layer.get('type') === 'WMSTime') {
const params = config.layer.getSource().getParams();
const params = config.layer.getSource()?.getParams();
let time;
if (Array.isArray(value)) {
time = value[0];
Expand All @@ -278,7 +278,7 @@ export class TimeLayerSliderPanel extends React.Component<TimeLayerSliderPanelPr
} else {
params.TIME = time.format(timeFormat);
}
config.layer.getSource().updateParams(params);
config.layer.getSource()?.updateParams(params);
}
});
};
Expand Down

0 comments on commit 3c731b6

Please sign in to comment.