Skip to content

Commit

Permalink
Remove stamen tiles from OSM TileLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
jericks committed Nov 4, 2023
1 parent 3da1585 commit ea80480
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 176 deletions.
6 changes: 6 additions & 0 deletions doc/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
GeoScript Groovy Releases
=========================

1.23.0 (In Progress)
--------------------
The 1.23 release of GeoScript is build on Groovy 4.0.15, GeoTools 31.0, and the Java Topology Suite 1.90.0 and requires Java 11.

Remove Stamen Tiles from the OSM Tile Layer.

1.22.0
------
The 1.22 release of GeoScript is build on Groovy 4.0.15, GeoTools 30.0, and the Java Topology Suite 1.90.0 and requires Java 11.
Expand Down
60 changes: 3 additions & 57 deletions examples/tiles_osm.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,8 @@ OSM osm = new OSM()
ImageIO.write(raster.image, "png", new File(dir, "osm_${z}.png"))
}

// Stamen Toner
osm = new OSM("Stamen Toner", [
"http://a.tile.stamen.com/toner",
"http://b.tile.stamen.com/toner",
"http://c.tile.stamen.com/toner",
"http://d.tile.stamen.com/toner"
])
OSM wikiMedia = OSM.getWellKnownOSM("wikimedia")
(0..2).each{ int z ->
Raster raster = osm.getRaster(osm.tiles(z))
ImageIO.write(raster.image, "png", new File(dir, "stamen_toner_${z}.png"))
}

// Stamen Toner-lite
osm = new OSM("Stamen Toner", [
"http://a.tile.stamen.com/toner-lite",
"http://b.tile.stamen.com/toner-lite",
"http://c.tile.stamen.com/toner-lite",
"http://d.tile.stamen.com/toner-lite"
])
(0..2).each{ int z ->
Raster raster = osm.getRaster(osm.tiles(z))
ImageIO.write(raster.image, "png", new File(dir, "stamen_toner-lite_${z}.png"))
}

// Stamen Watercolor
osm = new OSM("Stamen Watercolor", [
"http://a.tile.stamen.com/watercolor",
"http://b.tile.stamen.com/watercolor",
"http://c.tile.stamen.com/watercolor",
"http://d.tile.stamen.com/watercolor"
])
(1..2).each{ int z ->
Raster raster = osm.getRaster(osm.tiles(z))
ImageIO.write(raster.image, "png", new File(dir, "stamen_watercolor_${z}.png"))
}

// Open MapQuest Street Map
osm = new OSM("MapQuest Street Map",[
"http://otile1.mqcdn.com/tiles/1.0.0/map",
"http://otile2.mqcdn.com/tiles/1.0.0/map",
"http://otile3.mqcdn.com/tiles/1.0.0/map",
"http://otile4.mqcdn.com/tiles/1.0.0/map"
])
(0..3).each{ int z ->
Raster raster = osm.getRaster(osm.tiles(z))
ImageIO.write(raster.image, "png", new File(dir, "mq_map_${z}.png"))
}

// Open MapQuest Satellite Map
osm = new OSM("MapQuest Satellite Map", [
"http://otile1.mqcdn.com/tiles/1.0.0/sat",
"http://otile2.mqcdn.com/tiles/1.0.0/sat",
"http://otile3.mqcdn.com/tiles/1.0.0/sat",
"http://otile4.mqcdn.com/tiles/1.0.0/sat"
])
(0..3).each{ int z ->
Raster raster = osm.getRaster(osm.tiles(z))
ImageIO.write(raster.image, "png", new File(dir, "mq_sat_${z}.png"))
Raster raster = wikiMedia.getRaster(wikiMedia.tiles(z))
ImageIO.write(raster.image, "png", new File(dir, "osm_wikimedia_${z}.png"))
}
9 changes: 4 additions & 5 deletions examples/tiles_osm_states.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import javax.imageio.ImageIO
File dir = new File("osm")
dir.mkdir()

