@@ -102,7 +102,9 @@ export var MapTileLayer = GridLayer.extend({
102102 this . _mapTiles . push ( mapTile ) ;
103103 this . _addToTileMap ( mapTile ) ;
104104 this . _updateBounds ( ) ;
105- // this.redraw();
105+ if ( this . _map ) {
106+ this . redraw ( ) ;
107+ }
106108 }
107109 } ,
108110
@@ -116,7 +118,32 @@ export var MapTileLayer = GridLayer.extend({
116118 this . _mapTiles . splice ( index , 1 ) ;
117119 this . _removeFromTileMap ( mapTile ) ;
118120 this . _updateBounds ( ) ;
119- // this.redraw();
121+ if ( this . _map ) {
122+ this . redraw ( ) ;
123+ }
124+ }
125+ } ,
126+
127+ /**
128+ * Removes a map-tile element from the layer using specific coordinates
129+ * Used when tile coordinates have changed and we need to remove based on old coordinates
130+ * @param {HTMLTileElement } mapTile - The map-tile element to remove
131+ * @param {Object } coords - The coordinates to use for removal {col, row, zoom}
132+ */
133+ removeMapTileAt : function ( mapTile , coords ) {
134+ const index = this . _mapTiles . indexOf ( mapTile ) ;
135+ if ( index !== - 1 ) {
136+ this . _mapTiles . splice ( index , 1 ) ;
137+ this . _removeFromTileMapAt ( coords ) ;
138+ // Clean up bidirectional links using current tile reference
139+ if ( mapTile . _tileDiv ) {
140+ mapTile . _tileDiv . _mapTile = null ;
141+ mapTile . _tileDiv = null ;
142+ }
143+ this . _updateBounds ( ) ;
144+ if ( this . _map ) {
145+ this . redraw ( ) ;
146+ }
120147 }
121148 } ,
122149
@@ -271,6 +298,27 @@ export var MapTileLayer = GridLayer.extend({
271298 const tileKey = `${ mapTile . col } :${ mapTile . row } :${ mapTile . zoom } ` ;
272299 delete this . _tileMap [ tileKey ] ;
273300
301+ // Clean up bidirectional links
302+ if ( mapTile . _tileDiv ) {
303+ mapTile . _tileDiv . _mapTile = null ;
304+ mapTile . _tileDiv = null ;
305+ }
306+
307+ // Also remove from pending tiles if it exists there
308+ if ( this . _pendingTiles && this . _pendingTiles [ tileKey ] ) {
309+ delete this . _pendingTiles [ tileKey ] ;
310+ }
311+ } ,
312+
313+ /**
314+ * Removes a tile from the tile map using specific coordinates
315+ * @param {Object } coords - The coordinates {col, row, zoom}
316+ * @private
317+ */
318+ _removeFromTileMapAt : function ( coords ) {
319+ const tileKey = `${ coords . col } :${ coords . row } :${ coords . zoom } ` ;
320+ delete this . _tileMap [ tileKey ] ;
321+
274322 // Also remove from pending tiles if it exists there
275323 if ( this . _pendingTiles && this . _pendingTiles [ tileKey ] ) {
276324 delete this . _pendingTiles [ tileKey ] ;
0 commit comments