feat: (broken) implement route map and address autocomplete widgets with associated infrastructure testing scripts
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
const axios = require('axios');
|
||||
const polylineLib = require('@mapbox/polyline');
|
||||
require('dotenv').config({ path: '.env' });
|
||||
|
||||
async function testStepsPolyline() {
|
||||
const apiKey = process.env.API_MAPS;
|
||||
const resToll = await axios.post('https://routes.googleapis.com/directions/v2:computeRoutes', {
|
||||
travelMode: 'DRIVE', routingPreference: 'TRAFFIC_UNAWARE',
|
||||
origin: { address: "25 Impasse du Puits du Suc, Saint-Martin-en-Haut, France" },
|
||||
destination: { address: "Toulouse, France" },
|
||||
}, { headers: { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': 'routes.polyline.encodedPolyline,routes.legs.steps.polyline.encodedPolyline' } });
|
||||
|
||||
const mainPoly = resToll.data.routes[0].polyline.encodedPolyline;
|
||||
const mainCoords = polylineLib.decode(mainPoly, 5);
|
||||
|
||||
const steps = resToll.data.routes[0].legs[0].steps;
|
||||
let stepCoords = [];
|
||||
for(let step of steps) {
|
||||
if(step.polyline && step.polyline.encodedPolyline) {
|
||||
stepCoords = stepCoords.concat(polylineLib.decode(step.polyline.encodedPolyline, 5));
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Main polyline points: ${mainCoords.length}`);
|
||||
console.log(`Steps combined points: ${stepCoords.length}`);
|
||||
|
||||
const combinedPoly = polylineLib.encode(stepCoords, 5);
|
||||
|
||||
const ulysUrl = `https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage`;
|
||||
|
||||
try {
|
||||
const res = await axios.post(ulysUrl, JSON.stringify(combinedPoly), {
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
const feats = res.data.features || res.data;
|
||||
console.log(`Found ${feats.length} gates.`);
|
||||
feats.forEach(f => {
|
||||
const pm = f.Placemark || f.placemark || {};
|
||||
console.log(pm.Preview || pm.preview || "Gate");
|
||||
});
|
||||
} catch(e) {
|
||||
console.log("Error:", e.message);
|
||||
}
|
||||
}
|
||||
testStepsPolyline();
|
||||
Reference in New Issue
Block a user