slippy-tile
Advanced tools
Comparing version 1.2.1 to 1.2.2
# Changelog | ||
## 1.2.1 - 2016-10-20 | ||
## 1.2.2 - 2016-10-21 | ||
- Remove all `request` related dependencies | ||
- Removed `download` method | ||
- Added DigitalGlobe as provider | ||
@@ -6,0 +8,0 @@ - Converted `source.json` to `providers.yml` |
@@ -19,6 +19,6 @@ [![Build Status](https://travis-ci.org/DenisCarriere/slippy-tile.svg?branch=master)](https://travis-ci.org/DenisCarriere/slippy-tile) | ||
```javascript | ||
import * as slippyTile from 'slippy-tile' | ||
import slippyTile from 'slippy-tile' | ||
const tile = [10, 15, 8] // x, y, zoom | ||
const url = slippyTile.url(tile, 'osm') | ||
const url = slippyTile(tile, 'osm') | ||
//= https://b.tile.openstreetmap.org/8/10/15.png | ||
@@ -55,3 +55,3 @@ ``` | ||
const scheme = 'https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png' | ||
const url = slippyTile.url([10, 15, 8], scheme) | ||
const url = slippyTile([10, 15, 8], scheme) | ||
//= https://b.tile.openstreetmap.org/8/10/15.png | ||
@@ -58,0 +58,0 @@ ``` |
70
index.js
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
const mercator = require('global-mercator'); | ||
const rp = require('request-promise'); | ||
const providers_1 = require('./utils/providers'); | ||
const fs = require('fs'); | ||
const yml = require('js-yaml'); | ||
const path = require('path'); | ||
const providers = yml.safeLoad(fs.readFileSync(path.join(__dirname, 'providers.yml'), { encoding: 'utf-8' })); | ||
/** | ||
@@ -20,6 +14,7 @@ * Substitutes the given tile information [x,y,zoom] to the URL tile scheme. | ||
* @example | ||
* const url = slippyTile.url([10, 15, 8], 'osm') | ||
* import slippyTile from 'slippyTile' | ||
* slippyTile([10, 15, 8], 'osm') | ||
* //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
*/ | ||
function url(tile, scheme) { | ||
function slippyTile(tile, scheme) { | ||
const [x, y, zoom] = tile; | ||
@@ -45,21 +40,18 @@ let url = providerLookup(scheme); | ||
} | ||
exports.url = url; | ||
exports.slippyTile = slippyTile; | ||
// /** | ||
// * Downloads Tile | ||
// * | ||
// * @param {Tile} tile Tile [x, y, zoom] | ||
// * @param {string} scheme Tile scheme URL or pre-loaded source unique key | ||
// * @returns {Promise<Buffer>} tile buffer | ||
// * @example | ||
// * const url = slippyTile.url([10, 15, 8], 'osm') | ||
// * //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
// */ | ||
// export async function download(tile: Tile, scheme: string): Promise<Buffer> { | ||
// return rp.get(url(tile, scheme), { encoding : 'binary' }) | ||
// .then(data => new Buffer(data, 'binary')) | ||
// } | ||
/** | ||
* Downloads Tile | ||
* | ||
* @param {Tile} tile Tile [x, y, zoom] | ||
* @param {string} scheme Tile scheme URL or pre-loaded source unique key | ||
* @returns {Promise<Buffer>} tile buffer | ||
* @example | ||
* const url = slippyTile.url([10, 15, 8], 'osm') | ||
* //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
*/ | ||
function download(tile, scheme) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return rp.get(url(tile, scheme), { encoding: 'binary' }) | ||
.then(data => new Buffer(data, 'binary')); | ||
}); | ||
} | ||
exports.download = download; | ||
/** | ||
* Replaces {switch:a,b,c} with a random sample. | ||
@@ -70,4 +62,4 @@ * | ||
* @example | ||
* const scheme = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
* const url = slippyTile.parseSwitch(scheme) | ||
* import { parseSwitch } from 'slippyTile' | ||
* parseSwitch('http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png') | ||
* //='http://tile-b.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
@@ -89,5 +81,6 @@ */ | ||
* @param {string} provider Provider unique key | ||
* @returns {string} scheme Tile scheme URL | ||
* @returns {string} url Tile URL scheme | ||
* @example | ||
* const scheme = slippyTile.providerLookup('bing') | ||
* import { provider } from 'slippyTile' | ||
* provider('bing-imagery') | ||
* //='http://ecn.t{switch:0,1,2,3}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=5250' | ||
@@ -98,4 +91,4 @@ */ | ||
const key = provider.toLowerCase().trim(); | ||
if (providers_1.providers[key] !== undefined) { | ||
return providers_1.providers[key].scheme; | ||
if (providers[key] !== undefined) { | ||
return providers[key].url; | ||
} | ||
@@ -112,3 +105,4 @@ } | ||
* @example | ||
* const item = sample(['a', 'b', 'c']) | ||
* import { sample } from 'slippyTile' | ||
* sample(['a', 'b', 'c']) | ||
* //='a' | ||
@@ -120,2 +114,4 @@ */ | ||
exports.sample = sample; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = slippyTile; | ||
//# sourceMappingURL=index.js.map |
69
index.ts
import * as mercator from 'global-mercator' | ||
import * as rp from 'request-promise' | ||
import { providers } from './utils/providers' | ||
import * as fs from 'fs' | ||
import * as yml from 'js-yaml' | ||
import * as path from 'path' | ||
export interface Provider { | ||
name: string | ||
categories: Array<string> | ||
url: string | ||
description: string | ||
attribution: string | ||
format: string | ||
} | ||
interface Providers { | ||
[key: string]: Provider | ||
} | ||
const providers: Providers = yml.safeLoad(fs.readFileSync(path.join(__dirname, 'providers.yml'), { encoding: 'utf-8' })) | ||
/** | ||
@@ -17,6 +33,7 @@ * Tile [x, y, zoom] | ||
* @example | ||
* const url = slippyTile.url([10, 15, 8], 'osm') | ||
* import slippyTile from 'slippyTile' | ||
* slippyTile([10, 15, 8], 'osm') | ||
* //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
*/ | ||
export function url(tile: Tile, scheme: string) { | ||
export function slippyTile(tile: Tile, scheme: string) { | ||
const [x, y, zoom] = tile | ||
@@ -37,16 +54,16 @@ let url = providerLookup(scheme) | ||
/** | ||
* Downloads Tile | ||
* | ||
* @param {Tile} tile Tile [x, y, zoom] | ||
* @param {string} scheme Tile scheme URL or pre-loaded source unique key | ||
* @returns {Promise<Buffer>} tile buffer | ||
* @example | ||
* const url = slippyTile.url([10, 15, 8], 'osm') | ||
* //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
*/ | ||
export async function download(tile: Tile, scheme: string): Promise<Buffer> { | ||
return rp.get(url(tile, scheme), { encoding : 'binary' }) | ||
.then(data => new Buffer(data, 'binary')) | ||
} | ||
// /** | ||
// * Downloads Tile | ||
// * | ||
// * @param {Tile} tile Tile [x, y, zoom] | ||
// * @param {string} scheme Tile scheme URL or pre-loaded source unique key | ||
// * @returns {Promise<Buffer>} tile buffer | ||
// * @example | ||
// * const url = slippyTile.url([10, 15, 8], 'osm') | ||
// * //='https://c.tile.openstreetmap.org/8/10/15.png' | ||
// */ | ||
// export async function download(tile: Tile, scheme: string): Promise<Buffer> { | ||
// return rp.get(url(tile, scheme), { encoding : 'binary' }) | ||
// .then(data => new Buffer(data, 'binary')) | ||
// } | ||
@@ -59,4 +76,4 @@ /** | ||
* @example | ||
* const scheme = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
* const url = slippyTile.parseSwitch(scheme) | ||
* import { parseSwitch } from 'slippyTile' | ||
* parseSwitch('http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png') | ||
* //='http://tile-b.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
@@ -78,5 +95,6 @@ */ | ||
* @param {string} provider Provider unique key | ||
* @returns {string} scheme Tile scheme URL | ||
* @returns {string} url Tile URL scheme | ||
* @example | ||
* const scheme = slippyTile.providerLookup('bing') | ||
* import { provider } from 'slippyTile' | ||
* provider('bing-imagery') | ||
* //='http://ecn.t{switch:0,1,2,3}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=5250' | ||
@@ -88,3 +106,3 @@ */ | ||
if (providers[key] !== undefined) { | ||
return providers[key].scheme | ||
return providers[key].url | ||
} | ||
@@ -101,3 +119,4 @@ } | ||
* @example | ||
* const item = sample(['a', 'b', 'c']) | ||
* import { sample } from 'slippyTile' | ||
* sample(['a', 'b', 'c']) | ||
* //='a' | ||
@@ -108,1 +127,3 @@ */ | ||
} | ||
export default slippyTile |
{ | ||
"name": "slippy-tile", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Helps convert Slippy Map url tile schemas", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"scripts": { | ||
"build": "tsc && js-yaml providers.yml", | ||
"prepublish": "tsc", | ||
"test": "tsc && npm run lint && nyc ava", | ||
@@ -29,5 +29,3 @@ "docs": "tsc && cat HEADER.md > README.md && documentation build index.js -c documentation.yml -f md >> README.md && cat CHANGELOG.md >> README.md", | ||
"@types/js-yaml": "^3.5.28", | ||
"@types/bluebird": "^3.0.35", | ||
"@types/request": "^0.0.31", | ||
"@types/request-promise": "^3.0.32", | ||
"@types/node": "^6.0.45", | ||
"ava": "^0.16.0", | ||
@@ -62,8 +60,5 @@ "coveralls": "^2.11.14", | ||
"dependencies": { | ||
"bluebird": "^3.4.6", | ||
"global-mercator": "^1.3.2", | ||
"js-yaml": "^3.6.1", | ||
"request": "^2.75.0", | ||
"request-promise": "^4.1.1" | ||
"js-yaml": "^3.6.1" | ||
} | ||
} |
@@ -19,6 +19,6 @@ [![Build Status](https://travis-ci.org/DenisCarriere/slippy-tile.svg?branch=master)](https://travis-ci.org/DenisCarriere/slippy-tile) | ||
```javascript | ||
import * as slippyTile from 'slippy-tile' | ||
import slippyTile from 'slippy-tile' | ||
const tile = [10, 15, 8] // x, y, zoom | ||
const url = slippyTile.url(tile, 'osm') | ||
const url = slippyTile(tile, 'osm') | ||
//= https://b.tile.openstreetmap.org/8/10/15.png | ||
@@ -55,3 +55,3 @@ ``` | ||
const scheme = 'https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png' | ||
const url = slippyTile.url([10, 15, 8], scheme) | ||
const url = slippyTile([10, 15, 8], scheme) | ||
//= https://b.tile.openstreetmap.org/8/10/15.png | ||
@@ -72,3 +72,3 @@ ``` | ||
- `{proj}`: default = EPSG:3857 | ||
# url | ||
# slippyTile | ||
@@ -85,3 +85,4 @@ Substitutes the given tile information [x,y,zoom] to the URL tile scheme. | ||
```javascript | ||
const url = slippyTile.url([10, 15, 8], 'osm') | ||
import slippyTile from 'slippyTile' | ||
slippyTile([10, 15, 8], 'osm') | ||
//='https://c.tile.openstreetmap.org/8/10/15.png' | ||
@@ -92,20 +93,2 @@ ``` | ||
# download | ||
Downloads Tile | ||
**Parameters** | ||
- `tile` **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** Tile [x, y, zoom] | ||
- `scheme` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Tile scheme URL or pre-loaded source unique key | ||
**Examples** | ||
```javascript | ||
const url = slippyTile.url([10, 15, 8], 'osm') | ||
//='https://c.tile.openstreetmap.org/8/10/15.png' | ||
``` | ||
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** tile buffer | ||
# parseSwitch | ||
@@ -122,4 +105,4 @@ | ||
```javascript | ||
const scheme = 'http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
const url = slippyTile.parseSwitch(scheme) | ||
import { parseSwitch } from 'slippyTile' | ||
parseSwitch('http://tile-{switch:a,b,c}.openstreetmap.fr/hot/{zoom}/{x}/{y}.png') | ||
//='http://tile-b.openstreetmap.fr/hot/{zoom}/{x}/{y}.png' | ||
@@ -141,7 +124,8 @@ ``` | ||
```javascript | ||
const scheme = slippyTile.providerLookup('bing') | ||
import { provider } from 'slippyTile' | ||
provider('bing-imagery') | ||
//='http://ecn.t{switch:0,1,2,3}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=5250' | ||
``` | ||
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** scheme Tile scheme URL | ||
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** url Tile URL scheme | ||
@@ -159,3 +143,4 @@ # sample | ||
```javascript | ||
const item = sample(['a', 'b', 'c']) | ||
import { sample } from 'slippyTile' | ||
sample(['a', 'b', 'c']) | ||
//='a' | ||
@@ -167,4 +152,6 @@ ``` | ||
## 1.2.1 - 2016-10-20 | ||
## 1.2.2 - 2016-10-21 | ||
- Remove all `request` related dependencies | ||
- Removed `download` method | ||
- Added DigitalGlobe as provider | ||
@@ -171,0 +158,0 @@ - Converted `source.json` to `providers.yml` |
19
test.js
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
const ava_1 = require('ava'); | ||
const slippyTile = require('./index'); | ||
const index_1 = require('./index'); | ||
ava_1.default('url', t => { | ||
const scheme = 'https://tile.openstreetmap.org/{zoom}/{x}/{y}.png'; | ||
const tile = [10, 15, 8]; | ||
const url = slippyTile.url(tile, scheme); | ||
const url = index_1.default(tile, scheme); | ||
t.deepEqual(url, 'https://tile.openstreetmap.org/8/10/15.png'); | ||
@@ -20,10 +12,5 @@ }); | ||
const tile = [10, 15, 8]; | ||
const url = slippyTile.url(tile, 'osm'); | ||
const url = index_1.default(tile, 'osm'); | ||
t.true(!!url); | ||
}); | ||
ava_1.default('download', (t) => __awaiter(this, void 0, void 0, function* () { | ||
const tile = [10, 15, 8]; | ||
const buffer = yield slippyTile.download(tile, 'osm'); | ||
t.true(!!buffer); | ||
})); | ||
//# sourceMappingURL=test.js.map |
12
test.ts
import test from 'ava' | ||
import * as slippyTile from './index' | ||
import slippyTile from './index' | ||
import { Tile } from './index' | ||
@@ -8,3 +8,3 @@ | ||
const tile: Tile = [10, 15, 8] | ||
const url = slippyTile.url(tile, scheme) | ||
const url = slippyTile(tile, scheme) | ||
t.deepEqual(url, 'https://tile.openstreetmap.org/8/10/15.png') | ||
@@ -15,10 +15,4 @@ }) | ||
const tile: Tile = [10, 15, 8] | ||
const url = slippyTile.url(tile, 'osm') | ||
const url = slippyTile(tile, 'osm') | ||
t.true(!!url) | ||
}) | ||
test('download', async t => { | ||
const tile: Tile = [10, 15, 8] | ||
const buffer = await slippyTile.download(tile, 'osm') | ||
t.true(!!buffer) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
2
9
192658
21
298
161
- Removedbluebird@^3.4.6
- Removedrequest@^2.75.0
- Removedrequest-promise@^4.1.1
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbluebird@3.7.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequest-promise@4.2.6(transitive)
- Removedrequest-promise-core@1.1.4(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstealthy-require@1.1.1(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)