mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-06 03:14:00 +00:00
refactor(installations): make model engine neutral
This commit is contained in:
1 parent
5dd05a4a81
commit
c58bc9864b
4 files changed
+52
-8
No files matched your search
@@ -1257,6 +1257,7 @@
|
|||||||
"src/layers/installations/source.js",
|
"src/layers/installations/source.js",
|
||||||
"src/layers/installations/state.js",
|
"src/layers/installations/state.js",
|
||||||
"src/layers/installations/viewport.js",
|
"src/layers/installations/viewport.js",
|
||||||
|
"src/layers/shared/color.js",
|
||||||
"src/data/inputOwnership.js",
|
"src/data/inputOwnership.js",
|
||||||
"src/data/tomtomTiles.js",
|
"src/data/tomtomTiles.js",
|
||||||
"src/sources/capability.js",
|
"src/sources/capability.js",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { installationResponseSaturated } from './source.js';
|
import { installationResponseSaturated } from './source.js';
|
||||||
import * as Cesium from 'cesium';
|
import * as geo from '../../geo/index.js';
|
||||||
|
import { rgbaFromCss } from '../shared/color.js';
|
||||||
import {
|
import {
|
||||||
EARTH_MEAN_RADIUS_M,
|
EARTH_MEAN_RADIUS_M,
|
||||||
COLOR_BY_CLASS,
|
COLOR_BY_CLASS,
|
||||||
@@ -18,8 +19,8 @@ export function createModel({ state: layerState, services, parts, source }) {
|
|||||||
latitudeBDeg,
|
latitudeBDeg,
|
||||||
longitudeBDeg,
|
longitudeBDeg,
|
||||||
) {
|
) {
|
||||||
const latitudeBRad = Cesium.Math.toRadians(latitudeBDeg);
|
const latitudeBRad = geo.math.toRadians(latitudeBDeg);
|
||||||
const longitudeBRad = Cesium.Math.toRadians(longitudeBDeg);
|
const longitudeBRad = geo.math.toRadians(longitudeBDeg);
|
||||||
const latitudeDelta = latitudeBRad - latitudeARad;
|
const latitudeDelta = latitudeBRad - latitudeARad;
|
||||||
const longitudeDelta = Math.atan2(
|
const longitudeDelta = Math.atan2(
|
||||||
Math.sin(longitudeBRad - longitudeARad),
|
Math.sin(longitudeBRad - longitudeARad),
|
||||||
@@ -39,9 +40,7 @@ export function createModel({ state: layerState, services, parts, source }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function colorFor(record) {
|
function colorFor(record) {
|
||||||
return Cesium.Color.fromCssColorString(
|
return rgbaFromCss(COLOR_BY_CLASS[record.class] || '#9ca6b0');
|
||||||
COLOR_BY_CLASS[record.class] || '#9ca6b0',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import test from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import * as geo from '../../geo/index.js';
|
||||||
|
import { createModel } from './model.js';
|
||||||
|
|
||||||
|
const model = createModel({ state: {}, services: {}, parts: {}, source: {} });
|
||||||
|
|
||||||
|
test('installation distance prefilter wraps the date line and stays conservative at high latitudes', () => {
|
||||||
|
const from = geo.math.toRadians(179.8);
|
||||||
|
const distance = model.approximateSurfaceDistanceM(
|
||||||
|
geo.math.toRadians(70),
|
||||||
|
from,
|
||||||
|
69.9,
|
||||||
|
-179.8,
|
||||||
|
);
|
||||||
|
const start = geo.cartographic.fromDegrees(179.8, 70);
|
||||||
|
const end = geo.cartographic.fromDegrees(-179.8, 69.9);
|
||||||
|
const exact = geo.ellipsoidGeodesic.create(start, end).surfaceDistance;
|
||||||
|
|
||||||
|
assert.ok(distance > 0 && distance < 50_000);
|
||||||
|
assert.ok(distance >= exact * 0.99);
|
||||||
|
assert.ok(distance <= exact * 1.03);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('installation model returns engine-neutral palette and source presentation', () => {
|
||||||
|
const record = {
|
||||||
|
class: 'military_land',
|
||||||
|
sources: [
|
||||||
|
{ name: 'OpenStreetMap', id: 'way:1' },
|
||||||
|
{ name: 'OpenStreetMap', id: 'relation:2' },
|
||||||
|
{ name: 'Bundled registry', id: 'registry:3' },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.deepEqual(model.colorFor(record).rgba(), [
|
||||||
|
156 / 255,
|
||||||
|
166 / 255,
|
||||||
|
176 / 255,
|
||||||
|
1,
|
||||||
|
]);
|
||||||
|
assert.equal(
|
||||||
|
model.installationSourceLabel(record),
|
||||||
|
'OpenStreetMap + Bundled registry',
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import * as Cesium from 'cesium';
|
|
||||||
import * as geo from '../../geo/index.js';
|
import * as geo from '../../geo/index.js';
|
||||||
|
|
||||||
export function createState({ services }) {
|
export function createState({ services }) {
|
||||||
@@ -6,7 +5,7 @@ export function createState({ services }) {
|
|||||||
|
|
||||||
state.distanceEndpointScratch = geo.cartographic.create();
|
state.distanceEndpointScratch = geo.cartographic.create();
|
||||||
|
|
||||||
state.distanceGeodesicScratch = new Cesium.EllipsoidGeodesic();
|
state.distanceGeodesicScratch = geo.ellipsoidGeodesic.create();
|
||||||
|
|
||||||
Object.assign(state, {
|
Object.assign(state, {
|
||||||
viewer: null,
|
viewer: null,
|
||||||
|
|||||||
Reference in new issue
Block a user