Use hex color format; add color picker input
This commit is contained in:
parent
26c5b56d58
commit
54620a68fc
20
main.js
20
main.js
|
@ -154,16 +154,16 @@ const customLayerDiv = document.createElement("div");
|
||||||
customLayerDiv.innerHTML = `
|
customLayerDiv.innerHTML = `
|
||||||
<details>
|
<details>
|
||||||
<summary>Custom</summary>
|
<summary>Custom</summary>
|
||||||
<label>Layer Name: <input name="label"></label><br>
|
<label>Layer Name: <input type="text"></label><br>
|
||||||
<label>Layer URL: <input name="source"></label><br>
|
<label>Layer URL: <input type="url"></label><br>
|
||||||
<label>Color (optional): <input name="color"></label><br>
|
<label>Color (optional): <input type="color"></label><br>
|
||||||
<button>Add</button>
|
<button>Add</button>
|
||||||
<small>(must be in GeoJSON format)</small>
|
<small>(must be in GeoJSON format)</small>
|
||||||
<ul></ul>
|
<ul></ul>
|
||||||
</details>`;
|
</details>`;
|
||||||
const labelInput = customLayerDiv.querySelector('input[name=label]');
|
const labelInput = customLayerDiv.querySelector('input[type=text]');
|
||||||
const sourceInput = customLayerDiv.querySelector('input[name=source]');
|
const sourceInput = customLayerDiv.querySelector('input[type=url]');
|
||||||
const colorInput = customLayerDiv.querySelector('input[name=color]');
|
const colorInput = customLayerDiv.querySelector('input[type=color]');
|
||||||
|
|
||||||
customLayerDiv.querySelector("button").addEventListener("click", function(){
|
customLayerDiv.querySelector("button").addEventListener("click", function(){
|
||||||
if (!sourceInput.value.toLowerCase().endsWith(".geojson")) {
|
if (!sourceInput.value.toLowerCase().endsWith(".geojson")) {
|
||||||
|
@ -171,7 +171,7 @@ customLayerDiv.querySelector("button").addEventListener("click", function(){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newCustomLayer(labelInput.value, sourceInput.value, colorInput.value);
|
newCustomLayer(labelInput.value, sourceInput.value, colorInput.value.substring(1));
|
||||||
});
|
});
|
||||||
document.querySelector("aside").appendChild(customLayerDiv);
|
document.querySelector("aside").appendChild(customLayerDiv);
|
||||||
|
|
||||||
|
@ -192,7 +192,11 @@ let colors = [
|
||||||
function newCustomLayer(name, sourceURL, colorString) {
|
function newCustomLayer(name, sourceURL, colorString) {
|
||||||
let color;
|
let color;
|
||||||
if (colorString) {
|
if (colorString) {
|
||||||
color = colorString.split(' ').map(Number);
|
color = [
|
||||||
|
parseInt(colorString.substr(0,2),16),
|
||||||
|
parseInt(colorString.substr(2,2),16),
|
||||||
|
parseInt(colorString.substr(4,2),16),
|
||||||
|
];
|
||||||
if (color.length != 3 || color.some(Number.isNaN)) {
|
if (color.length != 3 || color.some(Number.isNaN)) {
|
||||||
alert("Invalid color provided; using random color instead.");
|
alert("Invalid color provided; using random color instead.");
|
||||||
color = null;
|
color = null;
|
||||||
|
|
Loading…
Reference in a new issue