From b192c067149cb8a08d9a2b064b07b27d434d7ec1 Mon Sep 17 00:00:00 2001 From: Eugene Maksymenko Date: Wed, 10 Jan 2024 15:09:41 +0200 Subject: [PATCH] Make Mercator Image Layer not a Web Layer by default. --- .../kotlin/earth/worldwind/examples/BasicGlobeActivity.kt | 4 ++-- .../src/androidMain/assets/basic_globe_tutorial.html | 2 +- .../kotlin/earth/worldwind/tutorials/BasicGlobeFragment.kt | 4 ++-- .../src/jsMain/kotlin/earth/worldwind/tutorials/Main.kt | 4 ++-- .../worldwind/layer/mercator/MercatorTiledImageLayer.kt | 7 +++---- ...{MercatorLayerFactory.kt => WebMercatorLayerFactory.kt} | 7 +++++-- .../kotlin/earth/worldwind/ogc/GpkgContentManager.kt | 4 ++-- 7 files changed, 17 insertions(+), 15 deletions(-) rename worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/{MercatorLayerFactory.kt => WebMercatorLayerFactory.kt} (92%) diff --git a/worldwind-examples-android/src/main/kotlin/earth/worldwind/examples/BasicGlobeActivity.kt b/worldwind-examples-android/src/main/kotlin/earth/worldwind/examples/BasicGlobeActivity.kt index 25c426c12..25eaf9084 100644 --- a/worldwind-examples-android/src/main/kotlin/earth/worldwind/examples/BasicGlobeActivity.kt +++ b/worldwind-examples-android/src/main/kotlin/earth/worldwind/examples/BasicGlobeActivity.kt @@ -9,7 +9,7 @@ import earth.worldwind.globe.projection.MercatorProjection import earth.worldwind.globe.projection.Wgs84Projection import earth.worldwind.layer.BackgroundLayer import earth.worldwind.layer.atmosphere.AtmosphereLayer -import earth.worldwind.layer.mercator.MercatorLayerFactory +import earth.worldwind.layer.mercator.WebMercatorLayerFactory import earth.worldwind.layer.starfield.StarFieldLayer import earth.worldwind.ogc.GpkgContentManager import kotlinx.coroutines.launch @@ -59,7 +59,7 @@ The globe uses the default navigation gestures: // Setting up the WorldWindow's layers. wwd.engine.layers.apply { addLayer(BackgroundLayer()) - addLayer(MercatorLayerFactory.createLayer( + addLayer(WebMercatorLayerFactory.createLayer( name = "Google Satellite", urlTemplate = "https://mt.google.com/vt/lyrs=s&x={x}&y={y}&z={z}&hl={lang}", imageFormat = "image/jpeg" diff --git a/worldwind-tutorials/src/androidMain/assets/basic_globe_tutorial.html b/worldwind-tutorials/src/androidMain/assets/basic_globe_tutorial.html index d2a0a1894..74310f91e 100644 --- a/worldwind-tutorials/src/androidMain/assets/basic_globe_tutorial.html +++ b/worldwind-tutorials/src/androidMain/assets/basic_globe_tutorial.html @@ -33,7 +33,7 @@

Get Started

