nakas Claude commited on
Commit
7105e21
·
1 Parent(s): a3af0ca

Fix zoom and pan behavior consistency - both now clear instantly

Browse files

UNIFIED PAN/ZOOM BEHAVIOR:
- Created handleMovementEnd() function for identical pan and zoom handling
- Both pan and zoom now use the same instant clearing mechanism
- Eliminated different code paths that caused inconsistent behavior
- Zoom now clears particles instantly just like pan does

CONSISTENT PARTICLE CLEARING:
- Both moveend and zoomend trigger identical instant clearing
- Same clearAllParticles() function used for both operations
- Same reloadParticlesAfterMove() function for both operations
- No more behavioral differences between pan and zoom

RELIABLE STATE MANAGEMENT:
- Enhanced reloadParticlesAfterMove() with force clean creation
- Removes any existing layers before creating new ones
- Consistent behavior regardless of previous zoom/pan operations
- Pan clearing now works reliably after any zoom level

FIXES:
- ✅ Zoom now clears particles instantly (was inconsistent)
- ✅ Pan clearing works consistently after zoom operations
- ✅ No more need to toggle particles to restore proper behavior
- ✅ Identical instant clearing for both pan and zoom

Console shows unified behavior:
- ⚡ "PAN END: INSTANTLY clearing and reloading particles..."
- ⚡ "ZOOM END: INSTANTLY clearing and reloading particles..."
- ⚡ "10m particles RECREATED at correct position (zoom X)"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +46 -50
app.py CHANGED
@@ -743,50 +743,42 @@ def create_wind_map(region="global"):
743
  }}, 10);
744
  }}
745
 
746
- // Function to reload particles after pan/zoom
747
  function reloadParticlesAfterMove() {{
748
- console.log("⚡ PAN/ZOOM END: Reloading particles...");
749
 
750
- // Check zoom level to prevent jumping artifacts - stricter limits
751
  var currentZoom = map.getZoom();
752
- if (currentZoom < 3) {{
753
- console.log("⚠️ Zoom level " + currentZoom + " too far out, clearing particles to prevent jumps");
754
- // Clear any existing particles at far zoom
755
- if (current10mLayer && map.hasLayer(current10mLayer)) {{
756
- map.removeLayer(current10mLayer);
757
- current10mLayer = null;
758
- }}
759
- if (current100mLayer && map.hasLayer(current100mLayer)) {{
760
- map.removeLayer(current100mLayer);
761
- current100mLayer = null;
762
  }}
763
- return;
 
 
 
 
764
  }}
765
 
766
- // Wait for map to fully settle before recreating particles
767
- setTimeout(function() {{
768
- // Force map refresh to ensure proper positioning
769
- map.invalidateSize();
770
-
771
- // Only recreate and add back layers if their toggles are ON and zoom is appropriate
772
- if (show10m) {{
773
- current10mLayer = create10mLayer();
774
- current10mLayer.addTo(map);
775
- console.log("⚡ 10m particles reloaded at correct position (zoom " + currentZoom + ")");
776
- }} else {{
777
- console.log("⚠️ 10m particles NOT reloaded (toggle OFF)");
778
- }}
779
-
780
- if (show100m) {{
781
- current100mLayer = create100mLayer();
782
- current100mLayer.addTo(map);
783
- console.log("⚡ 100m particles reloaded at correct position (zoom " + currentZoom + ")");
784
- }} else {{
785
- console.log("⚠️ 100m particles NOT reloaded (toggle OFF)");
786
  }}
787
-
788
- console.log("✅ Particle reload complete at correct map position!");
789
- }}, 200); // Longer delay to ensure map settles
 
 
 
 
 
790
  }}
791
 
792
  // Add pan/zoom event handlers - particles stay in place during movement
@@ -800,27 +792,31 @@ def create_wind_map(region="global"):
800
  // Do NOT clear particles - let them stay in place during zoom
801
  }});
802
 
