Skip to content

Commit 0cac899

Browse files
committed
in progress work on map-tile testing
1 parent 39eae4c commit 0cac899

24 files changed

+973
-10
lines changed

src/map-tile.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export class HTMLTileElement extends HTMLElement {
1717
return +(this.hasAttribute('row') ? this.getAttribute('row') : 0);
1818
}
1919
set row(val) {
20+
if (this.#hasConnected) {
21+
return;
22+
}
2023
var parsedVal = parseInt(val, 10);
2124
if (!isNaN(parsedVal)) {
2225
this.setAttribute('row', parsedVal);
@@ -26,6 +29,9 @@ export class HTMLTileElement extends HTMLElement {
2629
return +(this.hasAttribute('col') ? this.getAttribute('col') : 0);
2730
}
2831
set col(val) {
32+
if (this.#hasConnected) {
33+
return;
34+
}
2935
var parsedVal = parseInt(val, 10);
3036
if (!isNaN(parsedVal)) {
3137
this.setAttribute('col', parsedVal);
@@ -58,6 +64,9 @@ export class HTMLTileElement extends HTMLElement {
5864
}
5965
}
6066
set zoom(val) {
67+
if (this.#hasConnected) {
68+
return;
69+
}
6170
var parsedVal = parseInt(val, 10);
6271
if (!isNaN(parsedVal) && parsedVal >= 0 && parsedVal <= 25) {
6372
this.setAttribute('zoom', parsedVal);
@@ -170,10 +179,16 @@ export class HTMLTileElement extends HTMLElement {
170179
attributeChangedCallback(name, oldValue, newValue) {
171180
if (this.#hasConnected /* jshint ignore:line */) {
172181
switch (name) {
173-
case 'src':
174182
case 'row':
175183
case 'col':
176184
case 'zoom':
185+
// Prevent changes to row, col, and zoom after initialization
186+
if (oldValue !== newValue) {
187+
this.setAttribute(name, oldValue);
188+
return;
189+
}
190+
break;
191+
case 'src':
177192
if (oldValue !== newValue) {
178193
// If we've already calculated an extent, recalculate it
179194
if (this._extent) {
@@ -182,7 +197,7 @@ export class HTMLTileElement extends HTMLElement {
182197

183198
// If this tile is connected to a tile layer, update it
184199
if (this._tileLayer) {
185-
// Remove and re-add to update the tile's position
200+
// For src changes, normal removal works since coordinates haven't changed
186201
this._tileLayer.removeMapTile(this);
187202
this._tileLayer.addMapTile(this);
188203
}

src/mapml/layers/MapTileLayer.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)