@@ -29,6 +29,7 @@ type GlobalData = {
2929 last_layer_control : any
3030 height : any
3131 selected_layers : Record < string , { name : string ; url : string } >
32+ wrap_longitude : boolean
3233}
3334
3435declare global {
@@ -56,18 +57,31 @@ function updateComponentValue(map: any) {
5657 let previous_data = global_data . previous_data
5758 let bounds = map . getBounds ( )
5859 let zoom = map . getZoom ( )
60+ let center = map . getCenter ( )
61+ const wrapLng = global_data . wrap_longitude
62+
63+ // Use Leaflet's built-in wrapLatLng and wrapLatLngBounds if wrapping is enabled
64+ const wrapLatLng = ( latlng : any ) => {
65+ if ( ! latlng || ! wrapLng ) return latlng
66+ return map . wrapLatLng ( latlng )
67+ }
68+ const wrapBounds = ( b : any ) => {
69+ if ( ! b || ! wrapLng ) return b
70+ return map . wrapLatLngBounds ( b )
71+ }
72+
5973 let _data = {
60- last_clicked : global_data . lat_lng_clicked ,
61- last_object_clicked : global_data . last_object_clicked ,
74+ last_clicked : wrapLatLng ( global_data . lat_lng_clicked ) ,
75+ last_object_clicked : wrapLatLng ( global_data . last_object_clicked ) ,
6276 last_object_clicked_tooltip : global_data . last_object_clicked_tooltip ,
6377 last_object_clicked_popup : global_data . last_object_clicked_popup ,
6478 all_drawings : global_data . all_drawings ,
6579 last_active_drawing : global_data . last_active_drawing ,
66- bounds : bounds ,
80+ bounds : wrapBounds ( bounds ) ,
6781 zoom : zoom ,
6882 last_circle_radius : global_data . last_circle_radius ,
6983 last_circle_polygon : global_data . last_circle_polygon ,
70- center : map . getCenter ( ) ,
84+ center : wrapLatLng ( center ) ,
7185 selected_layers : Object . values ( global_data . selected_layers )
7286 }
7387
@@ -282,6 +296,7 @@ async function onRender(event: Event) {
282296 const return_on_hover : boolean = data . args [ "return_on_hover" ]
283297 const layer_control : string = data . args [ "layer_control" ]
284298 const pixelated : boolean = data . args [ "pixelated" ]
299+ const wrap_longitude : boolean = data . args [ "wrap_longitude" ] ?? false
285300
286301 // load scripts
287302 const loadScripts = async ( ) => {
@@ -417,7 +432,8 @@ async function onRender(event: Event) {
417432 last_feature_group : null ,
418433 last_layer_control : null ,
419434 selected_layers : { } ,
420- height : height
435+ height : height ,
436+ wrap_longitude : wrap_longitude
421437 }
422438 if ( script . indexOf ( "map_div2" ) !== - 1 ) {
423439 parent_div ?. classList . remove ( "single" )
0 commit comments