// Setting up the WorldWindow's layers. wwd.engine.layers.apply { addLayer(BackgroundLayer()) - addLayer(MercatorLayerFactory.createLayer( + addLayer(WebMercatorLayerFactory.createLayer( name = "Google Satellite", urlTemplate = "https://mt.google.com/vt/lyrs=s&x={x}&y={y}&z={z}&hl={lang}", imageFormat = "image/jpeg" diff --git a/worldwind-tutorials/src/androidMain/kotlin/earth/worldwind/tutorials/BasicGlobeFragment.kt b/worldwind-tutorials/src/androidMain/kotlin/earth/worldwind/tutorials/BasicGlobeFragment.kt index 40cd60ec0..285a2fb4b 100644 --- a/worldwind-tutorials/src/androidMain/kotlin/earth/worldwind/tutorials/BasicGlobeFragment.kt +++ b/worldwind-tutorials/src/androidMain/kotlin/earth/worldwind/tutorials/BasicGlobeFragment.kt @@ -10,7 +10,7 @@ import earth.worldwind.WorldWindow import earth.worldwind.globe.elevation.coverage.BasicElevationCoverage import earth.worldwind.layer.BackgroundLayer import earth.worldwind.layer.atmosphere.AtmosphereLayer -import earth.worldwind.layer.mercator.MercatorLayerFactory +import earth.worldwind.layer.mercator.WebMercatorLayerFactory import earth.worldwind.layer.starfield.StarFieldLayer import earth.worldwind.ogc.GpkgContentManager import kotlinx.coroutines.launch @@ -34,7 +34,7 @@ open class BasicGlobeFragment: Fragment() { // Setting up the WorldWindow's layers. wwd.engine.layers.apply { addLayer(BackgroundLayer()) - addLayer(MercatorLayerFactory.createLayer( + addLayer(WebMercatorLayerFactory.createLayer( name = "Google Satellite", urlTemplate = "https://mt.google.com/vt/lyrs=s&x={x}&y={y}&z={z}&hl={lang}", imageFormat = "image/jpeg" diff --git a/worldwind-tutorials/src/jsMain/kotlin/earth/worldwind/tutorials/Main.kt b/worldwind-tutorials/src/jsMain/kotlin/earth/worldwind/tutorials/Main.kt index 7a676a14a..81bafa63d 100644 --- a/worldwind-tutorials/src/jsMain/kotlin/earth/worldwind/tutorials/Main.kt +++ b/worldwind-tutorials/src/jsMain/kotlin/earth/worldwind/tutorials/Main.kt @@ -10,7 +10,7 @@ import earth.worldwind.globe.projection.MercatorProjection import earth.worldwind.globe.projection.Wgs84Projection import earth.worldwind.layer.BackgroundLayer import earth.worldwind.layer.atmosphere.AtmosphereLayer -import earth.worldwind.layer.mercator.MercatorLayerFactory +import earth.worldwind.layer.mercator.WebMercatorLayerFactory import earth.worldwind.layer.starfield.StarFieldLayer import earth.worldwind.render.Renderable import earth.worldwind.shape.Movable @@ -55,7 +55,7 @@ fun main() { // Add some image layers to the WorldWindow's globe. wwd.engine.layers.apply { addLayer(BackgroundLayer()) - addLayer(MercatorLayerFactory.createLayer( + addLayer(WebMercatorLayerFactory.createLayer( name = "Google Satellite", urlTemplate = "https://mt.google.com/vt/lyrs=s&x={x}&y={y}&z={z}&hl={lang}", imageFormat = "image/jpeg" diff --git a/worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/MercatorTiledImageLayer.kt b/worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/MercatorTiledImageLayer.kt index 932be1e71..e7f7cf162 100644 --- a/worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/MercatorTiledImageLayer.kt +++ b/worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/MercatorTiledImageLayer.kt @@ -5,7 +5,6 @@ import earth.worldwind.geom.Angle.Companion.POS180 import earth.worldwind.geom.Location import earth.worldwind.geom.Sector import earth.worldwind.layer.TiledImageLayer -import earth.worldwind.layer.WebImageLayer import earth.worldwind.render.image.ImageConfig import earth.worldwind.render.image.ImageOptions import earth.worldwind.render.image.ImageSource @@ -14,8 +13,8 @@ import earth.worldwind.util.LevelSet import earth.worldwind.util.TileFactory abstract class MercatorTiledImageLayer( - name: String, numLevels: Int, tileSize: Int, override val imageFormat: String, override val isTransparent: Boolean -): TiledImageLayer(name), WebImageLayer { + name: String, numLevels: Int = 22, tileSize: Int = 256, transparent: Boolean = false +): TiledImageLayer(name) { private val tileFactory = object : TileFactory { override fun createTile(sector: Sector, level: Level, row: Int, column: Int) = MercatorImageTile(sector as MercatorSector, level, row, column).apply { @@ -33,7 +32,7 @@ abstract class MercatorTiledImageLayer( val levelSet = LevelSet(sector, tileOrigin, firstLevelDelta, numLevels, tileSize, tileSize, 1) tiledSurfaceImage = MercatorTiledSurfaceImage(tileFactory, levelSet).apply { // Reduce memory usage by using a 16-bit configuration with no alpha - if (!isTransparent) imageOptions = ImageOptions(ImageConfig.RGB_565) + if (!transparent) imageOptions = ImageOptions(ImageConfig.RGB_565) } } diff --git a/worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/MercatorLayerFactory.kt b/worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/WebMercatorLayerFactory.kt similarity index 92% rename from worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/MercatorLayerFactory.kt rename to worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/WebMercatorLayerFactory.kt index 0e65b88ff..85112cec3 100644 --- a/worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/MercatorLayerFactory.kt +++ b/worldwind/src/commonMain/kotlin/earth/worldwind/layer/mercator/WebMercatorLayerFactory.kt @@ -1,10 +1,11 @@ package earth.worldwind.layer.mercator +import earth.worldwind.layer.WebImageLayer import earth.worldwind.render.image.ImageSource import earth.worldwind.util.locale.language import kotlin.random.Random -object MercatorLayerFactory { +object WebMercatorLayerFactory { const val SERVICE_TYPE = "XYZ" private const val OPEN_BRACKET = '{' private const val CLOSED_BRACKET = '}' @@ -22,9 +23,11 @@ object MercatorLayerFactory { val randomValue = urlParts.find { it.startsWith(RAND_PREFIX) } val randomValues = randomValue?.removeSurrounding(RAND_PREFIX, "}")?.split(",") - return object : MercatorTiledImageLayer(name, numLevels, tileSize, imageFormat, transparent) { + return object : MercatorTiledImageLayer(name, numLevels, tileSize, transparent), WebImageLayer { override val serviceType = SERVICE_TYPE override val serviceAddress = urlTemplate + override val imageFormat = imageFormat + override val isTransparent = transparent private val resultServerUrl = StringBuilder() override fun getImageSource(x: Int, y: Int, z: Int): ImageSource { diff --git a/worldwind/src/jvmCommonMain/kotlin/earth/worldwind/ogc/GpkgContentManager.kt b/worldwind/src/jvmCommonMain/kotlin/earth/worldwind/ogc/GpkgContentManager.kt index bc0e1919a..bd19e66de 100644 --- a/worldwind/src/jvmCommonMain/kotlin/earth/worldwind/ogc/GpkgContentManager.kt +++ b/worldwind/src/jvmCommonMain/kotlin/earth/worldwind/ogc/GpkgContentManager.kt @@ -7,7 +7,7 @@ import earth.worldwind.globe.elevation.coverage.WebElevationCoverage import earth.worldwind.layer.CacheableImageLayer import earth.worldwind.layer.TiledImageLayer import earth.worldwind.layer.WebImageLayer -import earth.worldwind.layer.mercator.MercatorLayerFactory +import earth.worldwind.layer.mercator.WebMercatorLayerFactory import earth.worldwind.layer.mercator.MercatorTiledSurfaceImage import earth.worldwind.ogc.gpkg.AbstractGeoPackage import earth.worldwind.ogc.gpkg.GeoPackage @@ -41,7 +41,7 @@ class GpkgContentManager(pathName: String, readOnly: Boolean = false): ContentMa tiledSurfaceImage?.cacheTileFactory = GpkgTileFactory(content, service.outputFormat) } - MercatorLayerFactory.SERVICE_TYPE -> MercatorLayerFactory.createLayer( + WebMercatorLayerFactory.SERVICE_TYPE -> WebMercatorLayerFactory.createLayer( content.identifier, service.address, service.outputFormat, service.isTransparent, config.numLevels, config.tileHeight ).apply {