PlotDirector/PlotLine.Tests/Browser/maps-geography-hierarchy-fixture.cjs

12 lines
2.0 KiB
JavaScript

// Isolated persistence/deployment fixture; all Location IDs are supplied by a disposable account's project.
const fs=require('node:fs'),{randomUUID}=require('node:crypto'),E=require('../../PlotLine/wwwroot/js/maps-engine.js'),G=require('../../PlotLine/wwwroot/js/maps-geography-engine.js');
const input=JSON.parse(fs.readFileSync(process.argv[2],'utf8')),places=new Map(input.locations.map(l=>[l.locationName,l.locationID]));
const make=(type,name,x,y)=>Object.assign(E.makeFeature(type,x,y,randomUUID()),{name,locationID:places.get(name)||null,isProvisional:false});
const rubery=make('Town','Rubery',0,0),frankley=make('Town','Frankley',300,-40),redditch=make('Town','Redditch',100,300),barmouth=make('Town','Barmouth',-350,-200),house=make('House',"Maggie's flat",25,20),forest=make('Forest','Forest',-50,-40),lake=make('Lake','Reservoir',320,-30),own=make('House','Own place',80,90),child=make('House','Own child',95,100),decor=make('Landmark','Decoration',600,450);
const road=make('Road','A38',150,0);road.startFeatureID=rubery.featureID;road.endFeatureID=frankley.featureID;E.updateArea(road,g=>g.points=[[-.5,0],[-.1,.35],[.2,-.3],[.5,0]]);
const trail=make('Trail','Trail',200,100);trail.startFeatureID=frankley.featureID;trail.endFeatureID=redditch.featureID;
const before=[rubery,frankley,redditch,barmouth,house,forest,lake,own,child,decor,road,trail];E.reorder(before,[lake.featureID],'front');
const states=[['Rubery',52.391,-2.016],['Frankley',52.412,-2.023],['Redditch',52.306,-1.942],['Barmouth',52.72,-4.05],['Own place',52.4,-2.01]].map(([name,Latitude,Longitude])=>({locationID:places.get(name),status:'Resolved',matchJson:JSON.stringify({Latitude,Longitude,Attribution:'Isolated acceptance coordinates; no live-provider requests'})}));
const result=G.position(before,states,{x:-600,y:-400,w:1200,h:800},input.locations);if(!result.canApply)throw Error(result.message);
fs.writeFileSync(process.argv[3],JSON.stringify({...input,before,after:result.features,states,counts:result.counts}),{mode:0o600});