mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-02-16 17:30:47 +01:00
Clean up Renderer (still uses bluejay)
This commit is contained in:
parent
f236f95383
commit
bf8ebfd3df
106
src/Renderer.js
106
src/Renderer.js
@ -12,7 +12,6 @@ const simplify = require('simplify-js');
|
|||||||
const Canvas = require('./Canvas');
|
const Canvas = require('./Canvas');
|
||||||
const LabelBuffer = require('./LabelBuffer');
|
const LabelBuffer = require('./LabelBuffer');
|
||||||
const Styler = require('./Styler');
|
const Styler = require('./Styler');
|
||||||
const Tile = require('./Tile');
|
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ class Renderer {
|
|||||||
let ref;
|
let ref;
|
||||||
const color = ((ref = this.styler.styleById['background']) !== null ?
|
const color = ((ref = this.styler.styleById['background']) !== null ?
|
||||||
ref.paint['background-color']
|
ref.paint['background-color']
|
||||||
:
|
:
|
||||||
void 0
|
void 0
|
||||||
);
|
);
|
||||||
if (color) {
|
if (color) {
|
||||||
@ -110,11 +109,11 @@ class Renderer {
|
|||||||
|
|
||||||
_getTile(tile) {
|
_getTile(tile) {
|
||||||
return this.tileSource
|
return this.tileSource
|
||||||
.getTile(tile.xyz.z, tile.xyz.x, tile.xyz.y)
|
.getTile(tile.xyz.z, tile.xyz.x, tile.xyz.y)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
tile.data = data;
|
tile.data = data;
|
||||||
return tile;
|
return tile;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_getTileFeatures(tile, zoom) {
|
_getTileFeatures(tile, zoom) {
|
||||||
@ -143,8 +142,7 @@ class Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_renderTiles(tiles) {
|
_renderTiles(tiles) {
|
||||||
var drawn, feature, i, j, k, l, label, labels, layer, layerId, len, len1, len2, len3, ref, ref1, tile;
|
var feature, i, j, k, labels, layer, layerId, len, len1, len2, ref, ref1, tile;
|
||||||
drawn = {};
|
|
||||||
labels = [];
|
labels = [];
|
||||||
ref = this._generateDrawOrder(tiles[0].xyz.z);
|
ref = this._generateDrawOrder(tiles[0].xyz.z);
|
||||||
for (i = 0, len = ref.length; i < len; i++) {
|
for (i = 0, len = ref.length; i < len; i++) {
|
||||||
@ -204,49 +202,53 @@ class Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (feature.style.type) {
|
switch (feature.style.type) {
|
||||||
case 'line':
|
case 'line': {
|
||||||
let width = feature.style.paint['line-width'];
|
let width = feature.style.paint['line-width'];
|
||||||
if (width instanceof Object) {
|
if (width instanceof Object) {
|
||||||
// TODO: apply the correct zoom based value
|
// TODO: apply the correct zoom based value
|
||||||
width = width.stops[0][1];
|
width = width.stops[0][1];
|
||||||
}
|
}
|
||||||
points = this._scaleAndReduce(tile, feature, feature.points, scale);
|
points = this._scaleAndReduce(tile, feature, feature.points, scale);
|
||||||
if (points.length) {
|
if (points.length) {
|
||||||
this.canvas.polyline(points, feature.color, width);
|
this.canvas.polyline(points, feature.color, width);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'fill':
|
}
|
||||||
points = feature.points.map((p) => {
|
case 'fill': {
|
||||||
return this._scaleAndReduce(tile, feature, p, scale, false);
|
points = feature.points.map((p) => {
|
||||||
});
|
return this._scaleAndReduce(tile, feature, p, scale, false);
|
||||||
this.canvas.polygon(points, feature.color);
|
});
|
||||||
break;
|
this.canvas.polygon(points, feature.color);
|
||||||
case 'symbol':
|
break;
|
||||||
const text = feature.label || (genericSymbol = config.poiMarker);
|
}
|
||||||
|
case 'symbol': {
|
||||||
if (this._seen[text] && !genericSymbol) {
|
const text = feature.label || (genericSymbol = config.poiMarker);
|
||||||
return false;
|
|
||||||
}
|
if (this._seen[text] && !genericSymbol) {
|
||||||
|
return false;
|
||||||
placed = false;
|
}
|
||||||
const points2 = this._scaleAndReduce(tile, feature, feature.points, scale);
|
|
||||||
for (const point of points2) {
|
placed = false;
|
||||||
let ref1, ref2;
|
const points2 = this._scaleAndReduce(tile, feature, feature.points, scale);
|
||||||
const x = point.x - text.length;
|
for (const point of points2) {
|
||||||
const margin = ((ref1 = config.layers[feature.layer]) != null ? ref1.margin : void 0) || config.labelMargin;
|
let ref1, ref2;
|
||||||
if (this.labelBuffer.writeIfPossible(text, x, point.y, feature, margin)) {
|
const x = point.x - text.length;
|
||||||
this.canvas.text(text, x, point.y, feature.color);
|
const margin = ((ref1 = config.layers[feature.layer]) != null ? ref1.margin : void 0) || config.labelMargin;
|
||||||
placed = true;
|
if (this.labelBuffer.writeIfPossible(text, x, point.y, feature, margin)) {
|
||||||
break;
|
this.canvas.text(text, x, point.y, feature.color);
|
||||||
} else if (((ref2 = config.layers[feature.layer]) != null ? ref2.cluster : void 0) && this.labelBuffer.writeIfPossible(config.poiMarker, point.x, point.y, feature, 3)) {
|
placed = true;
|
||||||
this.canvas.text(config.poiMarker, point.x, point.y, feature.color);
|
break;
|
||||||
placed = true;
|
} else if (((ref2 = config.layers[feature.layer]) != null ? ref2.cluster : void 0) && this.labelBuffer.writeIfPossible(config.poiMarker, point.x, point.y, feature, 3)) {
|
||||||
break;
|
this.canvas.text(config.poiMarker, point.x, point.y, feature.color);
|
||||||
}
|
placed = true;
|
||||||
}
|
break;
|
||||||
if (placed) {
|
|
||||||
this._seen[text] = true;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (placed) {
|
||||||
|
this._seen[text] = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -324,7 +326,7 @@ class Renderer {
|
|||||||
'road_label',
|
'road_label',
|
||||||
'housenum_label',
|
'housenum_label',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user