refactor: lake group detection and features rendering

This commit is contained in:
max 2022-07-23 19:53:03 +03:00
parent 4a15dc3243
commit 4b874246e3
10 changed files with 52 additions and 60 deletions

View file

@ -4,7 +4,9 @@ import {simplify} from "scripts/simplify";
import {filterOutOfCanvasPoints} from "utils/lineUtils";
import {round} from "utils/stringUtils";
export function drawCoastline(vertices: IGraphVertices, features: TPackFeatures) {
export function drawFeatures() {
/* uses */ const {vertices, features} = pack;
const landMask = defs.select("#land");
const waterMask = defs.select("#water");
@ -12,8 +14,7 @@ export function drawCoastline(vertices: IGraphVertices, features: TPackFeatures)
const SIMPLIFICATION_TOLERANCE = 0.3; // px
for (const feature of features) {
if (!feature) continue;
if (feature.type === "ocean") continue;
if (!feature || feature.type === "ocean") continue;
const points = feature.vertices.map(vertex => vertices.p[vertex]);
const filteredPoints = filterOutOfCanvasPoints(points);
@ -28,7 +29,7 @@ export function drawCoastline(vertices: IGraphVertices, features: TPackFeatures)
.attr("id", "land_" + feature.i);
lakes
.select("#freshwater")
.select(`#${feature.group}`)
.append("path")
.attr("d", path)
.attr("id", "lake_" + feature.i)
@ -46,9 +47,8 @@ export function drawCoastline(vertices: IGraphVertices, features: TPackFeatures)
.attr("fill", "black")
.attr("id", "water_" + feature.i);
const group = feature.group === "lake_island" ? "lake_island" : "sea_island";
coastline
.select("#" + group)
.select(`#${feature.group}`)
.append("path")
.attr("d", path)
.attr("id", "island_" + feature.i)

View file

@ -3,7 +3,7 @@ import {TIME} from "config/logging";
import {drawBiomes} from "./drawBiomes";
import {drawBorders} from "./drawBorders";
import {drawCells} from "./drawCells";
import {drawCoastline} from "./drawCoastline";
import {drawFeatures} from "./drawFeatures";
import {drawCoordinates} from "./drawCoordinates";
import {drawCultures} from "./drawCultures";
import {drawEmblems} from "./drawEmblems";
@ -24,10 +24,10 @@ const layerRenderersMap = {
biomes: drawBiomes,
borders: drawBorders,
cells: drawCells,
coastline: drawCoastline,
coordinates: drawCoordinates,
cultures: drawCultures,
emblems: drawEmblems,
features: drawFeatures,
grid: drawGrid,
heightmap: drawHeightmap,
ice: drawIce,