Skip to content

Commit

Permalink
Choose a color when adding a dataset to the menu
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bhousel committed Dec 10, 2024
1 parent 15f702c commit c7797c4
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion modules/core/RapidSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,6 +54,7 @@ export class RapidSystem extends AbstractSystem {
this.acceptIDs = new Set(); // Set<dataID>
this.ignoreIDs = new Set(); // Set<dataID>

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
Expand Down Expand Up @@ -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, but I'm trying to match the legacy color-picking behavior
// from before Rapid#1642 (which changed a bunch of things)
// If adding a Meta dataset, choose rapid magenta..
// If adding an Overture dataset, choose overture cyan..
// If adding an Esri dataset, pick a color based on the index of the added array..
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) {
Expand Down

0 comments on commit c7797c4

Please sign in to comment.