From 2346bf3b335154d1df5ce01866f428e3e0f10f5f Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 15 Mar 2017 18:17:51 +0100 Subject: [PATCH] "HERE" addons and layer modifications Layers are now map and list based to facilitate ordering and deletion --- PBMap.pb | 157 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 96 insertions(+), 61 deletions(-) diff --git a/PBMap.pb b/PBMap.pb index 28a3441..e195f75 100644 --- a/PBMap.pb +++ b/PBMap.pb @@ -51,10 +51,11 @@ DeclareModule PBMap Declare LoadOptions(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 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 EnableLayer(*Ptr) - Declare DisableLayer(*Ptr) + 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 IsLayer(Name.s) + Declare DeleteLayer(Name.s) + Declare EnableLayer(Name.s) + Declare DisableLayer(Name.s) Declare BindMapGadget(Gadget.i) Declare SetCallBackLocation(*CallBackLocation) Declare SetCallBackMainPointer(CallBackMainPointer.i) @@ -200,6 +201,9 @@ Module PBMap ColourFocus.i ColourSelected.i ColourTrackDefault.i + ;HERE specific + appid.s + appcode.s EndStructure Structure Layer @@ -221,7 +225,7 @@ Module PBMap lg2.s ;< EndStructure - + Structure Box x1.i y1.i @@ -255,7 +259,8 @@ Module PBMap PixelCoordinates.PixelCoordinates ; Actual focus point coords in pixels (global) MoveStartingPoint.PixelCoordinates ; Start mouse position coords when dragging the map - List Layers.Layer() ; + List LayersList.Layer() + Map *Layers.Layer() Angle.d ZoomMin.i ; Min Zoom supported by server @@ -284,7 +289,7 @@ Module PBMap ;-*** Global variables ;-Show debug infos - Global MyDebugLevel = 0 + Global MyDebugLevel = 2 Global PBMap.PBMap, Null.i Global slash.s @@ -625,6 +630,10 @@ Module PBMap PBMap\Options\ProxyPort = Value Case "proxyuser" PBMap\Options\ProxyUser = Value + Case "appid" + PBMap\Options\appid = Value + Case "appcode" + PBMap\Options\appcode = Value Case "tilescachepath" PBMap\Options\HDDCachePath = Value Case "maxmemcache" @@ -677,6 +686,9 @@ Module PBMap WritePreferenceString("ProxyURL", \ProxyURL) WritePreferenceString("ProxyPort", \ProxyPort) WritePreferenceString("ProxyUser", \ProxyUser) + PreferenceGroup("HERE") + WritePreferenceString("APP_ID", \appid) + WritePreferenceString("APP_CODE", \appcode) PreferenceGroup("URL") WritePreferenceString("DefaultOSMServer", \DefaultOSMServer) PreferenceGroup("PATHS") @@ -723,6 +735,9 @@ Module PBMap ; WritePreferenceString("ProxyPort", "myproxyport") ; WritePreferenceString("ProxyUser", "myproxyname") ; 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() With PBMap\Options PreferenceGroup("PROXY") @@ -731,8 +746,11 @@ Module PBMap \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", "") \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 + 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") \DefaultOSMServer = ReadPreferenceString("DefaultOSMServer", "http://tile.openstreetmap.org/") @@ -765,16 +783,31 @@ Module PBMap ;-*** 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 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 - PBMap\Layers()\Name = LayerName - PBMap\Layers()\Order = Order - PBMap\Layers()\ServerURL = ServerURL - PBMap\Layers()\LayerType = 0 ; OSM - PBMap\Layers()\Enabled = #True - SortStructuredList(PBMap\Layers(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order)) + *Ptr\ServerURL = ServerURL + *Ptr\LayerType = 0 ; OSM + *Ptr\Enabled = #True + SortStructuredList(PBMap\LayersList(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order)) ProcedureReturn *Ptr Else 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 ;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) - 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()) + 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) If *Ptr - With PBMap\Layers() - \Name = LayerName - \Order = Order + With *Ptr;PBMap\Layers() \ServerURL = ServerURL \path = path \ressource = ressource \LayerType = 1 ; HERE \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_ID = APP_ID \format = format @@ -805,32 +842,33 @@ Module PBMap \param = param \scheme = scheme 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 Else ProcedureReturn #False EndIf EndProcedure - Procedure DeleteLayer(*Ptr) - ChangeCurrentElement(PBMap\Layers(), *Ptr) - DeleteElement(PBMap\Layers()) - SortStructuredList(PBMap\Layers(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order)) - FirstElement(PBMap\Layers()) + Procedure.i IsLayer(Name.s) + ProcedureReturn FindMapElement(PBMap\Layers(), Name) EndProcedure - Procedure EnableLayer(*Ptr) - PushListPosition(PBMap\Layers()) - ChangeCurrentElement(PBMap\Layers(), *Ptr) - PBMap\Layers()\Enabled = #True - PopListPosition(PBMap\Layers()) + Procedure DeleteLayer(Name.s) + FindMapElement(PBMap\Layers(), Name) + Protected *Ptr = PBMap\Layers() + ;Free the list element + ChangeCurrentElement(PBMap\LayersList(), *Ptr) + DeleteElement(PBMap\LayersList()) + ;Free the map element + DeleteMapElement(PBMap\Layers()) EndProcedure - Procedure DisableLayer(*Ptr) - PushListPosition(PBMap\Layers()) - ChangeCurrentElement(PBMap\Layers(), *Ptr) - PBMap\Layers()\Enabled = #False - PopListPosition(PBMap\Layers()) + Procedure EnableLayer(Name.s) + PBMap\Layers(Name)\Enabled = #True + EndProcedure + + Procedure DisableLayer(Name.s) + PBMap\Layers(Name)\Enabled = #False EndProcedure ;-*** These are threaded @@ -987,7 +1025,7 @@ Module PBMap ProcedureReturn *timg EndProcedure - Procedure DrawTiles(*Drawing.DrawingParameters, Layer) + Procedure DrawTiles(*Drawing.DrawingParameters, LayerName.s) Protected x.i, y.i,kq.q Protected tx = Int(*Drawing\TileCoordinates\x) ;Don't forget the Int() ! Protected ty = Int(*Drawing\TileCoordinates\y) @@ -997,7 +1035,7 @@ Module PBMap Protected URL.s, CacheFile.s Protected tilemax = 1<= 0 And tiley < tilemax 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 - Protected DirName.s = PBMap\Options\HDDCachePath + PBMap\Layers()\Name + Protected DirName.s = PBMap\Options\HDDCachePath + LayerName If FileSize(DirName) <> -2 If CreateDirectory(DirName) = #False ; Creates a directory based on the layer name Error("Can't create the following layer directory : " + DirName) @@ -1038,7 +1076,7 @@ Module PBMap MyDebug(DirName + " successfully created", 4) EndIf EndIf - With PBMap\Layers() + With PBMap\LayersList() Select \LayerType Case 0 ;OSM URL = \ServerURL + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + ".png" @@ -1552,6 +1590,7 @@ Module PBMap Protected *Drawing.DrawingParameters = @PBMap\Drawing Protected PixelCenter.PixelCoordinates Protected Px.d, Py.d,a, ts = PBMap\TileSize, nx, ny + Protected LayerOrder.i = 0 Protected NW.Coordinates, SE.Coordinates PBMap\Dirty = #False PBMap\Redraw = #False @@ -1586,9 +1625,9 @@ Module PBMap FillVectorOutput() ;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. - ForEach PBMap\Layers() - If PBMap\Layers()\Enabled - DrawTiles(*Drawing, ListIndex(PBMap\Layers())) + ForEach PBMap\LayersList() + If PBMap\LayersList()\Enabled + DrawTiles(*Drawing, PBMap\LayersList()\Name) EndIf Next If PBMap\Options\ShowTrack @@ -2368,7 +2407,7 @@ CompilerIf #PB_Compiler_IsMainFile ;*** Define Event.i, Gadget.i, Quit.b = #False Define pfValue.d - Define OpenSeaMap = 0, HereMap = 0, Degrees = 1 + Define Degrees = 1 Define *Track ;Our main gadget @@ -2386,7 +2425,6 @@ CompilerIf #PB_Compiler_IsMainFile PBMap::SetLocation(-36.81148, 175.08634,12) ; Change the PBMap coordinates 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::AddHereServerLayer("Here", 3, "2WbegPQlhdWwkwF6rtBP", "Js2e6a82ovHndsSOu5vziw") Repeat Event = WaitWindowEvent() @@ -2426,23 +2464,21 @@ CompilerIf #PB_Compiler_IsMainFile Case #Gdt_AddMarker PBMap::AddMarker(ValD(GetGadgetText(#StringLatitude)), ValD(GetGadgetText(#StringLongitude)), "", "Test", RGBA(Random(255), Random(255), Random(255), 255)) Case #Gdt_AddOpenseaMap - If OpenSeaMap = 0 - OpenSeaMap = PBMap::AddOSMServerLayer("OpenSeaMap", 3, "http://t1.openseamap.org/seamark/") ; Add a special osm overlay map on layer nb 3 - SetGadgetState(#Gdt_AddOpenseaMap, 1) - Else - PBMap::DeleteLayer(OpenSeaMap) - OpenSeaMap = 0 + If PBMap::IsLayer("OpenSeaMap") + PBMap::DeleteLayer("OpenSeaMap") 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 PBMap::Refresh() Case #Gdt_AddHereMap - If HereMap = 0 - HereMap = PBMap::AddHereServerLayer("Here", 2, "2WbegPQlhdWwkwF6rtBP", "Js2e6a82ovHndsSOu5vziw") ; Add a here overlay map on layer nb 2 - SetGadgetState(#Gdt_AddHereMap, 1) - Else - PBMap::DeleteLayer(HereMap) - HereMap = 0 + If PBMap::IsLayer("Here") + PBMap::DeleteLayer("Here") SetGadgetState(#Gdt_AddHereMap, 0) + Else + PBMap::AddHereServerLayer("Here", 2) ; Add a here overlay map on layer nb 2 + SetGadgetState(#Gdt_AddHereMap, 1) EndIf PBMap::Refresh() Case #Gdt_Degrees @@ -2494,10 +2530,9 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.60 beta 7 (Windows - x64) -; CursorPosition = 769 -; FirstLine = 751 +; CursorPosition = 57 +; FirstLine = 32 ; Folding = ------------------ ; EnableThread ; EnableXP -; DisableDebugger ; EnableUnicode \ No newline at end of file