803
- map.on('moveend', function() {{
804
- console.log("⚡ PAN END: Clearing and reloading particles at new position...");
805
- // Clear particles when movement ends and reload at correct position
806
- clearAllParticles();
807
- setTimeout(reloadParticlesAfterMove, 200);
808
- }});
809
-
810
- map.on('zoomend', function() {{
811
- console.log("⚡ ZOOM END: Clearing and reloading particles at new zoom...");
812
 
813
- // Clear particles when zoom ends
814
  clearAllParticles();
815
 
816
  // Check zoom level to prevent particle artifacts at far zoom
817
  var currentZoom = map.getZoom();
818
  if (currentZoom < 3) {{
819
- console.log("⚠️ Zoom too far out (level " + currentZoom + "), NOT reloading particles to prevent jumps");
820
  // Don't reload particles at far zoom
821
- }} else {{
822
- setTimeout(reloadParticlesAfterMove, 200);
823
  }}
 
 
 
 
 
 
 
 
 
 
 
824
  }});
825
 
826
 
 
743
  }}, 10);
744
  }}
745
 
746
+ // Function to reload particles after pan/zoom with consistent behavior
747
  function reloadParticlesAfterMove() {{
748
+ console.log("⚡ RELOADING particles with consistent behavior...");
749
 
750
+ // Get current zoom for logging
751
  var currentZoom = map.getZoom();
752
+
753
+ // Force map refresh to ensure proper positioning
754
+ map.invalidateSize();
755
+
756
+ // Always respect current toggle states - recreate layers if toggles are ON
757
+ if (show10m) {{
758
+ // Force clean creation of 10m layer
759
+ if (current10mLayer) {{
760
+ try {{ map.removeLayer(current10mLayer); }} catch(e) {{}}
 
761
  }}
762
+ current10mLayer = create10mLayer();
763
+ current10mLayer.addTo(map);
764
+ console.log("⚡ 10m particles RECREATED at correct position (zoom " + currentZoom + ")");
765
+ }} else {{
766
+ console.log("⚠️ 10m particles NOT reloaded (toggle OFF)");
767
  }}
768
 
769
+ if (show100m) {{
770
+ // Force clean creation of 100m layer
771
+ if (current100mLayer) {{
772
+ try {{ map.removeLayer(current100mLayer); }} catch(e) {{}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
773
  }}
774
+ current100mLayer = create100mLayer();
775
+ current100mLayer.addTo(map);
776
+ console.log("⚡ 100m particles RECREATED at correct position (zoom " + currentZoom + ")");
777
+ }} else {{
778
+ console.log("⚠️ 100m particles NOT reloaded (toggle OFF)");
779
+ }}
780
+
781
+ console.log("✅ Consistent particle reload complete - pan/zoom behavior now identical!");
782
  }}
783
 
784
  // Add pan/zoom event handlers - particles stay in place during movement
 
792
  // Do NOT clear particles - let them stay in place during zoom
793
  }});
794
 
795
+ // Unified instant clearing for both pan and zoom
796
+ function handleMovementEnd(eventType) {{
797
+ console.log("⚡ " + eventType + " END: INSTANTLY clearing and reloading particles...");
 
 
 
 
 
 
798
 
799
+ // INSTANT clearing - same for both pan and zoom
800
  clearAllParticles();
801
 
802
  // Check zoom level to prevent particle artifacts at far zoom
803
  var currentZoom = map.getZoom();
804
  if (currentZoom < 3) {{
805
+ console.log("⚠️ Zoom level " + currentZoom + " too far out, NOT reloading particles to prevent jumps");
806
  // Don't reload particles at far zoom
807
+ return;
 
808
  }}
809
+
810
+ // Reload particles at correct position - same for both pan and zoom
811
+ setTimeout(reloadParticlesAfterMove, 200);
812
+ }}
813
+
814
+ map.on('moveend', function() {{
815
+ handleMovementEnd("PAN");
816
+ }});
817
+
818
+ map.on('zoomend', function() {{
819
+ handleMovementEnd("ZOOM");
820
  }});
821
 
822