function worldMapCoordinates(config = {}, dimensions) {
const {
value = [], title, description, width = dimensions[0]
} = Array.isArray(config) ? {value: config} : config;
const height = dimensions[1];
let [lon, lat] = value;
lon = lon != null ? lon : null;
lat = lat != null ? lat : null;
const formEl = html`<form style="width: ${width}px;"></form>`;
const context = DOM.context2d(width, height);
const canvas = context.canvas;
canvas.style.margin = `-6px 0 ${width > 400 ? -12 : -18}px`;
const projection = config[2]
.precision(0.1)
.fitSize([width, height], { type: "Sphere" }).rotate([-153, 0]);
const path = d3.geoPath(projection, context).pointRadius(2.5);
formEl.append(canvas);
function fillMesh(f) {
context.beginPath();
path(f);
context.fillStyle = color(f.properties.zone);
context.fill();
}
function draw() {
context.fillStyle = "#fff";
context.fillRect(0, 0, width, height);
if (!utctoggle) {
context.beginPath(); path({type: "Sphere"});
context.fillStyle = colors.ocean; context.fill();
if (dectoggle) {
deczones.map((f, i) => {
context.beginPath();
path(f);
context.fillStyle = hsla10[i];
context.fill();
})
}
}
if (utctoggle) {
zones.map(f => fillMesh(f))
}
context.beginPath();
path(land);
if (!utctoggle) {
context.fillStyle = colors.land;
context.fill();
}
context.strokeStyle = `#888`;
context.stroke();
if (border) {
context.beginPath();
path(borders);
context.lineWidth = 1.25;
context.strokeStyle = `#888`;
context.stroke();
}
if (utctoggle) {
context.beginPath();
path(mesh);
context.lineWidth = 1.25;
context.strokeStyle = `#aaa`;
context.stroke();
}
if (dectoggle) {
context.beginPath();
path(graticule);
context.lineWidth = 1.25;
context.strokeStyle = `#000`;
context.stroke();
// context.font = "bold 24px serif";
// context.fillStyle = "#000";
// d3.range(-2, 342 + 1, 36).map((x, i) => context.fillText(i, projection([x, 90])[0] - (width < 400) * 4, 40 - (width < 400) * 20));
// context.fillStyle = "#000";
// d3.range(-2, 342 + 1, 36).map((x, i) => context.fillText(i, projection([x, 90])[0] - (width < 400) * 4, 578 - (width < 400) * 281 - (width < 800) * 120));
// context.font = width < 760 ? "12px serif" : "21px serif";
// context.fillStyle = `#000`;
// d3.range(-1.5, 342 + 1, 36).map(x => context.fillText(long2zone(x), ...projection([x, 27.5])));
// d3.range(-1.5, 342 + 1, 36).map(x => context.fillText(long2zone(x), ...projection([x, -48])));
// d3.range(-18, 336 + 1, 36).map(x => context.fillText(formatLongitude(x), ...projection([x, 90])));
// d3.range(-18, 336 + 1, 36).map(x => context.fillText(formatLongitude(x), ...projection([x, -90])));
}
if (suntoggle) {
context.beginPath();
path(night);
context.fillStyle = "rgba(0,0,255,0.4)";
context.fill();
context.beginPath();
path.pointRadius(28);
path({type: "Point", coordinates: sun});
context.strokeStyle = "#0009";
context.fillStyle = "#ff0b";
context.lineWidth = 1;
context.stroke();
context.fill();
}
}
draw();
return formEl;
}