From 770f9125396c5622a8f129cf6dc9ba37b6ad59d9 Mon Sep 17 00:00:00 2001 From: Blottiere Paul Date: Tue, 17 Jun 2025 00:06:53 +0200 Subject: [PATCH] Use PharoOWS-TMS service to request tiles --- .../GeoViewGoogleTilesProvider.class.st | 56 +++++++------------ ...GeoViewOpenStreetMapTilesProvider.class.st | 38 +++---------- src/GeoView/GeoViewTilesProviderTMS.class.st | 40 +++++++++++++ 3 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 src/GeoView/GeoViewTilesProviderTMS.class.st diff --git a/src/GeoView/GeoViewGoogleTilesProvider.class.st b/src/GeoView/GeoViewGoogleTilesProvider.class.st index a14f845..4d24edc 100644 --- a/src/GeoView/GeoViewGoogleTilesProvider.class.st +++ b/src/GeoView/GeoViewGoogleTilesProvider.class.st @@ -1,8 +1,7 @@ Class { #name : #GeoViewGoogleTilesProvider, - #superclass : #GeoViewTilesProvider, + #superclass : #GeoViewTilesProviderTMS, #instVars : [ - 'serverUrl', 'tilesType' ], #category : #'GeoView-Map' @@ -35,37 +34,43 @@ GeoViewGoogleTilesProvider class >> primaryTileUrl [ { #category : #'tiles type' } GeoViewGoogleTilesProvider >> beHybridType [ - tilesType := 'y' + tilesType := 'y'. + self updateUrl ] { #category : #'tiles type' } GeoViewGoogleTilesProvider >> beRoadmapType [ - tilesType := 'm' + tilesType := 'm'. + self updateUrl ] { #category : #'tiles type' } GeoViewGoogleTilesProvider >> beRoadsOnlyType [ - tilesType := 'h' + tilesType := 'h'. + self updateUrl ] { #category : #'tiles type' } GeoViewGoogleTilesProvider >> beSatelliteType [ - tilesType := 's' + tilesType := 's'. + self updateUrl ] { #category : #'tiles type' } GeoViewGoogleTilesProvider >> beTerrainOnlyType [ - tilesType := 't' + tilesType := 't'. + self updateUrl ] { #category : #'tiles type' } GeoViewGoogleTilesProvider >> beTerrainType [ - tilesType := 'p' + tilesType := 'p'. + self updateUrl ] { #category : #initialization } @@ -79,34 +84,13 @@ GeoViewGoogleTilesProvider >> initialize [ ] { #category : #accessing } -GeoViewGoogleTilesProvider >> serverUrl [ - - ^ serverUrl ifNil: [ serverUrl := self class primaryTileUrl ] -] - -{ #category : #accessing } -GeoViewGoogleTilesProvider >> serverUrl: anObject [ - - serverUrl := anObject -] - -{ #category : #request } -GeoViewGoogleTilesProvider >> tileFilenameFor: aZoomLevel x: anXCoordinate y: anYCoordinate [ - - ^ self serverUrl , '/lyrs=' , ( tilesType asString ) , '&x=' , anXCoordinate printString , '&y=' - , anYCoordinate printString , '&z=' , aZoomLevel printString -] - -{ #category : #request } -GeoViewGoogleTilesProvider >> tileFor: aZoomLevel x: anXCoordinate y: anYCoordinate [ - - | url | - url := self - tileFilenameFor: aZoomLevel - x: anXCoordinate - y: anYCoordinate. +GeoViewGoogleTilesProvider >> updateUrl [ + | format | + + format := '.png'. (tilesType = 's' or:[tilesType = 'y' or:[tilesType = 't' or:[tilesType = 'p']]]) - ifTrue: [ ^ ZnEasy getJpeg: url ] - ifFalse: [ ^ ZnEasy getPng: url ] + ifTrue: [ format := '.jpg' ]. + + self service url: self serverUrl, '?lyrs=', ( tilesType asString ), '&x={x}&y={y}&z={z}&ext=', format ] diff --git a/src/GeoView/GeoViewOpenStreetMapTilesProvider.class.st b/src/GeoView/GeoViewOpenStreetMapTilesProvider.class.st index 7b17add..04da0d0 100644 --- a/src/GeoView/GeoViewOpenStreetMapTilesProvider.class.st +++ b/src/GeoView/GeoViewOpenStreetMapTilesProvider.class.st @@ -1,9 +1,6 @@ Class { #name : #GeoViewOpenStreetMapTilesProvider, - #superclass : #GeoViewTilesProvider, - #instVars : [ - 'serverUrl' - ], + #superclass : #GeoViewTilesProviderTMS, #category : #'GeoView-Map' } @@ -28,7 +25,9 @@ GeoViewOpenStreetMapTilesProvider class >> mirror2TileUrl [ { #category : #constants } GeoViewOpenStreetMapTilesProvider class >> primaryTileUrl [ + "^ 'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png'" ^ 'https://a.tile.openstreetmap.org' + ] { #category : #initialization } @@ -36,35 +35,12 @@ GeoViewOpenStreetMapTilesProvider >> initialize [ super initialize. self haveCopyrightNote: true. - self defaultCopyrightNote: self class attributionText + self defaultCopyrightNote: self class attributionText. + self updateUrl ] { #category : #accessing } -GeoViewOpenStreetMapTilesProvider >> serverUrl [ +GeoViewOpenStreetMapTilesProvider >> updateUrl [ - ^ serverUrl ifNil: [ serverUrl := self class primaryTileUrl ] -] - -{ #category : #accessing } -GeoViewOpenStreetMapTilesProvider >> serverUrl: anObject [ - - serverUrl := anObject -] - -{ #category : #request } -GeoViewOpenStreetMapTilesProvider >> tileFilenameFor: aZoomLevel x: anXCoordinate y: anYCoordinate [ - - ^ self serverUrl , '/' , aZoomLevel printString , '/' - , anXCoordinate printString , '/' , anYCoordinate printString - , '.png' -] - -{ #category : #request } -GeoViewOpenStreetMapTilesProvider >> tileFor: aZoomLevel x: anXCoordinate y: anYCoordinate [ - - ^ ZnEasy getPng: - (self - tileFilenameFor: aZoomLevel - x: anXCoordinate - y: anYCoordinate) + self service url: self serverUrl, '/{z}/{x}/{y}.png' ] diff --git a/src/GeoView/GeoViewTilesProviderTMS.class.st b/src/GeoView/GeoViewTilesProviderTMS.class.st new file mode 100644 index 0000000..feba221 --- /dev/null +++ b/src/GeoView/GeoViewTilesProviderTMS.class.st @@ -0,0 +1,40 @@ +Class { + #name : #GeoViewTilesProviderTMS, + #superclass : #GeoViewTilesProvider, + #instVars : [ + 'service', + 'serverUrl' + ], + #category : #'GeoView-Map' +} + +{ #category : #accessing } +GeoViewTilesProviderTMS >> serverUrl [ + + ^ serverUrl ifNil: [ serverUrl := self class primaryTileUrl ] +] + +{ #category : #accessing } +GeoViewTilesProviderTMS >> serverUrl: anObject [ + + serverUrl := anObject. + self updateUrl +] + +{ #category : #accessing } +GeoViewTilesProviderTMS >> service [ + + ^ service ifNil: [ service := PharoOWSTMS new ] +] + +{ #category : #request } +GeoViewTilesProviderTMS >> tileFor: aZoomLevel x: anXCoordinate y: anYCoordinate [ + + ^ self service tile: anXCoordinate y: anYCoordinate z: aZoomLevel +] + +{ #category : #accessing } +GeoViewTilesProviderTMS >> updateUrl [ + + self subclassResponsibility +]