Reduce code deduplication

We can request tilecombine even if client needs actually one tile only.

Change-Id: Id897f219885be4cb93635d727d4ee871a4b55cb7
This commit is contained in:
Tamás Zolnai 2018-06-11 16:26:09 +02:00
parent 1f2982cdc5
commit 30f4cafd37

View file

@ -971,53 +971,33 @@ L.GridLayer = L.Layer.extend({
var twips, msg;
for (var r = 0; r < rectangles.length; ++r) {
rectQueue = rectangles[r];
if (rectQueue.length === 1) {
// only one tile here
coords = rectQueue[0];
key = this._tileCoordsToKey(coords);
var tilePositionsX = '';
var tilePositionsY = '';
for (i = 0; i < rectQueue.length; i++) {
coords = rectQueue[i];
twips = this._coordsToTwips(coords);
msg = 'tile ' +
'part=' + coords.part + ' ' +
'width=' + this._tileWidthPx + ' ' +
'height=' + this._tileHeightPx + ' ' +
'tileposx=' + twips.x + ' ' +
'tileposy=' + twips.y + ' ' +
'tilewidth=' + this._tileWidthTwips + ' ' +
'tileheight=' + this._tileHeightTwips;
this._map._socket.sendMessage(msg, key);
}
else {
// more tiles, use tilecombine
var tilePositionsX = '';
var tilePositionsY = '';
for (i = 0; i < rectQueue.length; i++) {
coords = rectQueue[i];
twips = this._coordsToTwips(coords);
if (tilePositionsX !== '') {
tilePositionsX += ',';
}
tilePositionsX += twips.x;
if (tilePositionsY !== '') {
tilePositionsY += ',';
}
tilePositionsY += twips.y;
if (tilePositionsX !== '') {
tilePositionsX += ',';
}
tilePositionsX += twips.x;
twips = this._coordsToTwips(coords);
msg = 'tilecombine ' +
'part=' + coords.part + ' ' +
'width=' + this._tileWidthPx + ' ' +
'height=' + this._tileHeightPx + ' ' +
'tileposx=' + tilePositionsX + ' ' +
'tileposy=' + tilePositionsY + ' ' +
'tilewidth=' + this._tileWidthTwips + ' ' +
'tileheight=' + this._tileHeightTwips;
this._map._socket.sendMessage(msg, '');
if (tilePositionsY !== '') {
tilePositionsY += ',';
}
tilePositionsY += twips.y;
}
twips = this._coordsToTwips(coords);
msg = 'tilecombine ' +
'part=' + coords.part + ' ' +
'width=' + this._tileWidthPx + ' ' +
'height=' + this._tileHeightPx + ' ' +
'tileposx=' + tilePositionsX + ' ' +
'tileposy=' + tilePositionsY + ' ' +
'tilewidth=' + this._tileWidthTwips + ' ' +
'tileheight=' + this._tileHeightTwips;
this._map._socket.sendMessage(msg, '');
}
},