Skip to content

Commit 8ebea61

Browse files
committed
Add bbox4326, bbox3857 & size
1 parent 92473fd commit 8ebea61

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11

22
# Changelog
33

4+
## 2.3.0 - 2017-09-11
5+
6+
- Add new replacers
7+
- `{bbox4326}`: GeoJSON Bounding Box using EPSG:4326 (WGS84)
8+
- `{bbox3857}`: GeoJSON Bounding Box using EPSG:3857 (World Mercator)
9+
- `{size}`: default = 256,256
10+
411
## 2.2.0 - 2017-09-08
512

613
- Dropped throw errors on uncomplete parsed URL

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ You can provide your own scheme by following the same syntax as JOSM.
4545
- `{-y}`: Tile Row for TMS scheme
4646
- `{zoom}` or `{z}` or `{TileMatrix}`: Zoom Level
4747
- `{bbox}`: GeoJSON Bounding Box
48+
- `{bbox4326}`: GeoJSON Bounding Box using EPSG:4326 (WGS84)
49+
- `{bbox3857}`: GeoJSON Bounding Box using EPSG:3857 (World Mercator)
4850
- `{quadkey}` or `{q}`: Microsoft's Quadkey
4951
- `{switch:1,2,3}`: Selects a random sample
5052
- `{height}` default = 256

index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ function wms (tile, url) {
6767
url = url.replace(/{width}/gi, '256')
6868
url = url.replace(/{size}/gi, '256,256')
6969
url = url.replace(/{(proj|srs|crs)}/gi, 'EPSG:3857')
70-
var bbox
71-
if (url.match(/EPSG:(3857|900913)/i)) {
72-
bbox = bboxToMeters(googleToBBox(tile))
73-
} else {
74-
bbox = googleToBBox(tile)
75-
}
76-
77-
if (url.match(/{bbox}/i)) { url = url.replace(/{bbox}/gi, bbox.join(',')) }
70+
const bbox = googleToBBox(tile)
71+
const bboxMeters = bboxToMeters(bbox)
72+
if (url.match(/EPSG:(3857|900913)/i) && url.match(/{bbox}/i)) url = url.replace(/{bbox}/gi, bboxMeters.join(','))
73+
if (url.match(/{bbox4326}/i)) url = url.replace(/{bbox4326}/gi, bbox.join(','))
74+
if (url.match(/{bbox3857}/i)) url = url.replace(/{bbox3857}/gi, bboxMeters.join(','))
75+
if (url.match(/{bbox}/i)) url = url.replace(/{bbox}/gi, bbox.join(','))
7876
}
7977
return url
8078
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "slippy-tile",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Helps convert Slippy Map url tile schemas",
55
"main": "index.js",
66
"types": "index.d.ts",

test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ test('slippy-tile', t => {
6666
'http://hostname/?service=WMS&request=GetMap&version=1.3.0&layers=FooLayer&transparent=false&format=image/png&height=256&width=256&srs=EPSG:3857&bbox=-18472078,17532819.8,-18315535,17689362.6',
6767
'ogc.wms'
6868
)
69+
t.equal(slippyTile([0, 0, 0],
70+
'https://services.arcgisonline.com/arcgis/rest/services/ESRI_Imagery_World_2D/MapServer/export?bbox={bbox4326}&bboxSR=EPSG:4326&imageSR={srs}&size={size}&format=png&transparent=true&f=image', options),
71+
'https://services.arcgisonline.com/arcgis/rest/services/ESRI_Imagery_World_2D/MapServer/export?bbox=-180,-85.051129,180,85.051129&bboxSR=EPSG:4326&imageSR=EPSG:3857&size=256,256&format=png&transparent=true&f=image',
72+
'ESRI_Imagery_World_2D'
73+
)
6974
slippyTile(TILE, 'https://ecn.t{switch:1,2,3}.tiles.virtualearth.net/tiles/a{quadkey}.jpeg')
7075
t.end()
7176
})

0 commit comments

Comments
 (0)