Skip to content

Commit

Permalink
fix uploadArea: geojson with no features leading page crash error solve
Browse files Browse the repository at this point in the history
  • Loading branch information
NSUWAL123 committed Mar 20, 2024
1 parent f35842a commit 39bf5d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import MultiPoint from 'ol/geom/MultiPoint.js';
import { buffer } from 'ol/extent';
import { bbox as OLBbox } from 'ol/loadingstrategy';
import { geojson as FGBGeoJson } from 'flatgeobuf';

import { isValidUrl } from '@/utilfunctions/urlChecker';
import { featureCollectionHasFeatures } from '@/utilfunctions/commonUtils';

const selectElement = 'singleselect';

Expand Down Expand Up @@ -229,6 +229,7 @@ const VectorLayer = ({
if (!map) return;
if (!geojson) return;
if (!valid(geojson)) return;
if (!featureCollectionHasFeatures(geojson)) return;

const vectorLyr = new OLVectorLayer({
source: new VectorSource({
Expand Down Expand Up @@ -340,7 +341,7 @@ const VectorLayer = ({
useEffect(() => {
if (!map || !vectorLayer || !zoomToLayer) return;
const source = vectorLayer.getSource();
if (source.getFeatures().length === 0) return;
if (source.getFeatures()?.length === 0) return;
const extent = source.getExtent();
if (!isExtentValid(extent)) return;
map.getView().fit(extent, viewProperties);
Expand Down Expand Up @@ -379,7 +380,7 @@ const VectorLayer = ({
});
function pointerMovefn(event) {
vectorLayer.getFeatures(event.pixel).then((features) => {
if (!features.length) {
if (!features?.length) {
selection = {};
hoverEffect(undefined, vectorLayer);

Expand Down
12 changes: 12 additions & 0 deletions src/frontend/src/utilfunctions/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ export const isInputEmpty = (text: string): boolean => {
const trimmedText = text.trim();
return trimmedText === '';
};

export const featureCollectionHasFeatures = (geojson): boolean => {
if (
geojson?.type === 'FeatureCollection' &&
geojson?.features &&
Array.isArray(geojson?.features) &&
geojson?.features?.length === 0
) {
return false;
}
return true;
};

0 comments on commit 39bf5d8

Please sign in to comment.