Skip to content

Commit

Permalink
Extract colors; disable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jleedev committed Sep 23, 2024
1 parent 607eeff commit 1394349
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/americana.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "maplibre-gl/dist/maplibre-gl.css";
import * as search from "./search.js";

import LegendControl from "./js/legend_control.js";
import { HillshadeControl } from "./js/icon_control.js";
import { HillshadeControl } from "./js/hillshade_control.js";
import * as LegendConfig from "./js/legend_config.js";
import SampleControl from "openmapsamples-maplibre/OpenMapSamplesControl.js";
import { default as OpenMapTilesSamples } from "openmapsamples/samples/OpenMapTiles/index.js";
Expand Down
3 changes: 3 additions & 0 deletions src/constants/color.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const backgroundFill = `hsl(30, 44%, 96%)`;
export const backgroundFillTranslucent = `hsla(30, 44%, 96%, 0.8)`;

export const hillshadeShadow = "hsla(30, 14%, 63%, 1)";
export const hillshadeHighlight = "hsla(30, 44%, 99%, 1)";

export const waterFill = "hsl(211, 50%, 85%)";
export const waterFillTranslucent = "hsla(211, 50%, 85%, 0.5)";
export const waterIntermittentFill = "hsla(211, 60%, 85%, 0.3)";
Expand Down
22 changes: 14 additions & 8 deletions src/js/icon_control.js → src/js/hillshade_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ export class HillshadeControl {
this._layerId = layerId;
}

_onClick = () => {
_updateButton() {
if (this._map.getLayoutProperty(this._layerId, "visibility") == "none") {
this._map.setLayoutProperty(this._layerId, "visibility", "visible");
this._button.classList.add("maplibregl-ctrl-terrain-enabled");
this._button.title = "Disable terrain";
} else {
this._map.setLayoutProperty(this._layerId, "visibility", "none");
this._button.classList.remove("maplibregl-ctrl-terrain-enabled");
this._button.title = "Enable terrain";
} else {
this._button.classList.add("maplibregl-ctrl-terrain-enabled");
this._button.title = "Disable terrain";
}
}

_onClick = () => {
const newValue =
this._map.getLayoutProperty(this._layerId, "visibility") == "none"
? "visible"
: "none";
this._map.setLayoutProperty(this._layerId, "visibility", newValue);
this._updateButton();
};

onAdd(map) {
Expand All @@ -23,8 +30,7 @@ export class HillshadeControl {

this._button = document.createElement("button");
this._button.className = "maplibregl-ctrl-terrain";
this._button.classList.add("maplibregl-ctrl-terrain-enabled");
this._button.title = "Disable terrain";
this._updateButton();
this._button.addEventListener("click", this._onClick);
this._container.append(this._button);

Expand Down
9 changes: 7 additions & 2 deletions src/layer/hillshade.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { hillshadeShadow, hillshadeHighlight } from "../constants/color";

export const hillshading = {
id: "hillshading",
type: "hillshade",
source: "dem",
layout: {
visibility: "none",
},
paint: {
"hillshade-exaggeration": [
"interpolate",
Expand All @@ -12,7 +17,7 @@ export const hillshading = {
17,
0.1,
],
"hillshade-shadow-color": "hsla(30, 14%, 63%, 1)",
"hillshade-highlight-color": "hsla(30, 44%, 99%, 1)",
"hillshade-shadow-color": hillshadeShadow,
"hillshade-highlight-color": hillshadeHighlight,
},
};

0 comments on commit 1394349

Please sign in to comment.