|
357 | 357 | return projection || projectionCode; |
358 | 358 | }; |
359 | 359 |
|
| 360 | + const canTransform = function (sourceProjectionCode, destinationProjectionCode) { |
| 361 | + if (!sourceProjectionCode || !destinationProjectionCode) { |
| 362 | + return false; |
| 363 | + } |
| 364 | + if (sourceProjectionCode === destinationProjectionCode) { |
| 365 | + return true; |
| 366 | + } |
| 367 | + try { |
| 368 | + const transform = ol.proj.getTransform(sourceProjectionCode, destinationProjectionCode); |
| 369 | + return typeof transform === 'function'; |
| 370 | + } catch (_error) { |
| 371 | + return false; |
| 372 | + } |
| 373 | + }; |
| 374 | + |
| 375 | + const transformCenterSafe = function (center, sourceProjectionCode, destinationProjectionCode) { |
| 376 | + if (!center) { |
| 377 | + return null; |
| 378 | + } |
| 379 | + if (!canTransform(sourceProjectionCode, destinationProjectionCode)) { |
| 380 | + return null; |
| 381 | + } |
| 382 | + try { |
| 383 | + return ol.proj.transform(center, sourceProjectionCode, destinationProjectionCode); |
| 384 | + } catch (_error) { |
| 385 | + return null; |
| 386 | + } |
| 387 | + }; |
| 388 | + |
| 389 | + const transformExtentSafe = function (extent, sourceProjectionCode, destinationProjectionCode) { |
| 390 | + if (!extent) { |
| 391 | + return null; |
| 392 | + } |
| 393 | + if (!canTransform(sourceProjectionCode, destinationProjectionCode)) { |
| 394 | + return null; |
| 395 | + } |
| 396 | + try { |
| 397 | + return ol.proj.transformExtent(extent, sourceProjectionCode, destinationProjectionCode); |
| 398 | + } catch (_error) { |
| 399 | + return null; |
| 400 | + } |
| 401 | + }; |
| 402 | + |
360 | 403 | const updateViewForLayer = function (layer) { |
361 | 404 | if (!layer) { |
362 | 405 | return; |
|
384 | 427 | if (size && currentProjectionCode) { |
385 | 428 | const currentExtent = currentView.calculateExtent(size); |
386 | 429 | if (currentProjectionCode !== nextProjectionCode) { |
387 | | - transformedExtent = ol.proj.transformExtent( |
| 430 | + transformedExtent = transformExtentSafe( |
388 | 431 | currentExtent, |
389 | 432 | currentProjectionCode, |
390 | 433 | nextProjectionCode |
|
396 | 439 |
|
397 | 440 | if (currentCenter) { |
398 | 441 | if (currentProjectionCode && currentProjectionCode !== nextProjectionCode) { |
399 | | - nextCenter = ol.proj.transform(currentCenter, currentProjectionCode, nextProjectionCode); |
| 442 | + nextCenter = |
| 443 | + transformCenterSafe(currentCenter, currentProjectionCode, nextProjectionCode) || |
| 444 | + defaultCenter; |
400 | 445 | } else { |
401 | 446 | nextCenter = currentCenter; |
402 | 447 | } |
|
461 | 506 | const initialCenter = |
462 | 507 | initialProjectionCode === defaultProjectionCode |
463 | 508 | ? defaultCenter |
464 | | - : ol.proj.transform(defaultCenter, defaultProjectionCode, initialProjectionCode); |
| 509 | + : ( |
| 510 | + transformCenterSafe( |
| 511 | + defaultCenter, |
| 512 | + defaultProjectionCode, |
| 513 | + initialProjectionCode |
| 514 | + ) || defaultCenter |
| 515 | + ); |
465 | 516 |
|
466 | 517 | tileGridOptions = initialGridDefinition |
467 | 518 | ? { |
|
0 commit comments