OSM osm = new OSM("Stamen Terrain", [
"http://a.tile.stamen.com/terrain",
"http://b.tile.stamen.com/terrain",
"http://c.tile.stamen.com/terrain",
"http://d.tile.stamen.com/terrain"
OSM osm = new OSM("OSM", [
"http://a.tile.openstreetmap.org",
"http://b.tile.openstreetmap.org",
"http://c.tile.openstreetmap.org"
])

Shapefile shp = new Shapefile("states.shp")
Expand Down
9 changes: 4 additions & 5 deletions examples/vectortiles_generate_pbf.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ generator.generate(vectorTiles, renderer, 0, 6)

// Render

OSM osm = new OSM("Stamen Toner", [
"http://a.tile.stamen.com/toner",
"http://b.tile.stamen.com/toner",
"http://c.tile.stamen.com/toner",
"http://d.tile.stamen.com/toner"
OSM osm = new OSM("OSM", [
"http://a.tile.openstreetmap.org",
"http://b.tile.openstreetmap.org",
"http://c.tile.openstreetmap.org"
])

["North Dakota", "Oregon", "Washington"].each { String name ->
Expand Down
9 changes: 4 additions & 5 deletions examples/vectortiles_render.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import geoscript.style.Stroke
File dir = new File("vectortiles")
dir.mkdir()

OSM osm = new OSM("Stamen Toner", [
"http://a.tile.stamen.com/toner",
"http://b.tile.stamen.com/toner",
"http://c.tile.stamen.com/toner",
"http://d.tile.stamen.com/toner"
OSM osm = new OSM("OSM", [
"http://a.tile.openstreetmap.org",
"http://b.tile.openstreetmap.org",
"http://c.tile.openstreetmap.org"
])

Pyramid pyramid = Pyramid.createGlobalMercatorPyramid()
Expand Down
62 changes: 14 additions & 48 deletions src/main/groovy/geoscript/layer/OSM.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class OSM extends ImageTileLayer {
*/
String imageType = "png"

/**
* @2x
*/
String preImageTypePrefix = "";

/**
* The global web mercator Pyramid
*/
Expand Down Expand Up @@ -74,7 +79,8 @@ class OSM extends ImageTileLayer {
ImageTile get(long z, long x, long y) {
ImageTile tile = new ImageTile(z, x, y)
String baseUrl = getBaseUrl()
URL url = new URL("${baseUrl}${baseUrl.endsWith("/") ? '' : '/'}${z}/${x}/${y}.${imageType}")
URL url = new URL("${baseUrl}${baseUrl.endsWith("/") ? '' : '/'}${z}/${x}/${y}${preImageTypePrefix}.${imageType}")
println url
URLConnection urlConnection = url.openConnection()
urlConnection.setRequestProperty("User-Agent", "GeoScript Groovy")
InputStream inputStream = urlConnection.inputStream
Expand Down Expand Up @@ -127,57 +133,18 @@ class OSM extends ImageTileLayer {

/**
* Get a well known OSM Layer.
* @param name The name of the well known OSM Layer (stamen-toner, stamen-toner-lite, stamen-watercolor, mapquest-street,
* mapquest-satellite, or osm)
* @param name The name of the well known OSM Layer (osm or wikimedia)
* @return An OSM Tile Layer
*/
static OSM getWellKnownOSM(String name) {
if (!name) {
null
} else if (name.equalsIgnoreCase("stamen-toner")) {
new OSM("Stamen Toner", [
"http://a.tile.stamen.com/toner",
"http://b.tile.stamen.com/toner",
"http://c.tile.stamen.com/toner",
"http://d.tile.stamen.com/toner"
])
} else if (name.equalsIgnoreCase("stamen-toner-lite")) {
new OSM("Stamen Toner Lite", [
"http://a.tile.stamen.com/toner-lite",
"http://b.tile.stamen.com/toner-lite",
"http://c.tile.stamen.com/toner-lite",
"http://d.tile.stamen.com/toner-lite"
])
} else if (name.equalsIgnoreCase("stamen-watercolor")) {
new OSM("Stamen Watercolor", [
"http://a.tile.stamen.com/watercolor",
"http://b.tile.stamen.com/watercolor",
"http://c.tile.stamen.com/watercolor",
"http://d.tile.stamen.com/watercolor"
])
} else if (name.equalsIgnoreCase("stamen-terrain")) {
new OSM("Stamen Terrain", [
"http://a.tile.stamen.com/terrain",
"http://b.tile.stamen.com/terrain",
"http://c.tile.stamen.com/terrain",
"http://d.tile.stamen.com/terrain"
])
} else if (name.equalsIgnoreCase("mapquest-street")) {
new OSM("MapQuest Street", [
"http://otile1.mqcdn.com/tiles/1.0.0/map",
"http://otile2.mqcdn.com/tiles/1.0.0/map",
"http://otile3.mqcdn.com/tiles/1.0.0/map",
"http://otile4.mqcdn.com/tiles/1.0.0/map"
])
} else if (name.equalsIgnoreCase("mapquest-satellite")) {
new OSM("MapQuest Satellite", [
"http://otile1.mqcdn.com/tiles/1.0.0/sat",
"http://otile2.mqcdn.com/tiles/1.0.0/sat",
"http://otile3.mqcdn.com/tiles/1.0.0/sat",
"http://otile4.mqcdn.com/tiles/1.0.0/sat"
])
} else if (name.equalsIgnoreCase("wikimedia")) {
new OSM("WikiMedia", ["https://maps.wikimedia.org/osm-intl"])
OSM osm = new OSM("WikiMedia", ["https://maps.wikimedia.org/osm-intl/"])
osm.preImageTypePrefix = "@2x"
osm.pyramid.tileWidth = 512
osm.pyramid.tileHeight = 512
osm
} else if (name.equalsIgnoreCase("osm")) {
new OSM()
} else {
Expand All @@ -193,8 +160,7 @@ class OSM extends ImageTileLayer {
@Override
OSM create(String paramsStr) {
Map params = [:]
if (paramsStr in ['stamen-toner', 'stamen-toner-lite', 'stamen-watercolor',
'mapquest-street', 'mapquest-satellite', 'osm', 'wikimedia']) {
if (paramsStr in ['osm', 'wikimedia']) {
params["type"] = "osm"
params["name"] = paramsStr
create(params)
Expand Down
56 changes: 0 additions & 56 deletions src/test/groovy/geoscript/layer/OSMTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ class OSMTest {
void getWellKnownOSM() {
OSM osm = OSM.getWellKnownOSM("osm")
assertEquals "OSM", osm.name
osm = OSM.getWellKnownOSM("stamen-toner")
assertEquals "Stamen Toner", osm.name
osm = OSM.getWellKnownOSM("stamen-toner")
assertEquals "Stamen Toner", osm.name
osm = OSM.getWellKnownOSM("stamen-toner-lite")
assertEquals "Stamen Toner Lite", osm.name
osm = OSM.getWellKnownOSM("stamen-watercolor")
assertEquals "Stamen Watercolor", osm.name
osm = OSM.getWellKnownOSM("stamen-terrain")
assertEquals "Stamen Terrain", osm.name
osm = OSM.getWellKnownOSM("mapquest-street")
assertEquals "MapQuest Street", osm.name
osm = OSM.getWellKnownOSM("mapquest-satellite")
assertEquals "MapQuest Satellite", osm.name
osm = OSM.getWellKnownOSM("wikimedia")
assertEquals "WikiMedia", osm.name
assertNull OSM.getWellKnownOSM("N/A")
Expand All @@ -51,22 +37,6 @@ class OSMTest {
assertEquals 'OSM', osm.name
osm = TileLayer.getTileLayer([type: 'osm'])
assertEquals 'OSM', osm.name
osm = TileLayer.getTileLayer([type: 'osm', name: 'stamen-toner'])
assertEquals 'Stamen Toner', osm.name
osm = TileLayer.getTileLayer([type: 'osm', name: 'stamen-toner-lite'])
assertEquals 'Stamen Toner Lite', osm.name
osm = TileLayer.getTileLayer([type: 'osm', name: 'stamen-watercolor'])
assertEquals 'Stamen Watercolor', osm.name
osm = TileLayer.getTileLayer([type: 'osm', name: 'stamen-terrain'])
assertEquals 'Stamen Terrain', osm.name
osm = TileLayer.getTileLayer([type: 'osm', name: 'mapquest-satellite'])
assertEquals 'MapQuest Satellite', osm.name
osm = TileLayer.getTileLayer([type: 'osm', name: 'mapquest-street'])
assertEquals 'MapQuest Street', osm.name
osm = TileLayer.getTileLayer([type: 'osm', url: 'http://a.tile.stamen.com/toner-lite'])
assertEquals "OSM", osm.name
osm = TileLayer.getTileLayer([type: 'osm', urls: 'http://a.tile.stamen.com/toner-lite,http://b.tile.stamen.com/toner-lite'])
assertEquals "OSM", osm.name
}

@Test
Expand All @@ -77,32 +47,6 @@ class OSMTest {
assertEquals 'OSM', osm.name
osm = TileLayer.getTileLayer("osm")
assertEquals 'OSM', osm.name
osm = TileLayer.getTileLayer("type=osm name=stamen-toner")
assertEquals 'Stamen Toner', osm.name
osm = TileLayer.getTileLayer("stamen-toner")
assertEquals 'Stamen Toner', osm.name
osm = TileLayer.getTileLayer("type=osm name=stamen-toner-lite")
assertEquals 'Stamen Toner Lite', osm.name
osm = TileLayer.getTileLayer("stamen-toner-lite")
assertEquals 'Stamen Toner Lite', osm.name
osm = TileLayer.getTileLayer([type: 'osm', name: 'stamen-watercolor'])
assertEquals 'Stamen Watercolor', osm.name
osm = TileLayer.getTileLayer([type: 'osm', name: 'stamen-terrain'])
assertEquals 'Stamen Terrain', osm.name
osm = TileLayer.getTileLayer("stamen-watercolor")
assertEquals 'Stamen Watercolor', osm.name
osm = TileLayer.getTileLayer("type=osm name=mapquest-satellite")
assertEquals 'MapQuest Satellite', osm.name
osm = TileLayer.getTileLayer("mapquest-satellite")
assertEquals 'MapQuest Satellite', osm.name
osm = TileLayer.getTileLayer("type=osm name=mapquest-street")
assertEquals 'MapQuest Street', osm.name
osm = TileLayer.getTileLayer("mapquest-street")
assertEquals 'MapQuest Street', osm.name
osm = TileLayer.getTileLayer("type=osm url=http://a.tile.stamen.com/toner-lite")
assertEquals "OSM", osm.name
osm = TileLayer.getTileLayer("type=osm urls=http://a.tile.stamen.com/toner-lite,http://b.tile.stamen.com/toner-lite")
assertEquals "OSM", osm.name
}

@Test
Expand Down

0 comments on commit ea80480

Please sign in to comment.