mirror of
https://github.com/stevenhowes/osgrid-server.git
synced 2026-05-26 15:53:42 +01:00
URL paths
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
node_modules
|
||||||
@@ -1,32 +1,26 @@
|
|||||||
|
// Convert between Ordnance Survey grid reference and WGS-84 lat/lon.
|
||||||
|
// See https://www.movable-type.co.uk/scripts/latlong-os-gridref.html
|
||||||
|
|
||||||
import OsGridRef from 'geodesy/osgridref.js';
|
import OsGridRef from 'geodesy/osgridref.js';
|
||||||
import { LatLon } from 'geodesy/osgridref.js';
|
import { LatLon } from 'geodesy/osgridref.js';
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
// Usage: http://server/gridref=osgb-grid-ref
|
||||||
// Convert between Ordnance Survey grid reference and WGS-84 lat/lon.
|
app.get('/gridref/:ref', (request, response) => {
|
||||||
// See https://www.movable-type.co.uk/scripts/latlong-os-gridref.html
|
const gridref = OsGridRef.parse(request.params.ref);
|
||||||
//
|
|
||||||
// Usage: http://server/?gridRef=osgb-grid-ref or ://server/?latlon=lat,lon
|
|
||||||
app.get('/', (request, response) => {
|
|
||||||
var urlParts = url.parse(request.url, true);
|
|
||||||
var parameters = urlParts.query;
|
|
||||||
|
|
||||||
if (parameters.gridRef) {
|
|
||||||
const gridref = OsGridRef.parse(parameters.gridRef);
|
|
||||||
const wgs84 = gridref.toLatLon();
|
const wgs84 = gridref.toLatLon();
|
||||||
response.send(String(wgs84.lat) + "," + String(wgs84.lon));
|
response.send(String(wgs84.lat) + "," + String(wgs84.lon));
|
||||||
} else if (parameters.latLon) {
|
});
|
||||||
const parts = parameters.latLon.split(",");
|
|
||||||
const wgs84 = new LatLon(parts[0], parts[1]);
|
// Usage: http://server/latlon=lat,lon
|
||||||
const gridref = wgs84.toOsGrid();
|
app.get('/latlon/:latlon', (request, response) => {
|
||||||
response.send(gridref.toString());
|
const parts = request.params.latlon.split(",");
|
||||||
} else {
|
const wgs84 = new LatLon(parts[0], parts[1]);
|
||||||
response.send(404);
|
const gridref = wgs84.toOsGrid();
|
||||||
}
|
response.send(gridref.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(9090, () => console.log('Listening on port 9090'));
|
app.listen(9090, () => console.log('Listening on port 9090'));
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "osgreid",
|
"name": "osgrid-server",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user