feat: (broken) implement route map and address autocomplete widgets with associated infrastructure testing scripts
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
const axios = require('axios');
|
||||
const polylineLib = require('@mapbox/polyline');
|
||||
require('dotenv').config({ path: '.env' });
|
||||
|
||||
async function testHalfPolyline() {
|
||||
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' } });
|
||||
|
||||
const mainPoly = resToll.data.routes[0].polyline.encodedPolyline;
|
||||
const mainCoords = polylineLib.decode(mainPoly, 5);
|
||||
|
||||
const halfCoords = mainCoords.slice(0, Math.floor(mainCoords.length / 2));
|
||||
const halfPoly = polylineLib.encode(halfCoords, 5);
|
||||
|
||||
console.log(`Sending first half (${halfCoords.length} points)`);
|
||||
|
||||
const ulysUrl = `https://api-ulys.azure-api.net/placemark/v2/legs?precision=5&includeLayersIds=GaresPeage`;
|
||||
|
||||
try {
|
||||
const res = await axios.post(ulysUrl, JSON.stringify(halfPoly), {
|
||||
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);
|
||||
}
|
||||
}
|
||||
testHalfPolyline();
|
||||
Reference in New Issue
Block a user