Public
Edited
Nov 17, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof tNum = Inputs.range([0, badTriangles.length-1], {value: 0, step: 1, label: "Gain"})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
let p = [];
for (let i=0; i<100; i++) {
p.push(newreturn(geojson))
}
return p
}
Insert cell
lng = 180
Insert cell
newlng = {
const prevLng = 180;
let newlng = -179;
newlng += newlng - prevLng > 180 ? -360 :
prevLng - newlng > 180 ? 360 : 0;

return newlng
}
Insert cell
Insert cell
{
const polygon = feature.geometry.coordinates;
const list = polygon[0];
let polygonList = [];
let newPolygon = [];
newPolygon.push(list[0]);
let compareValue = list[0];
let dynamicCompareValue = list[0];
for (let i=1; i<list.length; i++) {
const current = list[i];
const previous = list[i-1];
//if difference between this point and previous greater than 180, create new polygon
if (Math.abs(current[0] - dynamicCompareValue[0]) > 180) {
newPolygon.push([...compareValue]);
//push polygon we had been building into polygon list
polygonList.push(newPolygon);

//new compare value is current test point
dynamicCompareValue = [...current];

//change current test point to be < 180 degrees from very first point lon
let alterPoint = [...current];
let alterLng = alterPoint[0];
alterLng += alterLng - compareValue[0] > 180 ? -360 :
compareValue[0] - alterLng > 180 ? 360 : 0;

//new polygon starts with very first point and new compare point
newPolygon = [[...compareValue], [alterLng, dynamicCompareValue[1]]];
} else {
let alterPoint = [...current];
let alterLng = alterPoint[0];
alterLng += alterLng - compareValue[0] > 180 ? -360 :
compareValue[0] - alterLng > 180 ? 360 : 0;

alterPoint[0] = alterLng;
newPolygon.push(alterPoint);
}
}

if (newPolygon.length > 2) {
polygonList.push(newPolygon);
}

let fc = {
"type":"FeatureCollection",
"features":[]
}

for (let i=0; i<polygonList.length; i++) {
let feature = {
"type":"Feature",
"properties":{},
"geometry":{
"type":"Polygon",
"coordinates":[polygonList[i]]
}
}

fc.features.push(feature);
}

console.log(fc);
return fc;
}
Insert cell
{
// fetch("https://api.mapbox.com/v4/mbxsolutions.meteo_france_v2/5/13/11.vector.pbf?access_token=pk.eyJ1IjoibWJ4c29sdXRpb25zIiwiYSI6ImNsanlpZWd1YjA0am8zZXFndXk5ZTBjaWEifQ.dOzecVKbvgrdZ_WIR6qC3A").then(response => {
// if (!response.ok) {
// return Promise.resolve(null);
// throw new Error("ahhh");
// }

// return response.json();
// })
// .then(data => {
// if (data === null) {
// console.log("wazs null");
// }
// })
// .catch(error => {
// console.log("error", error);
// })

const req = new XMLHttpRequest();
req.open('GET', "https://api.mapbox.com/v4/mbxsolutions.meteo_france_v2/5/13/11.vector.pbf?access_token=pk.eyJ1IjoibWJ4c29sdXRpb25zIiwiYSI6ImNsanlpZWd1YjA0am8zZXFndXk5ZTBjaWEifQ.dOzecVKbvgrdZ_WIR6qC3A", true);
req.onerror = () => {
console.log(req.statusText);
}

req.onload = () => {
console.log("load", req.statusText);
throw new Error("ahhh");
}

req.send();
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more