From 079ef964ec3b0f68c85d39f59ec3bfe5a5524b94 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 9 Dec 2024 23:49:08 -0500 Subject: [PATCH] Choose a color when adding a dataset to the menu I'm trying to match the legacy color-choosing behavior from before Rapid#1642 (which changed a bunch of things) This code is a bit weird - I don't like it and we should change it... - If adding fbRoads/msBuildings, choose "Rapid magenta". - If adding an Overture dataset, choose "Overture cyan". - If adding an Esri dataset, choose a color based on how many datasets were added already. --- modules/core/RapidSystem.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/core/RapidSystem.js b/modules/core/RapidSystem.js index 0fd331139..c476dbf33 100644 --- a/modules/core/RapidSystem.js +++ b/modules/core/RapidSystem.js @@ -4,6 +4,7 @@ import { Extent } from '@rapid-sdk/math'; import { AbstractSystem } from './AbstractSystem.js'; const RAPID_MAGENTA = '#da26d3'; +const OVERTURE_CYAN = '#00ffff'; const RAPID_COLORS = [ '#ff0000', // red '#ffa500', // orange @@ -53,6 +54,7 @@ export class RapidSystem extends AbstractSystem { this.acceptIDs = new Set(); // Set this.ignoreIDs = new Set(); // Set + this._nextColorIndex = 2; // see note in _datasetsChanged() this._taskExtent = null; this._isTaskBoundsRect = null; this._hadPoweruser = false; // true if the user had poweruser mode at any point in their editing @@ -392,7 +394,24 @@ export class RapidSystem extends AbstractSystem { const enabledIDs = []; for (const [datasetID, dataset] of this.catalog) { - dataset.added = this._addedDatasetIDs.has(datasetID); + // This code is a bit weird - I don't like it and we should change it... + // I'm trying to match the legacy color-choosing behavior from before Rapid#1642 (which changed a bunch of things) + // - If adding fbRoads/msBuildings, choose "Rapid magenta". + // - If adding an Overture dataset, choose "Overture cyan". + // - If adding an Esri dataset, choose a color based on how many datasets were added already. + const wasAdded = dataset.added; + const nowAdded = this._addedDatasetIDs.has(datasetID); + if (!wasAdded && nowAdded && dataset.color === RAPID_MAGENTA) { // being added right now with the default color + if (dataset.categories.has('meta') || dataset.categories.has('microsoft')) { + dataset.color = RAPID_MAGENTA; + } else if (dataset.categories.has('overture')) { + dataset.color = OVERTURE_CYAN; + } else { + dataset.color = RAPID_COLORS[this._nextColorIndex++ % RAPID_COLORS.length]; + } + } + + dataset.added = nowAdded; dataset.enabled = this._enabledDatasetIDs.has(datasetID); if (dataset.added && dataset.enabled) {