Skip to content

Commit

Permalink
fix: adaptaions after ol-util upgrade to v10.x
Browse files Browse the repository at this point in the history
  • Loading branch information
annarieger committed Nov 16, 2022
1 parent 2e04fca commit 4440810
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 49 deletions.
15 changes: 15 additions & 0 deletions src/Button/CopyButton/CopyButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import OlView from 'ol/View';
import OlMap from 'ol/Map';
import OlPoint from 'ol/geom/Point';
import OlFeature from 'ol/Feature';
import OlStyleStyle from 'ol/style/Style';
import OlStyleStroke from 'ol/style/Stroke';
import OlStyleFill from 'ol/style/Fill';

import { clickMap, mockForEachFeatureAtPixel, renderInMapContext } from '../../Util/rtlTestUtils';
import { DigitizeUtil } from '../../Util/DigitizeUtil';
Expand All @@ -16,8 +19,19 @@ describe('<CopyButton />', () => {
const coord = [829729, 6708850];
let map: OlMap;
let feature: OlFeature<OlPoint>;
let style: OlStyleStyle;

beforeEach(() => {

style = new OlStyleStyle({
stroke: new OlStyleStroke({
color: 'red',
width: 2
}),
fill: new OlStyleFill({
color: 'green'
})
});
feature = new OlFeature<OlPoint>({
geometry: new OlPoint(coord),
someProp: 'test'
Expand Down Expand Up @@ -55,6 +69,7 @@ describe('<CopyButton />', () => {
const mock = mockForEachFeatureAtPixel(map, [200, 200], feature);

const layer = DigitizeUtil.getDigitizeLayer(map);
layer.setStyle(style);

renderInMapContext(map, <CopyButton />);

Expand Down
4 changes: 3 additions & 1 deletion src/Button/CopyButton/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import OlVectorSource from 'ol/source/Vector';
import OlGeometry from 'ol/geom/Geometry';
import OlVectorLayer from 'ol/layer/Vector';
import { SelectEvent as OlSelectEvent } from 'ol/interaction/Select';
import OlStyle from 'ol/style/Style';

import AnimateUtil from '@terrestris/ol-util/dist/AnimateUtil/AnimateUtil';

Expand Down Expand Up @@ -77,7 +78,8 @@ const CopyButton: React.FC<CopyButtonProps> = ({
layers[0],
copy,
500,
50
50,
layers[0].getStyle() as OlStyle
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/Button/DigitizeButton/DigitizeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ class DigitizeButton extends React.Component<DigitizeButtonProps, DigitizeButton
copy,
500,
50,
this.digitizeStyleFunction(feat)
this.digitizeStyleFunction(feat) as OlStyleStyle
);
};

Expand Down
3 changes: 3 additions & 0 deletions src/Field/ScaleCombo/ScaleCombo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ class ScaleCombo extends React.Component<ScaleComboProps, ScaleComboState> {
*/
pushScale = (scales: number[], resolution: number, view: OlView) => {
const scale = MapUtil.getScaleForResolution(resolution, view.getProjection().getUnits());
if (!scale) {
return;
}
const roundScale = MapUtil.roundScale(scale);
if (scales.includes(roundScale) ) {
return;
Expand Down
10 changes: 8 additions & 2 deletions src/Field/WfsSearch/WfsSearch.example.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ class WfsSearchExample extends React.Component {
baseUrl='https://ows-demo.terrestris.de/geoserver/osm/wfs'
featureTypes={['osm:osm-country-borders']}
maxFeatures={3}
searchAttributes={{
'osm:osm-country-borders': ['name']
attributeDetails={{
'osm:osm-country-borders': {
name: {
type: 'string',
exactSearch: false,
matchCase: false
}
}
}}
map={this.map}
/>
Expand Down
10 changes: 8 additions & 2 deletions src/Field/WfsSearch/WfsSearch.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ describe('<WfsSearch />', () => {
placeholder: 'Type a countryname in its own language…',
baseUrl: 'https://ows-demo.terrestris.de/geoserver/osm/wfs',
featureTypes: ['osm:osm-country-borders'],
searchAttributes: {
'osm:osm-country-borders': ['name']
attributeDetails: {
'osm:osm-country-borders': {
name: {
type: 'string',
exactSearch: false,
matchCase: false
}
}
}
});
const doSearchSpy = jest.spyOn(wrapper.instance(), 'doSearch');
Expand Down
22 changes: 3 additions & 19 deletions src/Field/WfsSearch/WfsSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import _isFunction from 'lodash/isFunction';
import _debounce from 'lodash/debounce';

import Logger from '@terrestris/base-util/dist/Logger';
import WfsFilterUtil from '@terrestris/ol-util/dist/WfsFilterUtil/WfsFilterUtil';
import WfsFilterUtil, { AttributeDetails } from '@terrestris/ol-util/dist/WfsFilterUtil/WfsFilterUtil';

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

Expand Down Expand Up @@ -46,15 +46,7 @@ interface OwnProps {
* }
* ```
*/
attributeDetails: {
[featureType: string]: {
[attributeName: string]: {
matchCase: boolean;
type: string;
exactSearch: boolean;
};
};
};
attributeDetails: AttributeDetails;
/**
* SRS name. No srsName attribute will be set on geometries when this is not
* provided.
Expand Down Expand Up @@ -109,12 +101,7 @@ interface OwnProps {
* The base URL. Please make sure that the WFS-Server supports CORS.
*/
baseUrl: string;
/**
* An object mapping feature types to an array of attributes that should be searched through.
*/
searchAttributes: {
[featureType: string]: string[];
};

/**
* The namespace URI used for features.
*/
Expand Down Expand Up @@ -322,7 +309,6 @@ export class WfsSearch extends React.Component<WfsSearchProps, WfsSearchState> {
propertyNames,
srsName,
wfsFormatOptions,
searchAttributes,
attributeDetails
} = this.props;

Expand All @@ -336,7 +322,6 @@ export class WfsSearch extends React.Component<WfsSearchProps, WfsSearchState> {
propertyNames: propertyNames ?? [],
srsName,
wfsFormatOptions,
searchAttributes,
attributeDetails
};

Expand Down Expand Up @@ -436,7 +421,6 @@ export class WfsSearch extends React.Component<WfsSearchProps, WfsSearchState> {
onSelect,
propertyNames,
renderOption,
searchAttributes,
attributeDetails,
srsName,
wfsFormatOptions,
Expand Down
10 changes: 8 additions & 2 deletions src/Field/WfsSearchInput/WfsSearchInput.example.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ class WfsSearchInputExample extends React.Component {
placeholder="Type a countryname in its own language…"
baseUrl='https://ows-demo.terrestris.de/geoserver/osm/wfs'
featureTypes={['osm:osm-country-borders']}
searchAttributes={{
'osm:osm-country-borders': ['name']
attributeDetails={{
'osm:osm-country-borders': {
name: {
type: 'string',
exactSearch: false,
matchCase: false
}
}
}}
map={this.map}
onFetchSuccess={this.onFetchSuccess.bind(this)}
Expand Down
12 changes: 9 additions & 3 deletions src/Field/WfsSearchInput/WfsSearchInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('<WfsSearchInput />', () => {
expect(wrapper.state().searchTerm).toBe(evt.target.value);
});

it ('calls onBeforeSearch callback if passed in props', () => {
it('calls onBeforeSearch callback if passed in props', () => {
const wrapper = TestUtil.mountComponent(WfsSearchInput, {
});
wrapper.setProps({
Expand All @@ -53,8 +53,14 @@ describe('<WfsSearchInput />', () => {
placeholder: 'Type a countryname in its own language…',
baseUrl: 'https://ows-demo.terrestris.de/geoserver/osm/wfs',
featureTypes: ['osm:osm-country-borders'],
searchAttributes: {
'osm:osm-country-borders': ['name']
attributeDetails: {
'osm:osm-country-borders': {
name: {
type: 'string',
exactSearch: false,
matchCase: false
}
}
}
});
const doSearchSpy = jest.spyOn(wrapper.instance(), 'doSearch');
Expand Down
22 changes: 3 additions & 19 deletions src/Field/WfsSearchInput/WfsSearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import OlFormatGeoJson from 'ol/format/GeoJSON';
import _debounce from 'lodash/debounce';

import Logger from '@terrestris/base-util/dist/Logger';
import WfsFilterUtil from '@terrestris/ol-util/dist/WfsFilterUtil/WfsFilterUtil';
import WfsFilterUtil, { AttributeDetails } from '@terrestris/ol-util/dist/WfsFilterUtil/WfsFilterUtil';

import { Feature } from 'geojson';

Expand Down Expand Up @@ -47,15 +47,7 @@ interface OwnProps {
* }
* ```
*/
attributeDetails: {
[featureType: string]: {
[attributeName: string]: {
matchCase: boolean;
type: string;
exactSearch: boolean;
};
};
};
attributeDetails: AttributeDetails;
/**
* SRS name. No srsName attribute will be set on geometries when this is not
* provided.
Expand Down Expand Up @@ -97,12 +89,7 @@ interface OwnProps {
* The base URL. Please make sure that the WFS-Server supports CORS.
*/
baseUrl: string;
/**
* An object mapping feature types to an array of attributes that should be searched through.
*/
searchAttributes: {
[featureType: string]: string[];
};

/**
* The namespace URI used for features.
*/
Expand Down Expand Up @@ -293,7 +280,6 @@ export class WfsSearchInput extends React.Component<WfsSearchInputProps, WfsSear
propertyNames,
srsName,
wfsFormatOptions,
searchAttributes,
attributeDetails
} = this.props;

Expand All @@ -307,7 +293,6 @@ export class WfsSearchInput extends React.Component<WfsSearchInputProps, WfsSear
propertyNames: propertyNames ?? [],
srsName,
wfsFormatOptions,
searchAttributes,
attributeDetails
};

Expand Down Expand Up @@ -433,7 +418,6 @@ export class WfsSearchInput extends React.Component<WfsSearchInputProps, WfsSear
minChars,
outputFormat,
propertyNames,
searchAttributes,
attributeDetails,
srsName,
wfsFormatOptions,
Expand Down
12 changes: 12 additions & 0 deletions src/LayerTree/LayerTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
EventDataNode
} from 'rc-tree/lib/interface';

import _isNumber from 'lodash/isNumber';

import OlMap from 'ol/Map';
import OlLayerBase from 'ol/layer/Base';
import OlLayerGroup from 'ol/layer/Group';
Expand Down Expand Up @@ -523,6 +525,9 @@ class LayerTree extends React.Component<LayerTreeProps, LayerTreeState> {
return;
}
const dragInfo = MapUtil.getLayerPositionInfo(dragLayer, this.props.map);
if (!dragInfo || !dragInfo?.groupLayer) {
return;
}
const dragCollection = dragInfo.groupLayer.getLayers();
const dropLayer = MapUtil.getLayerByOlUid(this.props.map, e.node.props.eventKey);
if (!dropLayer) {
Expand All @@ -535,9 +540,16 @@ class LayerTree extends React.Component<LayerTreeProps, LayerTreeState> {
dragCollection.remove(dragLayer);

const dropInfo = MapUtil.getLayerPositionInfo(dropLayer, this.props.map);
if (!dropInfo || !dropInfo?.groupLayer) {
return;
}
const dropPosition = dropInfo.position;
const dropCollection = dropInfo.groupLayer.getLayers();

if (!_isNumber(dropPosition)) {
return;
}

// drop before node
if (location === -1) {
if (dropPosition === dropCollection.getLength() - 1) {
Expand Down

0 comments on commit 4440810

Please sign in to comment.