"HERE" addons and layer modifications

Layers are now map and list based to facilitate ordering and deletion
This commit is contained in:
djes
2017-03-15 18:17:51 +01:00
parent c1b55ef8c3
commit 2346bf3b33

157
PBMap.pb
View File

@@ -51,10 +51,11 @@ DeclareModule PBMap
Declare LoadOptions(PreferencesFile.s = "PBMap.prefs") Declare LoadOptions(PreferencesFile.s = "PBMap.prefs")
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 DeleteLayer(*Ptr) Declare IsLayer(Name.s)
Declare EnableLayer(*Ptr) Declare DeleteLayer(Name.s)
Declare DisableLayer(*Ptr) Declare EnableLayer(Name.s)
Declare DisableLayer(Name.s)
Declare BindMapGadget(Gadget.i) Declare BindMapGadget(Gadget.i)
Declare SetCallBackLocation(*CallBackLocation) Declare SetCallBackLocation(*CallBackLocation)
Declare SetCallBackMainPointer(CallBackMainPointer.i) Declare SetCallBackMainPointer(CallBackMainPointer.i)
@@ -200,6 +201,9 @@ Module PBMap
ColourFocus.i ColourFocus.i
ColourSelected.i ColourSelected.i
ColourTrackDefault.i ColourTrackDefault.i
;HERE specific
appid.s
appcode.s
EndStructure EndStructure
Structure Layer Structure Layer
@@ -221,7 +225,7 @@ Module PBMap
lg2.s lg2.s
;< ;<
EndStructure EndStructure
Structure Box Structure Box
x1.i x1.i
y1.i y1.i
@@ -255,7 +259,8 @@ Module PBMap
PixelCoordinates.PixelCoordinates ; Actual focus point coords in pixels (global) PixelCoordinates.PixelCoordinates ; Actual focus point coords in pixels (global)
MoveStartingPoint.PixelCoordinates ; Start mouse position coords when dragging the map MoveStartingPoint.PixelCoordinates ; Start mouse position coords when dragging the map
List Layers.Layer() ; List LayersList.Layer()
Map *Layers.Layer()
Angle.d Angle.d
ZoomMin.i ; Min Zoom supported by server ZoomMin.i ; Min Zoom supported by server
@@ -284,7 +289,7 @@ Module PBMap
;-*** Global variables ;-*** Global variables
;-Show debug infos ;-Show debug infos
Global MyDebugLevel = 0 Global MyDebugLevel = 2
Global PBMap.PBMap, Null.i Global PBMap.PBMap, Null.i
Global slash.s Global slash.s
@@ -625,6 +630,10 @@ Module PBMap
PBMap\Options\ProxyPort = Value PBMap\Options\ProxyPort = Value
Case "proxyuser" Case "proxyuser"
PBMap\Options\ProxyUser = Value PBMap\Options\ProxyUser = Value
Case "appid"
PBMap\Options\appid = Value
Case "appcode"
PBMap\Options\appcode = Value
Case "tilescachepath" Case "tilescachepath"
PBMap\Options\HDDCachePath = Value PBMap\Options\HDDCachePath = Value
Case "maxmemcache" Case "maxmemcache"
@@ -677,6 +686,9 @@ Module PBMap
WritePreferenceString("ProxyURL", \ProxyURL) WritePreferenceString("ProxyURL", \ProxyURL)
WritePreferenceString("ProxyPort", \ProxyPort) WritePreferenceString("ProxyPort", \ProxyPort)
WritePreferenceString("ProxyUser", \ProxyUser) WritePreferenceString("ProxyUser", \ProxyUser)
PreferenceGroup("HERE")
WritePreferenceString("APP_ID", \appid)
WritePreferenceString("APP_CODE", \appcode)
PreferenceGroup("URL") PreferenceGroup("URL")
WritePreferenceString("DefaultOSMServer", \DefaultOSMServer) WritePreferenceString("DefaultOSMServer", \DefaultOSMServer)
PreferenceGroup("PATHS") PreferenceGroup("PATHS")
@@ -723,6 +735,9 @@ Module PBMap
; WritePreferenceString("ProxyPort", "myproxyport") ; WritePreferenceString("ProxyPort", "myproxyport")
; WritePreferenceString("ProxyUser", "myproxyname") ; WritePreferenceString("ProxyUser", "myproxyname")
; WritePreferenceString("ProxyPass", "myproxypass") ;TODO !Warning! !not encoded! ; WritePreferenceString("ProxyPass", "myproxypass") ;TODO !Warning! !not encoded!
; PreferenceGroup("HERE")
; WritePreferenceString("APP_ID", "myhereid") ;TODO !Warning! !not encoded!
; WritePreferenceString("APP_CODE", "myherecode") ;TODO !Warning! !not encoded!
; ClosePreferences() ; ClosePreferences()
With PBMap\Options With PBMap\Options
PreferenceGroup("PROXY") PreferenceGroup("PROXY")
@@ -731,8 +746,11 @@ Module PBMap
\ProxyURL = ReadPreferenceString("ProxyURL", "") ;InputRequester("ProxyServer", "Do you use a Proxy Server? Then enter the full url:", "") \ProxyURL = ReadPreferenceString("ProxyURL", "") ;InputRequester("ProxyServer", "Do you use a Proxy Server? Then enter the full url:", "")
\ProxyPort = ReadPreferenceString("ProxyPort", "") ;InputRequester("ProxyPort" , "Do you use a specific port? Then enter it", "") \ProxyPort = ReadPreferenceString("ProxyPort", "") ;InputRequester("ProxyPort" , "Do you use a specific port? Then enter it", "")
\ProxyUser = ReadPreferenceString("ProxyUser", "") ;InputRequester("ProxyUser" , "Do you use a user name? Then enter it", "") \ProxyUser = ReadPreferenceString("ProxyUser", "") ;InputRequester("ProxyUser" , "Do you use a user name? Then enter it", "")
\ProxyPassword = InputRequester("ProxyPass", "Do you use a password ? Then enter it", "") ;TODO \ProxyPassword = ReadPreferenceString("ProxyPass", "") ;InputRequester("ProxyPass", "Do you use a password ? Then enter it", "") ;TODO
EndIf EndIf
PreferenceGroup("HERE")
\appid = ReadPreferenceString("APP_ID", "") ;InputRequester("Here App ID", "Do you use HERE ? Enter app ID", "") ;TODO
\appcode = ReadPreferenceString("APP_CODE", "") ;InputRequester("Here App Code", "Do you use HERE ? Enter app Code", "") ;TODO
PreferenceGroup("URL") PreferenceGroup("URL")
\DefaultOSMServer = ReadPreferenceString("DefaultOSMServer", "http://tile.openstreetmap.org/") \DefaultOSMServer = ReadPreferenceString("DefaultOSMServer", "http://tile.openstreetmap.org/")
@@ -765,16 +783,31 @@ Module PBMap
;-*** Layers ;-*** Layers
;Add a layer to a list (to get things ordered) and to a map (to access things easily)
Procedure.i AddLayer(Name.s, Order.i)
Protected *Ptr = 0
*Ptr = AddMapElement(PBMap\Layers(), Name)
If *Ptr
PBMap\Layers() = AddElement(PBMap\LayersList()) ; This map element is a ptr to a linked list element
If PBMap\Layers()
PBMap\LayersList()\Name = Name
PBMap\LayersList()\Order = Order
ProcedureReturn PBMap\Layers()
Else
*Ptr = 0
EndIf
EndIf
ProcedureReturn *Ptr
EndProcedure
; "OpenStreetMap" layer ; "OpenStreetMap" layer
Procedure.i AddOSMServerLayer(LayerName.s, Order.i, ServerURL.s = "http://tile.openstreetmap.org/") Procedure.i AddOSMServerLayer(LayerName.s, Order.i, ServerURL.s = "http://tile.openstreetmap.org/")
Protected *Ptr = AddElement(PBMap\Layers()) Protected *Ptr.Layer = AddLayer(LayerName, Order)
If *Ptr If *Ptr
PBMap\Layers()\Name = LayerName *Ptr\ServerURL = ServerURL
PBMap\Layers()\Order = Order *Ptr\LayerType = 0 ; OSM
PBMap\Layers()\ServerURL = ServerURL *Ptr\Enabled = #True
PBMap\Layers()\LayerType = 0 ; OSM SortStructuredList(PBMap\LayersList(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order))
PBMap\Layers()\Enabled = #True
SortStructuredList(PBMap\Layers(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order))
ProcedureReturn *Ptr ProcedureReturn *Ptr
Else Else
ProcedureReturn #False ProcedureReturn #False
@@ -785,17 +818,21 @@ Module PBMap
;see there for parameters : https://developer.here.com/rest-apis/documentation/enterprise-map-tile/topics/resource-base-maptile.html ;see there for parameters : https://developer.here.com/rest-apis/documentation/enterprise-map-tile/topics/resource-base-maptile.html
;you could use base.maps.api.here.com or aerial.maps.api.here.com or traffic.maps.api.here.com or pano.maps.api.here.com. ;you could use base.maps.api.here.com or aerial.maps.api.here.com or traffic.maps.api.here.com or pano.maps.api.here.com.
;use *.cit.map.api.com For Customer Integration Testing (see https://developer.here.com/rest-apis/documentation/enterprise-Map-tile/common/request-cit-environment-rest.html) ;use *.cit.map.api.com For Customer Integration Testing (see https://developer.here.com/rest-apis/documentation/enterprise-Map-tile/common/request-cit-environment-rest.html)
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 = AddElement(PBMap\Layers()) Protected *Ptr.Layer = AddLayer(LayerName, Order)
If *Ptr If *Ptr
With PBMap\Layers() With *Ptr;PBMap\Layers()
\Name = LayerName
\Order = Order
\ServerURL = ServerURL \ServerURL = ServerURL
\path = path \path = path
\ressource = ressource \ressource = ressource
\LayerType = 1 ; HERE \LayerType = 1 ; HERE
\Enabled = #True \Enabled = #True
If APP_ID = ""
APP_ID = PBMap\Options\appid
EndIf
If APP_CODE = ""
APP_CODE = PBMap\Options\appcode
EndIf
\APP_CODE = APP_CODE \APP_CODE = APP_CODE
\APP_ID = APP_ID \APP_ID = APP_ID
\format = format \format = format
@@ -805,32 +842,33 @@ Module PBMap
\param = param \param = param
\scheme = scheme \scheme = scheme
EndWith EndWith
SortStructuredList(PBMap\Layers(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order)) SortStructuredList(PBMap\LayersList(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order))
ProcedureReturn *Ptr ProcedureReturn *Ptr
Else Else
ProcedureReturn #False ProcedureReturn #False
EndIf EndIf
EndProcedure EndProcedure
Procedure DeleteLayer(*Ptr) Procedure.i IsLayer(Name.s)
ChangeCurrentElement(PBMap\Layers(), *Ptr) ProcedureReturn FindMapElement(PBMap\Layers(), Name)
DeleteElement(PBMap\Layers())
SortStructuredList(PBMap\Layers(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order))
FirstElement(PBMap\Layers())
EndProcedure EndProcedure
Procedure EnableLayer(*Ptr) Procedure DeleteLayer(Name.s)
PushListPosition(PBMap\Layers()) FindMapElement(PBMap\Layers(), Name)
ChangeCurrentElement(PBMap\Layers(), *Ptr) Protected *Ptr = PBMap\Layers()
PBMap\Layers()\Enabled = #True ;Free the list element
PopListPosition(PBMap\Layers()) ChangeCurrentElement(PBMap\LayersList(), *Ptr)
DeleteElement(PBMap\LayersList())
;Free the map element
DeleteMapElement(PBMap\Layers())
EndProcedure EndProcedure
Procedure DisableLayer(*Ptr) Procedure EnableLayer(Name.s)
PushListPosition(PBMap\Layers()) PBMap\Layers(Name)\Enabled = #True
ChangeCurrentElement(PBMap\Layers(), *Ptr) EndProcedure
PBMap\Layers()\Enabled = #False
PopListPosition(PBMap\Layers()) Procedure DisableLayer(Name.s)
PBMap\Layers(Name)\Enabled = #False
EndProcedure EndProcedure
;-*** These are threaded ;-*** These are threaded
@@ -987,7 +1025,7 @@ Module PBMap
ProcedureReturn *timg ProcedureReturn *timg
EndProcedure EndProcedure
Procedure DrawTiles(*Drawing.DrawingParameters, Layer) Procedure DrawTiles(*Drawing.DrawingParameters, LayerName.s)
Protected x.i, y.i,kq.q Protected x.i, y.i,kq.q
Protected tx = Int(*Drawing\TileCoordinates\x) ;Don't forget the Int() ! Protected tx = Int(*Drawing\TileCoordinates\x) ;Don't forget the Int() !
Protected ty = Int(*Drawing\TileCoordinates\y) Protected ty = Int(*Drawing\TileCoordinates\y)
@@ -997,7 +1035,7 @@ Module PBMap
Protected URL.s, CacheFile.s Protected URL.s, CacheFile.s
Protected tilemax = 1<<PBMap\Zoom Protected tilemax = 1<<PBMap\Zoom
Protected HereLoadBalancing.b ;Here is providing a load balancing system Protected HereLoadBalancing.b ;Here is providing a load balancing system
SelectElement(PBMap\Layers(), Layer) FindMapElement(PBMap\Layers(), LayerName)
MyDebug("Drawing tiles") MyDebug("Drawing tiles")
For y = - ny - 1 To ny + 1 For y = - ny - 1 To ny + 1
For x = - nx - 1 To nx + 1 For x = - nx - 1 To nx + 1
@@ -1010,9 +1048,9 @@ Module PBMap
tiley = ty + y tiley = ty + y
If tiley >= 0 And tiley < tilemax If tiley >= 0 And tiley < tilemax
kq = (PBMap\Zoom << 8) | (tilex << 16) | (tiley << 36) kq = (PBMap\Zoom << 8) | (tilex << 16) | (tiley << 36)
key = PBMap\Layers()\Name + Str(kq) key = LayerName + Str(kq)
; Creates the cache tree based on the OSM tree+Layer : layer/zoom/x/y.png ; Creates the cache tree based on the OSM tree+Layer : layer/zoom/x/y.png
Protected DirName.s = PBMap\Options\HDDCachePath + PBMap\Layers()\Name Protected DirName.s = PBMap\Options\HDDCachePath + LayerName
If FileSize(DirName) <> -2 If FileSize(DirName) <> -2
If CreateDirectory(DirName) = #False ; Creates a directory based on the layer name If CreateDirectory(DirName) = #False ; Creates a directory based on the layer name
Error("Can't create the following layer directory : " + DirName) Error("Can't create the following layer directory : " + DirName)
@@ -1038,7 +1076,7 @@ Module PBMap
MyDebug(DirName + " successfully created", 4) MyDebug(DirName + " successfully created", 4)
EndIf EndIf
EndIf EndIf
With PBMap\Layers() With PBMap\LayersList()
Select \LayerType Select \LayerType
Case 0 ;OSM Case 0 ;OSM
URL = \ServerURL + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + ".png" URL = \ServerURL + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + ".png"
@@ -1552,6 +1590,7 @@ Module PBMap
Protected *Drawing.DrawingParameters = @PBMap\Drawing Protected *Drawing.DrawingParameters = @PBMap\Drawing
Protected PixelCenter.PixelCoordinates Protected PixelCenter.PixelCoordinates
Protected Px.d, Py.d,a, ts = PBMap\TileSize, nx, ny Protected Px.d, Py.d,a, ts = PBMap\TileSize, nx, ny
Protected LayerOrder.i = 0
Protected NW.Coordinates, SE.Coordinates Protected NW.Coordinates, SE.Coordinates
PBMap\Dirty = #False PBMap\Dirty = #False
PBMap\Redraw = #False PBMap\Redraw = #False
@@ -1586,9 +1625,9 @@ Module PBMap
FillVectorOutput() FillVectorOutput()
;TODO add in layers of tiles ;this way we can cache them as 0 base 1.n layers ;TODO add in layers of tiles ;this way we can cache them as 0 base 1.n layers
; such as for openseamap tiles which are overlaid. not that efficent from here though. ; such as for openseamap tiles which are overlaid. not that efficent from here though.
ForEach PBMap\Layers() ForEach PBMap\LayersList()
If PBMap\Layers()\Enabled If PBMap\LayersList()\Enabled
DrawTiles(*Drawing, ListIndex(PBMap\Layers())) DrawTiles(*Drawing, PBMap\LayersList()\Name)
EndIf EndIf
Next Next
If PBMap\Options\ShowTrack If PBMap\Options\ShowTrack
@@ -2368,7 +2407,7 @@ CompilerIf #PB_Compiler_IsMainFile
;*** ;***
Define Event.i, Gadget.i, Quit.b = #False Define Event.i, Gadget.i, Quit.b = #False
Define pfValue.d Define pfValue.d
Define OpenSeaMap = 0, HereMap = 0, Degrees = 1 Define Degrees = 1
Define *Track Define *Track
;Our main gadget ;Our main gadget
@@ -2386,7 +2425,6 @@ CompilerIf #PB_Compiler_IsMainFile
PBMap::SetLocation(-36.81148, 175.08634,12) ; Change the PBMap coordinates PBMap::SetLocation(-36.81148, 175.08634,12) ; Change the PBMap coordinates
PBMAP::SetMapScaleUnit(PBMAP::#SCALE_KM) ; To change the scale unit PBMAP::SetMapScaleUnit(PBMAP::#SCALE_KM) ; To change the scale unit
PBMap::AddMarker(49.0446828398, 2.0349812508, "", "", -1, @MyMarker()) ; To add a marker with a customised GFX PBMap::AddMarker(49.0446828398, 2.0349812508, "", "", -1, @MyMarker()) ; To add a marker with a customised GFX
;PBMap::AddHereServerLayer("Here", 3, "2WbegPQlhdWwkwF6rtBP", "Js2e6a82ovHndsSOu5vziw")
Repeat Repeat
Event = WaitWindowEvent() Event = WaitWindowEvent()
@@ -2426,23 +2464,21 @@ CompilerIf #PB_Compiler_IsMainFile
Case #Gdt_AddMarker Case #Gdt_AddMarker
PBMap::AddMarker(ValD(GetGadgetText(#StringLatitude)), ValD(GetGadgetText(#StringLongitude)), "", "Test", RGBA(Random(255), Random(255), Random(255), 255)) PBMap::AddMarker(ValD(GetGadgetText(#StringLatitude)), ValD(GetGadgetText(#StringLongitude)), "", "Test", RGBA(Random(255), Random(255), Random(255), 255))
Case #Gdt_AddOpenseaMap Case #Gdt_AddOpenseaMap
If OpenSeaMap = 0 If PBMap::IsLayer("OpenSeaMap")
OpenSeaMap = PBMap::AddOSMServerLayer("OpenSeaMap", 3, "http://t1.openseamap.org/seamark/") ; Add a special osm overlay map on layer nb 3 PBMap::DeleteLayer("OpenSeaMap")
SetGadgetState(#Gdt_AddOpenseaMap, 1)
Else
PBMap::DeleteLayer(OpenSeaMap)
OpenSeaMap = 0
SetGadgetState(#Gdt_AddOpenseaMap, 0) SetGadgetState(#Gdt_AddOpenseaMap, 0)
Else
PBMap::AddOSMServerLayer("OpenSeaMap", 3, "http://t1.openseamap.org/seamark/") ; Add a special osm overlay map on layer nb 3
SetGadgetState(#Gdt_AddOpenseaMap, 1)
EndIf EndIf
PBMap::Refresh() PBMap::Refresh()
Case #Gdt_AddHereMap Case #Gdt_AddHereMap
If HereMap = 0 If PBMap::IsLayer("Here")
HereMap = PBMap::AddHereServerLayer("Here", 2, "2WbegPQlhdWwkwF6rtBP", "Js2e6a82ovHndsSOu5vziw") ; Add a here overlay map on layer nb 2 PBMap::DeleteLayer("Here")
SetGadgetState(#Gdt_AddHereMap, 1)
Else
PBMap::DeleteLayer(HereMap)
HereMap = 0
SetGadgetState(#Gdt_AddHereMap, 0) SetGadgetState(#Gdt_AddHereMap, 0)
Else
PBMap::AddHereServerLayer("Here", 2) ; Add a here overlay map on layer nb 2
SetGadgetState(#Gdt_AddHereMap, 1)
EndIf EndIf
PBMap::Refresh() PBMap::Refresh()
Case #Gdt_Degrees Case #Gdt_Degrees
@@ -2494,10 +2530,9 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.60 beta 7 (Windows - x64) ; IDE Options = PureBasic 5.60 beta 7 (Windows - x64)
; CursorPosition = 769 ; CursorPosition = 57
; FirstLine = 751 ; FirstLine = 32
; Folding = ------------------ ; Folding = ------------------
; EnableThread ; EnableThread
; EnableXP ; EnableXP
; DisableDebugger
; EnableUnicode ; EnableUnicode