Comparing version 0.6.1 to 0.7.0
18
index.js
@@ -170,2 +170,17 @@ // a tile is an array [x,y,z] | ||
function pointToTileFraction (lon, lat, z) { | ||
var tile = pointToTile(lon, lat, z); | ||
var bbox = tileToBBOX(tile); | ||
var xTileOffset = bbox[2] - bbox[0]; | ||
var xPointOffset = lon - bbox[0]; | ||
var xPercentOffset = xPointOffset / xTileOffset; | ||
var yTileOffset = bbox[1] - bbox[3]; | ||
var yPointOffset = lat - bbox[3]; | ||
var yPercentOffset = yPointOffset / yTileOffset; | ||
return [tile[0]+xPercentOffset, tile[1]+yPercentOffset, z]; | ||
} | ||
module.exports = { | ||
@@ -183,3 +198,4 @@ tileToGeoJSON: tileToGeoJSON, | ||
pointToTile: pointToTile, | ||
bboxToTile: bboxToTile | ||
bboxToTile: bboxToTile, | ||
pointToTileFraction: pointToTileFraction | ||
}; |
{ | ||
"name": "tilebelt", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "simple tile utilities", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,2 +26,3 @@ tilebelt | ||
tileToGeoJSON(tile) | get a geojson representation of a tile | ||
tileToBBOX(tile) | get the bbox of a tile | ||
getChildren(tile) | get the 4 tiles one zoom level higher | ||
@@ -36,2 +37,3 @@ getParent(tile) | get the tile one zoom level lower | ||
pointToTile(lon, lat, zoom) | get the tile for a point at a specified zoom level | ||
pointToTileFraction(lon, lat, zoom) | get the precise fractional tile location for a point at a zoom level | ||
@@ -38,0 +40,0 @@ ##tests |
@@ -173,2 +173,11 @@ var test = require('tape'), | ||
t.end(); | ||
}); | ||
test('pointToTileFraction', function(t) { | ||
var tile = tilebelt.pointToTileFraction(-95.93965530395508,41.26000108568697,9); | ||
t.ok(tile, 'convert point to tile fraction'); | ||
t.equal(tile[0], 119.552490234375); | ||
t.equal(tile[1], 191.4701834281966); | ||
t.equal(tile[2], 9); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13376
331
41