Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Try new calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvsde committed Aug 25, 2018
1 parent e4731bc commit ebc1dd7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# OMSI to LGLN

Convert OMSI URLs to LGLN URLs via a local proxy server.

Example URL:

http://localhost:3000/?&x=53.3332&y=9.8667&z=16
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports = async function () {
const app = express()

app.get('/', async (request, response) => {
console.log(chalk`\n================================================================================`)

console.log(chalk`\n{bold Request coordinates (lat/long)}`)
console.log(request.query)

Expand Down
31 changes: 17 additions & 14 deletions lib/convert-coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ function convertCoordinates (options) {
options.z = parseFloat(options.z)
}

const latInner = Math.PI * (1 - 2 * options.y / 2 ** options.z)
const latSinh = Math.sinh(degToRad(latInner))
const latAtan = Math.atan(degToRad(latSinh))
const lat = latAtan * 180 / Math.PI

const long = options.x * 360 / 2 ** options.z - 180

const {
easting: centerX,
northing: centerY
} = utm.fromLatLon(options.x, options.y)

const C = 40075016.686
const tileWidth = C * Math.cos(degToRad(options.x)) / 2 ** options.z
const halfTileWidth = tileWidth / 2

return {
x1: centerX - halfTileWidth,
y1: centerY - halfTileWidth,
x2: centerX + halfTileWidth,
y2: centerY + halfTileWidth
}
easting: x1,
northing: y2
} = utm.fromLatLon(lat, long)

const s = 40075016.686 * Math.cos(degToRad(lat)) / 2 ** options.z

const x2 = x1 + s
const y1 = y2 - s

return { x1, y1, x2, y2 }
}

module.exports = convertCoordinates
9 changes: 9 additions & 0 deletions lib/request-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ const chalk = require('chalk')

axios.defaults.baseURL = 'https://www.umweltkarten-niedersachsen.de'

axios.interceptors.response.use(response => {
console.log(chalk`\n{bold Request URL}`)
console.log(chalk`{blue ${response.request.res.responseUrl}}`)

return response
}, error => {
return Promise.reject(error)
})

/**
* Request map from LGLN
* @param {Object} options Request options
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "omsi-to-lgln",
"version": "0.1.0-alpha.3",
"version": "0.1.0-alpha.4",
"description": "Convert OMSI URLs to LGLN URLs",
"main": "index.js",
"bin": "bin/omsi-to-lgln.js",
Expand Down

0 comments on commit ebc1dd7

Please sign in to comment.