@@ -74,6 +74,10 @@ export default class MapLeafletLiveMapComponent extends Component {
7474 this . #createMapContextMenu( map ) ;
7575 this . trigger ( 'onLoad' , ...arguments ) ;
7676 this . load . perform ( ) ;
77+
78+ // Listen for map move/zoom events to trigger viewport-based resource reload
79+ map . on ( 'moveend' , ( ) => this . reloadResourcesInViewport . perform ( ) ) ;
80+ map . on ( 'zoomend' , ( ) => this . reloadResourcesInViewport . perform ( ) ) ;
7781 }
7882
7983 @action trigger ( name , ...rest ) {
@@ -160,11 +164,19 @@ export default class MapLeafletLiveMapComponent extends Component {
160164 /** load resources and wait for stuff here and trigger map ready **/
161165 @task * load ( ) {
162166 try {
167+ // Get initial map bounds for spatial filtering
168+ const bounds = this . map ? this . map . getBounds ( ) : null ;
169+ const params = bounds
170+ ? {
171+ bounds : [ bounds . getSouth ( ) , bounds . getWest ( ) , bounds . getNorth ( ) , bounds . getEast ( ) ] ,
172+ }
173+ : { } ;
174+
163175 const data = yield all ( [
164176 this . loadResource . perform ( 'routes' ) ,
165- this . loadResource . perform ( 'vehicles' ) ,
166- this . loadResource . perform ( 'drivers' ) ,
167- this . loadResource . perform ( 'places' ) ,
177+ this . loadResource . perform ( 'vehicles' , { params } ) ,
178+ this . loadResource . perform ( 'drivers' , { params } ) ,
179+ this . loadResource . perform ( 'places' , { params } ) ,
168180 this . loadResource . perform ( 'service-areas' ) ,
169181 ] ) ;
170182
@@ -176,6 +188,26 @@ export default class MapLeafletLiveMapComponent extends Component {
176188 }
177189 }
178190
191+ @task ( { restartable : true } ) * reloadResourcesInViewport ( ) {
192+ if ( ! this . map ) {
193+ return ;
194+ }
195+
196+ // Get current map bounds
197+ const bounds = this . map . getBounds ( ) ;
198+ const params = {
199+ bounds : [ bounds . getSouth ( ) , bounds . getWest ( ) , bounds . getNorth ( ) , bounds . getEast ( ) ] ,
200+ } ;
201+
202+ // Reload spatially-filtered resources (drivers, vehicles, places)
203+ // Orders, routes, and service-areas are not spatially filtered
204+ try {
205+ yield all ( [ this . loadResource . perform ( 'vehicles' , { params } ) , this . loadResource . perform ( 'drivers' , { params } ) , this . loadResource . perform ( 'places' , { params } ) ] ) ;
206+ } catch ( err ) {
207+ debug ( 'Failed to reload resources in viewport: ' + err . message ) ;
208+ }
209+ }
210+
179211 @task * loadResource ( path , options = { } ) {
180212 if ( this . abilities . cannot ( `fleet-ops list ${ path } ` ) ) return [ ] ;
181213
0 commit comments