Skip to content

Commit

Permalink
fix: reloadFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
TreffN committed Nov 22, 2024
1 parent fe2868a commit 703b34f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
27 changes: 18 additions & 9 deletions src/components/EditFeatureDrawer/EditFeatureFullForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import {

import moment from 'moment';

import {
equalTo
} from 'ol/format/filter';

import { ValidateErrorEntity } from 'rc-field-form/es/interface';

import {
Expand Down Expand Up @@ -87,10 +83,18 @@ export const EditFeatureFullForm: React.FC<EditFeatureFullFormProps> = ({
return;
}

const root = document.implementation.createDocument(null, 'root');
const filter = root.createElement('Filter');
const resourceId = root.createElement('ResourceId');
resourceId.setAttribute('rid', id);
filter.appendChild(resourceId);
root.documentElement.appendChild(filter);

const updatedFeatures = await executeGetFeature({
layer: layer,
filter: equalTo('id', id)
});
filter: filter
},
'2.0.0');

if (
updatedFeatures?.features[0]
Expand Down Expand Up @@ -230,9 +234,14 @@ export const EditFeatureFullForm: React.FC<EditFeatureFullFormProps> = ({
// get feature id from response
const featureId = xmlDoc.getElementsByTagName('ogc:FeatureId');
const idString = featureId.item(0)?.getAttribute('fid');
const id = idString?.split('.')[1];
if (id) {
reloadFeature(id);
if (idString === 'none') {
const featId = feature.id;
if (!featId) {
return;
}
reloadFeature((featId as string));
} else if (idString) {
reloadFeature(idString);
}
};

Expand Down
12 changes: 8 additions & 4 deletions src/hooks/useExecuteGetFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import useSHOGunAPIClient from './useSHOGunAPIClient';

export type GetFeatureOpts = {
layer: WmsLayer;
filter?: OlFormatFilter;
filter?: OlFormatFilter | Element;
};

export const useExecuteGetFeature = () => {
const client = useSHOGunAPIClient();
const map = useMap();
const executeWfsDescribeFeatureType = useExecuteWfsDescribeFeatureType();

const executeGetFeature = useCallback(async (opts: GetFeatureOpts) => {
const executeGetFeature = useCallback(async (opts: GetFeatureOpts, version = '1.1.0') => {
if (!map) {
return;
}
Expand Down Expand Up @@ -64,15 +64,19 @@ export const useExecuteGetFeature = () => {
url = url.slice(0, -1);
}

const featureRequest = new OlFormatWFS().writeGetFeature({
const featureRequest = new OlFormatWFS({version: version}).writeGetFeature({
srsName: map.getView().getProjection().getCode(),
featureNS: describeFeatureType.targetNamespace,
featurePrefix: describeFeatureType.targetPrefix,
featureTypes: [source?.getParams().LAYERS],
outputFormat: 'application/json',
filter: opts.filter
filter: opts.filter instanceof OlFormatFilter ? opts.filter : undefined
});

if (featureRequest instanceof Element && opts.filter instanceof Element) {
featureRequest.getElementsByTagName('Query')[0].appendChild(opts.filter);
}

const defaultHeaders = {
'Content-Type': 'application/json'
};
Expand Down

0 comments on commit 703b34f

Please sign in to comment.