Geoserver layers support

Basic geoserver support (google maps services only by now)
This commit is contained in:
djes
2017-04-03 11:32:08 +02:00
parent d5cd0cd6f3
commit c1a650bce5

View File

@@ -53,6 +53,7 @@ DeclareModule PBMap
Declare SaveOptions(PreferencesFile.s = "PBMap.prefs") Declare SaveOptions(PreferencesFile.s = "PBMap.prefs")
Declare.i AddOSMServerLayer(LayerName.s, Order.i, ServerURL.s = "http://tile.openstreetmap.org/") Declare.i AddOSMServerLayer(LayerName.s, Order.i, ServerURL.s = "http://tile.openstreetmap.org/")
Declare.i AddHereServerLayer(LayerName.s, Order.i, APP_ID.s = "", APP_CODE.s = "", ServerURL.s = "aerial.maps.api.here.com", path.s = "/maptile/2.1/", ressource.s = "maptile", id.s = "newest", scheme.s = "satellite.day", format.s = "jpg", lg.s = "eng", lg2.s = "eng", param.s = "") Declare.i AddHereServerLayer(LayerName.s, Order.i, APP_ID.s = "", APP_CODE.s = "", ServerURL.s = "aerial.maps.api.here.com", path.s = "/maptile/2.1/", ressource.s = "maptile", id.s = "newest", scheme.s = "satellite.day", format.s = "jpg", lg.s = "eng", lg2.s = "eng", param.s = "")
Declare.i AddGeoServerLayer(LayerName.s, Order.i, ServerLayerName.s, ServerURL.s = "http://localhost:8080/", path.s = "geowebcache/service/gmaps", format.s = "image/png")
Declare IsLayer(Name.s) Declare IsLayer(Name.s)
Declare DeleteLayer(Name.s) Declare DeleteLayer(Name.s)
Declare EnableLayer(Name.s) Declare EnableLayer(Name.s)
@@ -216,21 +217,24 @@ Module PBMap
Order.i ; Layer nb Order.i ; Layer nb
Name.s Name.s
ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/ ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/
path.s
LayerType.i ; OSM : 0 ; Here : 1 LayerType.i ; OSM : 0 ; Here : 1
Enabled.i Enabled.i
Alpha.d ; 1 : opaque ; 0 : transparent Alpha.d ; 1 : opaque ; 0 : transparent
format.s
;> HERE specific params ;> HERE specific params
APP_ID.s APP_ID.s
APP_CODE.s APP_CODE.s
path.s
ressource.s ressource.s
param.s param.s
id.s id.s
scheme.s scheme.s
format.s
lg.s lg.s
lg2.s lg2.s
;< ;<
;> GeoServer specific params
ServerLayerName.s
;<
EndStructure EndStructure
Structure Box Structure Box
@@ -935,7 +939,7 @@ Module PBMap
Procedure.i AddHereServerLayer(LayerName.s, Order.i, APP_ID.s = "", APP_CODE.s = "", ServerURL.s = "aerial.maps.api.here.com", path.s = "/maptile/2.1/", ressource.s = "maptile", id.s = "newest", scheme.s = "satellite.day", format.s = "jpg", lg.s = "eng", lg2.s = "eng", param.s = "") Procedure.i AddHereServerLayer(LayerName.s, Order.i, APP_ID.s = "", APP_CODE.s = "", ServerURL.s = "aerial.maps.api.here.com", path.s = "/maptile/2.1/", ressource.s = "maptile", id.s = "newest", scheme.s = "satellite.day", format.s = "jpg", lg.s = "eng", lg2.s = "eng", param.s = "")
Protected *Ptr.Layer = AddLayer(LayerName, Order, 1) Protected *Ptr.Layer = AddLayer(LayerName, Order, 1)
If *Ptr If *Ptr
With *Ptr;PBMap\Layers() With *Ptr ;PBMap\Layers()
\ServerURL = ServerURL \ServerURL = ServerURL
\path = path \path = path
\ressource = ressource \ressource = ressource
@@ -963,6 +967,26 @@ Module PBMap
EndIf EndIf
EndProcedure EndProcedure
;GeoServer / geowebcache - google maps service
;template 'http://localhost:8080/geowebcache/service/gmaps?layers=layer-name&zoom={Z}&x={X}&y={Y}&format=image/png'
Procedure.i AddGeoServerLayer(LayerName.s, Order.i, ServerLayerName.s, ServerURL.s = "http://localhost:8080/", path.s = "geowebcache/service/gmaps", format.s = "image/png")
Protected *Ptr.Layer = AddLayer(LayerName, Order, 1)
If *Ptr
With *Ptr ;PBMap\Layers()
\ServerURL = ServerURL
\path = path
\LayerType = 2 ; GeoServer
\format = format
\Enabled = #True
\ServerLayerName = ServerLayerName
EndWith
PBMap\Redraw = #True
ProcedureReturn *Ptr
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure.i IsLayer(Name.s) Procedure.i IsLayer(Name.s)
ProcedureReturn FindMapElement(PBMap\Layers(), Name) ProcedureReturn FindMapElement(PBMap\Layers(), Name)
EndProcedure EndProcedure
@@ -1215,19 +1239,27 @@ Module PBMap
EndIf EndIf
With PBMap\Layers() With PBMap\Layers()
Select \LayerType Select \LayerType
Case 0 ;OSM ;---- OSM tiles
Case 0
URL = \ServerURL + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + ".png" URL = \ServerURL + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + ".png"
; Tile cache name based on y ; Tile cache name based on y
CacheFile = DirName + slash + Str(tiley) + ".png" CacheFile = DirName + slash + Str(tiley) + ".png"
Case 1 ;Here ;---- Here tiles
Case 1
HereLoadBalancing = 1 + ((tiley + tilex) % 4) HereLoadBalancing = 1 + ((tiley + tilex) % 4)
;{Base URL}{Path}{resource (tile type)}/{Map id}/{scheme}/{zoom}/{column}/{row}/{size}/{format}?app_id={YOUR_APP_ID}&app_code={YOUR_APP_CODE}&{param}={value} ; {Base URL}{Path}{resource (tile type)}/{Map id}/{scheme}/{zoom}/{column}/{row}/{size}/{format}?app_id={YOUR_APP_ID}&app_code={YOUR_APP_CODE}&{param}={value}
URL = "https://" + StrU(HereLoadBalancing, #PB_Byte) + "." + \ServerURL + \path + \ressource + "/" + \id + "/" + \scheme + "/" + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + "/256/" + \format + "?app_id=" + \APP_ID + "&app_code=" + \APP_CODE + "&lg=" + \lg + "&lg2=" + \lg2 URL = "https://" + StrU(HereLoadBalancing, #PB_Byte) + "." + \ServerURL + \path + \ressource + "/" + \id + "/" + \scheme + "/" + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + "/256/" + \format + "?app_id=" + \APP_ID + "&app_code=" + \APP_CODE + "&lg=" + \lg + "&lg2=" + \lg2
If \param <> "" If \param <> ""
URL + "&" + \param URL + "&" + \param
EndIf EndIf
; Tile cache name based on y ; Tile cache name based on y
CacheFile = DirName + slash + Str(tiley) + "." + \format CacheFile = DirName + slash + Str(tiley) + "." + \format
;---- GeoServer / geowebcache - google maps service tiles
Case 2
; template 'http://localhost:8080/geowebcache/service/gmaps?layers=layer-name&zoom={Z}&x={X}&y={Y}&format=image/png'
URL = \ServerURL + \path + "?layers=" + \ServerLayerName + "&zoom={" + Str(PBMap\Zoom) + "}&x={" + Str(tilex) + "}&y={" + Str(tiley) + "}&format=" + \format
; Tile cache name based on y
CacheFile = DirName + slash + Str(tiley) + ".png"
EndSelect EndSelect
EndWith EndWith
*timg = GetTile(key, URL, CacheFile) *timg = GetTile(key, URL, CacheFile)
@@ -2430,6 +2462,7 @@ CompilerIf #PB_Compiler_IsMainFile
#Gdt_AddMarker #Gdt_AddMarker
#Gdt_AddOpenseaMap #Gdt_AddOpenseaMap
#Gdt_AddHereMap #Gdt_AddHereMap
#Gdt_AddGeoServerMap
#Gdt_Degrees #Gdt_Degrees
#Gdt_EditMode #Gdt_EditMode
#Gdt_ClearDiskCache #Gdt_ClearDiskCache
@@ -2501,6 +2534,7 @@ CompilerIf #PB_Compiler_IsMainFile
ResizeGadget(#Gdt_SaveGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_SaveGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Gdt_AddOpenseaMap,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_AddOpenseaMap,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Gdt_AddHereMap,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_AddHereMap,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Gdt_AddGeoServerMap,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Gdt_Degrees,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_Degrees,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Gdt_EditMode,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_EditMode,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Gdt_ClearDiskCache,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_ClearDiskCache,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
@@ -2535,11 +2569,12 @@ CompilerIf #PB_Compiler_IsMainFile
ButtonGadget(#Gdt_SaveGpx, 530, 300, 150, 30, "Save GPX") ButtonGadget(#Gdt_SaveGpx, 530, 300, 150, 30, "Save GPX")
ButtonGadget(#Gdt_AddOpenseaMap, 530, 330, 150, 30, "Show/Hide OpenSeaMap", #PB_Button_Toggle) ButtonGadget(#Gdt_AddOpenseaMap, 530, 330, 150, 30, "Show/Hide OpenSeaMap", #PB_Button_Toggle)
ButtonGadget(#Gdt_AddHereMap, 530, 360, 150, 30, "Show/Hide HERE Aerial", #PB_Button_Toggle) ButtonGadget(#Gdt_AddHereMap, 530, 360, 150, 30, "Show/Hide HERE Aerial", #PB_Button_Toggle)
ButtonGadget(#Gdt_Degrees, 530, 390, 150, 30, "Show/Hide Degrees", #PB_Button_Toggle) ButtonGadget(#Gdt_AddGeoServerMap, 530, 390, 150, 30, "Show/Hide Geoserver layer", #PB_Button_Toggle)
ButtonGadget(#Gdt_EditMode, 530, 420, 150, 30, "Edit mode ON/OFF", #PB_Button_Toggle) ButtonGadget(#Gdt_Degrees, 530, 420, 150, 30, "Show/Hide Degrees", #PB_Button_Toggle)
ButtonGadget(#Gdt_ClearDiskCache, 530, 450, 150, 30, "Clear disk cache", #PB_Button_Toggle) ButtonGadget(#Gdt_EditMode, 530, 450, 150, 30, "Edit mode ON/OFF", #PB_Button_Toggle)
TextGadget(#TextGeoLocationQuery, 530, 485, 150, 15, "Enter an address") ButtonGadget(#Gdt_ClearDiskCache, 530, 480, 150, 30, "Clear disk cache", #PB_Button_Toggle)
StringGadget(#StringGeoLocationQuery, 530, 500, 150, 20, "") TextGadget(#TextGeoLocationQuery, 530, 515, 150, 15, "Enter an address")
StringGadget(#StringGeoLocationQuery, 530, 530, 150, 20, "")
SetActiveGadget(#StringGeoLocationQuery) SetActiveGadget(#StringGeoLocationQuery)
AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, #MenuEventGeoLocationStringEnter) AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, #MenuEventGeoLocationStringEnter)
;*** TODO : code to remove when the SetActiveGadget(-1) will be fixed ;*** TODO : code to remove when the SetActiveGadget(-1) will be fixed
@@ -2643,6 +2678,16 @@ CompilerIf #PB_Compiler_IsMainFile
SetGadgetState(#Gdt_AddHereMap, 1) SetGadgetState(#Gdt_AddHereMap, 1)
EndIf EndIf
PBMap::Refresh() PBMap::Refresh()
Case #Gdt_AddGeoServerMap
If PBMap::IsLayer("GeoServer")
PBMap::DeleteLayer("GeoServer")
SetGadgetState(#Gdt_AddGeoServerMap, 0)
Else
PBMap::AddGeoServerLayer("GeoServer", 3, "demolayer", "http://localhost:8080/", "geowebcache/service/gmaps", "image/png") ; Add a geoserver overlay map on layer nb 3
PBMap::SetLayerAlpha("GeoServer", 0.75)
SetGadgetState(#Gdt_AddGeoServerMap, 1)
EndIf
PBMap::Refresh()
Case #Gdt_Degrees Case #Gdt_Degrees
Degrees = 1 - Degrees Degrees = 1 - Degrees
PBMap::SetOption("ShowDegrees", Str(Degrees)) PBMap::SetOption("ShowDegrees", Str(Degrees))
@@ -2692,8 +2737,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.60 (Windows - x64) ; IDE Options = PureBasic 5.60 (Windows - x64)
; CursorPosition = 1503 ; CursorPosition = 2691
; FirstLine = 1488 ; FirstLine = 2684
; Folding = ------------------- ; Folding = -------------------
; EnableThread ; EnableThread
; EnableXP ; EnableXP