|
480 | 480 | } catch (err) { |
481 | 481 | console.error(gettext("Unable to fit NetJSON bounds:"), err); |
482 | 482 | } |
483 | | - |
484 | | - // Restrict horizontal panning to three wrapped worlds |
485 | | - map.leaflet.setMaxBounds( |
486 | | - L.latLngBounds(L.latLng(-90, -540), L.latLng(90, 540)), |
487 | | - ); |
488 | | - |
489 | | - map.leaflet.on("moveend", (event) => { |
490 | | - const netjsonGraph = map; // alias for clarity |
491 | | - const bounds = event.target.getBounds(); |
492 | | - |
493 | | - // Ensure data.features exists; otherwise skip wrap logic |
494 | | - if (!netjsonGraph.data || !Array.isArray(netjsonGraph.data.features)) { |
495 | | - return; // nothing to wrap |
496 | | - } |
497 | | - |
498 | | - // When panning west past the dateline, clone features shifted −360° |
499 | | - if (bounds._southWest.lng < -180 && !netjsonGraph.westWorldFeaturesAppended) { |
500 | | - const westWorld = structuredClone(netjsonGraph.data); |
501 | | - westWorld.features = westWorld.features.filter( |
502 | | - (f) => !f.geometry || f.geometry.coordinates[0] <= 180, |
503 | | - ); |
504 | | - westWorld.features.forEach((f) => { |
505 | | - if (f.geometry) { |
506 | | - f.geometry.coordinates[0] -= 360; |
507 | | - } |
508 | | - }); |
509 | | - netjsonGraph.utils.appendData(westWorld, netjsonGraph); |
510 | | - netjsonGraph.westWorldFeaturesAppended = true; |
511 | | - } |
512 | | - |
513 | | - // When panning east past the dateline, clone features shifted +360° |
514 | | - if (bounds._northEast.lng > 180 && !netjsonGraph.eastWorldFeaturesAppended) { |
515 | | - const eastWorld = structuredClone(netjsonGraph.data); |
516 | | - eastWorld.features = eastWorld.features.filter( |
517 | | - (f) => !f.geometry || f.geometry.coordinates[0] >= -180, |
518 | | - ); |
519 | | - eastWorld.features.forEach((f) => { |
520 | | - if (f.geometry) { |
521 | | - f.geometry.coordinates[0] += 360; |
522 | | - } |
523 | | - }); |
524 | | - netjsonGraph.utils.appendData(eastWorld, netjsonGraph); |
525 | | - netjsonGraph.eastWorldFeaturesAppended = true; |
526 | | - } |
527 | | - }); |
528 | 483 | }, |
529 | 484 | }); |
530 | 485 |
|
|
0 commit comments