Skip to content

Commit

Permalink
Make Mercator Image Layer not a Web Layer by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksymenko committed Jan 10, 2024
1 parent 014aa9f commit b192c06
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h2>Get Started</h2>
// 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 = '}'
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b192c06

Please sign in to comment.