@@ -27,13 +27,26 @@ export var MapTileLayer = GridLayer.extend({
27
27
GridLayer . prototype . initialize . call ( this , options ) ;
28
28
this . _mapTiles = options . mapTiles || [ ] ;
29
29
this . _tileMap = { } ;
30
+ this . _pendingTiles = { } ;
30
31
this . _buildTileMap ( ) ;
31
-
32
+ this . _container = DomUtil . create ( 'div' , 'leaflet-layer' ) ;
33
+ DomUtil . addClass ( this . _container , 'mapml-static-tile-container' ) ;
32
34
// Store bounds for visibility checks
33
35
// this.layerBounds = this._computeLayerBounds();
34
36
// this.zoomBounds = this._computeZoomBounds();
35
37
} ,
36
38
39
+ onAdd : function ( map ) {
40
+ this . options . pane . appendChild ( this . _container ) ;
41
+ // Call the parent method
42
+ GridLayer . prototype . onAdd . call ( this , map ) ;
43
+ } ,
44
+ onRemove : function ( map ) {
45
+ // Clean up pending tiles
46
+ this . _pendingTiles = { } ;
47
+ DomUtil . remove ( this . _container ) ;
48
+ } ,
49
+
37
50
/**
38
51
* Adds a map-tile element to the layer
39
52
* @param {HTMLTileElement } mapTile - The map-tile element to add
@@ -91,14 +104,18 @@ export var MapTileLayer = GridLayer.extend({
91
104
/**
92
105
* Overrides GridLayer createTile to use map-tile elements
93
106
* @param {Object } coords - Tile coordinates
107
+ * @param {Function } done - Callback to be called when the tile is ready, with error and tile element params
94
108
* @returns {HTMLElement } - The created tile element
95
109
*/
96
- createTile : function ( coords ) {
110
+ createTile : function ( coords , done ) {
97
111
const tileKey = this . _tileCoordsToKey ( coords ) ;
98
112
const tileSize = this . getTileSize ( ) ;
99
113
100
114
// Create container element
101
115
const tileElement = document . createElement ( 'div' ) ;
116
+ tileElement . setAttribute ( 'col' , coords . x ) ;
117
+ tileElement . setAttribute ( 'row' , coords . y ) ;
118
+ tileElement . setAttribute ( 'zoom' , coords . z ) ;
102
119
DomUtil . addClass ( tileElement , 'leaflet-tile' ) ;
103
120
104
121
// Set size
@@ -116,11 +133,30 @@ export var MapTileLayer = GridLayer.extend({
116
133
img . height = tileSize . y ;
117
134
img . alt = '' ;
118
135
img . setAttribute ( 'role' , 'presentation' ) ;
136
+ // bidirectional link map-tile element and rendered div
137
+ tileElement . _mapTile = matchingTile ;
138
+ matchingTile . _tileDiv = tileElement ;
119
139
120
140
tileElement . appendChild ( img ) ;
121
141
122
- // This is needed for Leaflet to properly handle the tile
123
- this . _tileReady ( coords , null , tileElement ) ;
142
+ // Add the loaded class manually to ensure tile is visible
143
+ DomUtil . addClass ( tileElement , 'leaflet-tile-loaded' ) ;
144
+
145
+ // Call the done callback to signal that the tile is ready
146
+ done ( null , tileElement ) ;
147
+ } else {
148
+ // The tile might be added later, register a pending tile
149
+ if ( ! this . _pendingTiles ) {
150
+ this . _pendingTiles = { } ;
151
+ }
152
+
153
+ // Store the tile element and done callback for later update
154
+ this . _pendingTiles [ tileKey ] = {
155
+ element : tileElement ,
156
+ done : done
157
+ } ;
158
+
159
+ // Don't call done yet - we'll call it when the map-tile is added
124
160
}
125
161
126
162
return tileElement ;
@@ -145,8 +181,40 @@ export var MapTileLayer = GridLayer.extend({
145
181
_addToTileMap : function ( mapTile ) {
146
182
const tileKey = `${ mapTile . col } :${ mapTile . row } :${ mapTile . zoom } ` ;
147
183
this . _tileMap [ tileKey ] = mapTile ;
148
- } ,
149
184
185
+ // Check if this tile was requested but not available at that time
186
+ if ( this . _pendingTiles && this . _pendingTiles [ tileKey ] ) {
187
+ const pendingTile = this . _pendingTiles [ tileKey ] ;
188
+ const tileElement = pendingTile . element ;
189
+ const doneCallback = pendingTile . done ;
190
+
191
+ // Create and append the image to the tile
192
+ const tileSize = this . getTileSize ( ) ;
193
+ const img = document . createElement ( 'img' ) ;
194
+ img . src = mapTile . src ;
195
+ img . width = tileSize . x ;
196
+ img . height = tileSize . y ;
197
+ img . alt = '' ;
198
+ img . setAttribute ( 'role' , 'presentation' ) ;
199
+
200
+ // bidirectional link map-tile element and rendered div
201
+ tileElement . _mapTile = mapTile ;
202
+ mapTile . _tileDiv = tileElement ;
203
+
204
+ tileElement . appendChild ( img ) ;
205
+
206
+ // Add the loaded class manually to ensure tile is visible
207
+ DomUtil . addClass ( tileElement , 'leaflet-tile-loaded' ) ;
208
+
209
+ // Call the done callback to signal that the tile is now ready
210
+ if ( doneCallback ) {
211
+ doneCallback ( null , tileElement ) ;
212
+ }
213
+
214
+ // Remove from pending tiles
215
+ delete this . _pendingTiles [ tileKey ] ;
216
+ }
217
+ } ,
150
218
/**
151
219
* Removes a map-tile element from the tile map
152
220
* @param {HTMLTileElement } mapTile - The map-tile element to remove
@@ -155,6 +223,11 @@ export var MapTileLayer = GridLayer.extend({
155
223
_removeFromTileMap : function ( mapTile ) {
156
224
const tileKey = `${ mapTile . col } :${ mapTile . row } :${ mapTile . zoom } ` ;
157
225
delete this . _tileMap [ tileKey ] ;
226
+
227
+ // Also remove from pending tiles if it exists there
228
+ if ( this . _pendingTiles && this . _pendingTiles [ tileKey ] ) {
229
+ delete this . _pendingTiles [ tileKey ] ;
230
+ }
158
231
} ,
159
232
160
233
/**
0 commit comments