@@ -176,6 +176,7 @@ function CreateComponent() {
176
176
> ( ) ;
177
177
const [ name , setName ] = useState < string > ( "" ) ;
178
178
const [ validationFailure , setValidationFailure ] = useState < string > ( "" ) ;
179
+ const [ parsingFailure , setParsingFailure ] = useState < string > ( "" ) ;
179
180
// const [showAboutModal, setShowAboutModal] = useState<boolean>(false);
180
181
181
182
useEffect ( ( ) => {
@@ -369,7 +370,7 @@ function CreateComponent() {
369
370
370
371
const loadTextArea = ( ) => {
371
372
if ( ! drawRef . current || ! mapRef . current ) return ;
372
- const isBbox = / ^ ( - ? \d + ( \. \d + ) ? , ) { 3 } - ? \d + ( \. \d + ) ? $ / ;
373
+ const isBbox = / ^ \s * ( - ? \d + ( \. \d + ) ? \s * , \s * ) { 3 } - ? \d + ( \. \d + ) ? \s * $ / ;
373
374
if ( isBbox . test ( textAreaValue ) ) {
374
375
const arr = textAreaValue . split ( "," ) ;
375
376
const minX = + arr [ 0 ] ;
@@ -445,10 +446,28 @@ function CreateComponent() {
445
446
< div >
446
447
< p > Paste bbox or GeoJSON:</ p >
447
448
< textarea
449
+ aria-invalid = { parsingFailure !== "" }
448
450
value = { textAreaValue }
449
451
onChange = { ( e ) => setTextAreaValue ( e . target . value ) }
450
452
/>
451
- < button onClick = { loadTextArea } > Load</ button >
453
+ { parsingFailure !== "" && (
454
+ < p > Parsing failed. { parsingFailure } </ p >
455
+ ) }
456
+ < button onClick = { ( ) => {
457
+ setParsingFailure ( "" ) ;
458
+ try {
459
+ loadTextArea ( ) ;
460
+ } catch ( e ) {
461
+ console . error ( e ) ;
462
+ // JSON.parse throws a SyntaxError if the input is not valid JSON. Might be a bbox.
463
+ if ( e instanceof SyntaxError ) {
464
+ setParsingFailure ( "Expected bbox format:\n minLon, minLat, maxLon, maxLat" ) ;
465
+ } else {
466
+ // If it's not a SyntaxError, it's probably invalid GeoJSON.
467
+ setParsingFailure ( "GeoJSON must contain valid Polygon or MultiPolygon geometries." ) ;
468
+ }
469
+ }
470
+ } } > Load</ button >
452
471
</ div >
453
472
< input
454
473
value = { name }
0 commit comments