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

Commit

Permalink
Use OpenStreetMap zoom level
Browse files Browse the repository at this point in the history
  • Loading branch information
mvsde committed Aug 19, 2018
1 parent 01e336c commit f3e38fb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
20 changes: 14 additions & 6 deletions lib/convert-coordinates.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const utm = require('utm')

const degToRad = require('./deg-to-rad')

/**
* Convert OMSI coordinates to LGLN coordinates
* @param {Object} options Convert options
Expand All @@ -21,14 +23,20 @@ function convertCoordinates (options) {
options.z = parseFloat(options.z)
}

const { easting, northing } = utm.fromLatLon(options.x, options.y)
const zoom = (100 * options.z) / 2
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: easting - zoom,
y1: northing - zoom,
x2: easting + zoom,
y2: northing + zoom
x1: centerX - halfTileWidth,
y1: centerY - halfTileWidth,
x2: centerX + halfTileWidth,
y2: centerY + halfTileWidth
}
}

Expand Down
10 changes: 10 additions & 0 deletions lib/deg-to-rad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Convert degree to radian
* @param {number} angle Degree
* @returns {number} Radian
*/
function degToRad (angle) {
return angle * (Math.PI / 180)
}

module.exports = degToRad
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.2",
"version": "0.1.0-alpha.3",
"description": "Convert OMSI URLs to LGLN URLs",
"main": "index.js",
"bin": "bin/omsi-to-lgln.js",
Expand Down

0 comments on commit f3e38fb

Please sign in to comment.