From f2ec2043e46362baebfe86f8f5cf9329e497d3bd Mon Sep 17 00:00:00 2001 From: djes Date: Fri, 22 Jul 2016 19:25:05 +0200 Subject: [PATCH 01/35] Wip --- osm.pb | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/osm.pb b/osm.pb index 8abffc0..a33ff34 100644 --- a/osm.pb +++ b/osm.pb @@ -1,4 +1,4 @@ -;************************************************************** +;************************************************************** ; Program: OSM (OpenStreetMap Module) ; Author: Thyphoon And Djes ; Date: Mai 17, 2016 @@ -49,6 +49,17 @@ Module OSM GetImageThread.i EndStructure + Structure DrawingParameters + x.d + y.d + OSMTileX.i + OSMTileY.i + OSMZoom.i + DeltaX.i + DeltaY.i + PassNb.i + EndStructure + Structure TileThread GetImageThread.i *Tile.Tile @@ -78,11 +89,9 @@ Module OSM Gadget.i ; Canvas Gadget Id TargetLocation.Location ; Latitude and Longitude from focus point - TargetTile.Tile ; Focus Tile coord + *Drawing.DrawingParameters ; Focus Tile coord Position.Pixel ; Actual focus Point coords in pixels - DeltaX.i - DeltaY.i MoveStartingPoint.Pixel ; Start mouse position coords when dragging the map ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/ @@ -582,7 +591,7 @@ Module OSM EndProcedure - Procedure DrawingThread(Null) + Procedure DrawingThread(*Drawing.DrawingParameters) Debug "--------- Main drawing thread ------------" OSM\Dirty = #False @@ -608,7 +617,14 @@ Module OSM If OSM\Dirty Debug "Something was dirty ! We try again to redraw" ;Delay(250) - CreateThread(@DrawingThread(), Null) + + *Drawing\PassNb + 1 + CreateThread(@DrawingThread(), *Drawing) + EndIf + + *Drawing\PassNb - 1 + If *Drawing\PassNb = 0 + FreeMemory(*TargetTile) EndIf EndProcedure @@ -655,6 +671,7 @@ Module OSM Protected MouseX.i, MouseY.i Protected OldX.i, OldY.i Protected TileX.d, TileY.d + Protected *Drawing.DrawingParameters If IsGadget(OSM\Gadget) And GadgetType(OSM\Gadget) = #PB_GadgetType_Canvas Select Event @@ -682,20 +699,22 @@ Module OSM ;OSM tile position in tile.decimal TileX = OSM\Position\x / OSM\TileSize TileY = OSM\Position\y / OSM\TileSize + *Drawing = AllocateMemory(SizeOf(*DrawingParameters)) ;Pixel shift - OSM\DeltaX = OSM\Position\x - Int(TileX) * OSM\TileSize - OSM\DeltaY = OSM\Position\y - Int(TileY) * OSM\TileSize + *Drawing\DeltaX = OSM\Position\x - Int(TileX) * OSM\TileSize + *Drawing\DeltaY = OSM\Position\y - Int(TileY) * OSM\TileSize ;Moved to a new tile ? If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) Debug "--- New tile" - OSM\TargetTile\x = TileX - OSM\TargetTile\y = TileY + *TargetTile\x = TileX + *TargetTile\y = TileY Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) - XY2LatLon(@OSM\TargetTile, @OSM\TargetLocation) - Debug "OSM\TargetTile\x " + StrD(OSM\TargetTile\x) + " ; OSM\TargetTile\y " + StrD(OSM\TargetTile\y) + XY2LatLon(*Drawing, @OSM\TargetLocation) + Debug "OSM\TargetTile\x " + StrD(*Drawing\x) + " ; OSM\TargetTile\y " + StrD(*Drawing\y) EndIf OSM\EmergencyQuit = #False - CreateThread(@DrawingThread(), Null) + *Drawing\PassNb = 1 + CreateThread(@DrawingThread(), *Drawing) OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) EndIf @@ -783,11 +802,3 @@ If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_System EndSelect Until Quit = #True EndIf - -; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 250 -; FirstLine = 231 -; Folding = ----- -; EnableUnicode -; EnableThread -; EnableXP \ No newline at end of file From 0ed61605742c1671826f1b5e9e6cd87bf812cbc0 Mon Sep 17 00:00:00 2001 From: djes Date: Fri, 22 Jul 2016 19:32:21 +0200 Subject: [PATCH 02/35] Wip Lil bugfix --- osm.pb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osm.pb b/osm.pb index a33ff34..be7f138 100644 --- a/osm.pb +++ b/osm.pb @@ -706,8 +706,8 @@ Module OSM ;Moved to a new tile ? If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) Debug "--- New tile" - *TargetTile\x = TileX - *TargetTile\y = TileY + *Drawing\x = TileX + *Drawing\y = TileY Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) XY2LatLon(*Drawing, @OSM\TargetLocation) Debug "OSM\TargetTile\x " + StrD(*Drawing\x) + " ; OSM\TargetTile\y " + StrD(*Drawing\y) From 90ce8410078958504edd709abcbcaca57356d8b5 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 25 Jul 2016 12:30:33 +0200 Subject: [PATCH 03/35] Cleaning and add --- Roller.gpx | 9706 ++++++++++++++++++++++++++++++++++++++++++++++++++++ osm.pb | 228 +- 2 files changed, 9821 insertions(+), 113 deletions(-) create mode 100644 Roller.gpx diff --git a/Roller.gpx b/Roller.gpx new file mode 100644 index 0000000..d286dad --- /dev/null +++ b/Roller.gpx @@ -0,0 +1,9706 @@ + + + + Haaaaaaaa une bonne grosse montée après une petite pluie puis le reste de la rando sous une bonne pluie. Mais tip top! + + 2016 + http://www.runtastic.com + + + runtastic + + + + + + Cliquez sur ce lien pour voir cette activité sur Runtastic.com + + + + 91.0 + + + + 91.0 + + + + 89.0 + + + + 88.0 + + + + 88.0 + + + + 86.0 + + + + 86.0 + + + + 86.0 + + + + 87.0 + + + + 88.0 + + + + 88.0 + + + + 88.0 + + + + 86.0 + + + + 86.0 + + + + 87.0 + + + + 87.0 + + + + 85.0 + + + + 85.0 + + + + 84.0 + + + + 85.0 + + + + 85.0 + + + + 85.0 + + + + 87.0 + + + + 85.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 83.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 81.0 + + + + 82.0 + + + + 83.0 + + + + 85.0 + + + + 85.0 + + + + 86.0 + + + + 86.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 86.0 + + + + 84.0 + + + + 85.0 + + + + 86.0 + + + + 85.0 + + + + 85.0 + + + + 84.0 + + + + 84.0 + + + + 83.0 + + + + 81.0 + + + + 81.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 83.0 + + + + 83.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 82.0 + + + + 83.0 + + + + 82.0 + + + + 83.0 + + + + 82.0 + + + + 81.0 + + + + 81.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 80.0 + + + + 78.0 + + + + 78.0 + + + + 79.0 + + + + 78.0 + + + + 79.0 + + + + 79.0 + + + + 79.0 + + + + 78.0 + + + + 78.0 + + + + 77.0 + + + + 77.0 + + + + 79.0 + + + + 78.0 + + + + 78.0 + + + + 78.0 + + + + 79.0 + + + + 80.0 + + + + 79.0 + + + + 80.0 + + + + 80.0 + + + + 79.0 + + + + 80.0 + + + + 79.0 + + + + 78.0 + + + + 77.0 + + + + 78.0 + + + + 79.0 + + + + 79.0 + + + + 79.0 + + + + 80.0 + + + + 79.0 + + + + 79.0 + + + + 79.0 + + + + 79.0 + + + + 80.0 + + + + 80.0 + + + + 81.0 + + + + 79.0 + + + + 79.0 + + + + 79.0 + + + + 79.0 + + + + 78.0 + + + + 79.0 + + + + 77.0 + + + + 78.0 + + + + 78.0 + + + + 79.0 + + + + 78.0 + + + + 77.0 + + + + 79.0 + + + + 78.0 + + + + 77.0 + + + + 77.0 + + + + 76.0 + + + + 75.0 + + + + 73.0 + + + + 71.0 + + + + 71.0 + + + + 71.0 + + + + 70.0 + + + + 71.0 + + + + 70.0 + + + + 70.0 + + + + 69.0 + + + + 68.0 + + + + 68.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 66.0 + + + + 65.0 + + + + 64.0 + + + + 64.0 + + + + 63.0 + + + + 61.0 + + + + 61.0 + + + + 62.0 + + + + 62.0 + + + + 61.0 + + + + 61.0 + + + + 62.0 + + + + 63.0 + + + + 65.0 + + + + 66.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 67.0 + + + + 67.0 + + + + 68.0 + + + + 69.0 + + + + 69.0 + + + + 70.0 + + + + 69.0 + + + + 71.0 + + + + 70.0 + + + + 69.0 + + + + 68.0 + + + + 69.0 + + + + 69.0 + + + + 68.0 + + + + 69.0 + + + + 70.0 + + + + 70.0 + + + + 70.0 + + + + 73.0 + + + + 71.0 + + + + 70.0 + + + + 70.0 + + + + 69.0 + + + + 68.0 + + + + 68.0 + + + + 68.0 + + + + 68.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 68.0 + + + + 68.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 68.0 + + + + 67.0 + + + + 68.0 + + + + 67.0 + + + + 67.0 + + + + 68.0 + + + + 68.0 + + + + 69.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 66.0 + + + + 65.0 + + + + 63.0 + + + + 62.0 + + + + 62.0 + + + + 62.0 + + + + 61.0 + + + + 59.0 + + + + 59.0 + + + + 60.0 + + + + 61.0 + + + + 64.0 + + + + 65.0 + + + + 66.0 + + + + 67.0 + + + + 68.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 66.0 + + + + 67.0 + + + + 67.0 + + + + 69.0 + + + + 67.0 + + + + 65.0 + + + + 64.0 + + + + 64.0 + + + + 62.0 + + + + 63.0 + + + + 64.0 + + + + 64.0 + + + + 67.0 + + + + 69.0 + + + + 70.0 + + + + 70.0 + + + + 72.0 + + + + 72.0 + + + + 72.0 + + + + 70.0 + + + + 70.0 + + + + 68.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 69.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 67.0 + + + + 68.0 + + + + 69.0 + + + + 70.0 + + + + 70.0 + + + + 70.0 + + + + 70.0 + + + + 70.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 67.0 + + + + 67.0 + + + + 68.0 + + + + 68.0 + + + + 68.0 + + + + 69.0 + + + + 70.0 + + + + 69.0 + + + + 69.0 + + + + 71.0 + + + + 71.0 + + + + 71.0 + + + + 71.0 + + + + 71.0 + + + + 71.0 + + + + 70.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 68.0 + + + + 68.0 + + + + 68.0 + + + + 69.0 + + + + 69.0 + + + + 67.0 + + + + 66.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 69.0 + + + + 70.0 + + + + 70.0 + + + + 69.0 + + + + 69.0 + + + + 70.0 + + + + 70.0 + + + + 70.0 + + + + 71.0 + + + + 71.0 + + + + 70.0 + + + + 69.0 + + + + 69.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 66.0 + + + + 65.0 + + + + 65.0 + + + + 65.0 + + + + 65.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 68.0 + + + + 69.0 + + + + 70.0 + + + + 70.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 68.0 + + + + 68.0 + + + + 68.0 + + + + 68.0 + + + + 69.0 + + + + 69.0 + + + + 68.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 68.0 + + + + 68.0 + + + + 66.0 + + + + 68.0 + + + + 67.0 + + + + 68.0 + + + + 67.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 67.0 + + + + 66.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 66.0 + + + + 65.0 + + + + 66.0 + + + + 68.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 67.0 + + + + 66.0 + + + + 65.0 + + + + 66.0 + + + + 66.0 + + + + 67.0 + + + + 65.0 + + + + 64.0 + + + + 63.0 + + + + 65.0 + + + + 65.0 + + + + 66.0 + + + + 66.0 + + + + 67.0 + + + + 68.0 + + + + 69.0 + + + + 69.0 + + + + 68.0 + + + + 68.0 + + + + 67.0 + + + + 67.0 + + + + 66.0 + + + + 68.0 + + + + 68.0 + + + + 66.0 + + + + 68.0 + + + + 68.0 + + + + 66.0 + + + + 67.0 + + + + 66.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 66.0 + + + + 66.0 + + + + 68.0 + + + + 68.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 67.0 + + + + 66.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 67.0 + + + + 67.0 + + + + 68.0 + + + + 67.0 + + + + 68.0 + + + + 67.0 + + + + 67.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 67.0 + + + + 67.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 64.0 + + + + 64.0 + + + + 61.0 + + + + 61.0 + + + + 60.0 + + + + 61.0 + + + + 62.0 + + + + 61.0 + + + + 60.0 + + + + 60.0 + + + + 58.0 + + + + 56.0 + + + + 55.0 + + + + 55.0 + + + + 55.0 + + + + 56.0 + + + + 56.0 + + + + 56.0 + + + + 56.0 + + + + 56.0 + + + + 58.0 + + + + 58.0 + + + + 57.0 + + + + 57.0 + + + + 57.0 + + + + 57.0 + + + + 57.0 + + + + 57.0 + + + + 58.0 + + + + 61.0 + + + + 61.0 + + + + 60.0 + + + + 63.0 + + + + 65.0 + + + + 67.0 + + + + 68.0 + + + + 68.0 + + + + 69.0 + + + + 69.0 + + + + 69.0 + + + + 68.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 66.0 + + + + 65.0 + + + + 65.0 + + + + 65.0 + + + + 65.0 + + + + 66.0 + + + + 67.0 + + + + 67.0 + + + + 68.0 + + + + 69.0 + + + + 70.0 + + + + 71.0 + + + + 72.0 + + + + 71.0 + + + + 72.0 + + + + 71.0 + + + + 71.0 + + + + 69.0 + + + + 69.0 + + + + 68.0 + + + + 67.0 + + + + 66.0 + + + + 65.0 + + + + 65.0 + + + + 66.0 + + + + 67.0 + + + + 69.0 + + + + 70.0 + + + + 71.0 + + + + 71.0 + + + + 72.0 + + + + 72.0 + + + + 73.0 + + + + 74.0 + + + + 74.0 + + + + 76.0 + + + + 74.0 + + + + 76.0 + + + + 77.0 + + + + 77.0 + + + + 75.0 + + + + 74.0 + + + + 73.0 + + + + 73.0 + + + + 75.0 + + + + 76.0 + + + + 77.0 + + + + 77.0 + + + + 80.0 + + + + 80.0 + + + + 80.0 + + + + 80.0 + + + + 80.0 + + + + 81.0 + + + + 81.0 + + + + 81.0 + + + + 81.0 + + + + 82.0 + + + + 82.0 + + + + 81.0 + + + + 81.0 + + + + 81.0 + + + + 79.0 + + + + 80.0 + + + + 79.0 + + + + 78.0 + + + + 79.0 + + + + 79.0 + + + + 79.0 + + + + 77.0 + + + + 77.0 + + + + 76.0 + + + + 76.0 + + + + 75.0 + + + + 75.0 + + + + 75.0 + + + + 75.0 + + + + 73.0 + + + + 75.0 + + + + 75.0 + + + + 75.0 + + + + 74.0 + + + + 74.0 + + + + 74.0 + + + + 75.0 + + + + 75.0 + + + + 76.0 + + + + 75.0 + + + + 73.0 + + + + 72.0 + + + + 73.0 + + + + 75.0 + + + + 76.0 + + + + 75.0 + + + + 72.0 + + + + 73.0 + + + + 75.0 + + + + 77.0 + + + + 78.0 + + + + 78.0 + + + + 79.0 + + + + 79.0 + + + + 78.0 + + + + 77.0 + + + + 78.0 + + + + 77.0 + + + + 78.0 + + + + 75.0 + + + + 73.0 + + + + 72.0 + + + + 75.0 + + + + 74.0 + + + + 70.0 + + + + 69.0 + + + + 69.0 + + + + 70.0 + + + + 70.0 + + + + 71.0 + + + + 70.0 + + + + 70.0 + + + + 69.0 + + + + 67.0 + + + + 67.0 + + + + 70.0 + + + + 68.0 + + + + 66.0 + + + + 66.0 + + + + 65.0 + + + + 66.0 + + + + 68.0 + + + + 70.0 + + + + 70.0 + + + + 72.0 + + + + 71.0 + + + + 71.0 + + + + 71.0 + + + + 73.0 + + + + 75.0 + + + + 75.0 + + + + 75.0 + + + + 77.0 + + + + 79.0 + + + + 79.0 + + + + 78.0 + + + + 76.0 + + + + 76.0 + + + + 77.0 + + + + 78.0 + + + + 77.0 + + + + 77.0 + + + + 81.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 83.0 + + + + 82.0 + + + + 84.0 + + + + 84.0 + + + + 83.0 + + + + 83.0 + + + + 85.0 + + + + 84.0 + + + + 84.0 + + + + 83.0 + + + + 83.0 + + + + 82.0 + + + + 82.0 + + + + 81.0 + + + + 81.0 + + + + 81.0 + + + + 81.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 81.0 + + + + 81.0 + + + + 80.0 + + + + 83.0 + + + + 83.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 83.0 + + + + 84.0 + + + + 84.0 + + + + 85.0 + + + + 86.0 + + + + 86.0 + + + + 83.0 + + + + 83.0 + + + + 81.0 + + + + 82.0 + + + + 82.0 + + + + 80.0 + + + + 80.0 + + + + 79.0 + + + + 80.0 + + + + 79.0 + + + + 80.0 + + + + 81.0 + + + + 82.0 + + + + 81.0 + + + + 82.0 + + + + 81.0 + + + + 81.0 + + + + 80.0 + + + + 79.0 + + + + 79.0 + + + + 78.0 + + + + 78.0 + + + + 77.0 + + + + 77.0 + + + + 76.0 + + + + 75.0 + + + + 77.0 + + + + 77.0 + + + + 76.0 + + + + 77.0 + + + + 79.0 + + + + 78.0 + + + + 77.0 + + + + 78.0 + + + + 78.0 + + + + 78.0 + + + + 79.0 + + + + 79.0 + + + + 78.0 + + + + 77.0 + + + + 79.0 + + + + 79.0 + + + + 78.0 + + + + 79.0 + + + + 77.0 + + + + 77.0 + + + + 76.0 + + + + 78.0 + + + + 76.0 + + + + 75.0 + + + + 74.0 + + + + 74.0 + + + + 73.0 + + + + 74.0 + + + + 73.0 + + + + 74.0 + + + + 75.0 + + + + 75.0 + + + + 75.0 + + + + 76.0 + + + + 74.0 + + + + 76.0 + + + + 76.0 + + + + 75.0 + + + + 72.0 + + + + 75.0 + + + + 75.0 + + + + 76.0 + + + + 77.0 + + + + 77.0 + + + + 76.0 + + + + 77.0 + + + + 77.0 + + + + 75.0 + + + + 77.0 + + + + 77.0 + + + + 77.0 + + + + 80.0 + + + + 80.0 + + + + 79.0 + + + + 79.0 + + + + 79.0 + + + + 77.0 + + + + 77.0 + + + + 76.0 + + + + 75.0 + + + + 76.0 + + + + 76.0 + + + + 77.0 + + + + 76.0 + + + + 76.0 + + + + 76.0 + + + + 77.0 + + + + 77.0 + + + + 78.0 + + + + 78.0 + + + + 78.0 + + + + 78.0 + + + + 78.0 + + + + 78.0 + + + + 77.0 + + + + 79.0 + + + + 80.0 + + + + 80.0 + + + + 80.0 + + + + 80.0 + + + + 85.0 + + + + 83.0 + + + + 82.0 + + + + 81.0 + + + + 81.0 + + + + 80.0 + + + + 80.0 + + + + 80.0 + + + + 79.0 + + + + 78.0 + + + + 81.0 + + + + 80.0 + + + + 81.0 + + + + 81.0 + + + + 80.0 + + + + 80.0 + + + + 80.0 + + + + 81.0 + + + + 81.0 + + + + 81.0 + + + + 82.0 + + + + 83.0 + + + + 84.0 + + + + 83.0 + + + + 84.0 + + + + 85.0 + + + + 85.0 + + + + 87.0 + + + + 86.0 + + + + 85.0 + + + + 88.0 + + + + 87.0 + + + + 87.0 + + + + 88.0 + + + + 89.0 + + + + 90.0 + + + + 90.0 + + + + 91.0 + + + + 93.0 + + + + 93.0 + + + + 93.0 + + + + 90.0 + + + + 91.0 + + + + 92.0 + + + + 93.0 + + + + 91.0 + + + + 91.0 + + + + 89.0 + + + + 90.0 + + + + 90.0 + + + + 89.0 + + + + 89.0 + + + + 90.0 + + + + 90.0 + + + + 91.0 + + + + 91.0 + + + + 91.0 + + + + 92.0 + + + + 94.0 + + + + 96.0 + + + + 98.0 + + + + 98.0 + + + + 100.0 + + + + 98.0 + + + + 98.0 + + + + 96.0 + + + + 94.0 + + + + 89.0 + + + + 89.0 + + + + 88.0 + + + + 88.0 + + + + 86.0 + + + + 88.0 + + + + 88.0 + + + + 90.0 + + + + 90.0 + + + + 89.0 + + + + 89.0 + + + + 88.0 + + + + 88.0 + + + + 86.0 + + + + 87.0 + + + + 88.0 + + + + 88.0 + + + + 88.0 + + + + 88.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 85.0 + + + + 87.0 + + + + 87.0 + + + + 88.0 + + + + 89.0 + + + + 89.0 + + + + 89.0 + + + + 90.0 + + + + 90.0 + + + + 91.0 + + + + 90.0 + + + + 90.0 + + + + 90.0 + + + + 90.0 + + + + 90.0 + + + + 92.0 + + + + 90.0 + + + + 88.0 + + + + 89.0 + + + + 88.0 + + + + 87.0 + + + + 87.0 + + + + 85.0 + + + + 83.0 + + + + 83.0 + + + + 84.0 + + + + 84.0 + + + + 83.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 82.0 + + + + 82.0 + + + + 86.0 + + + + 86.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 83.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 83.0 + + + + 83.0 + + + + 83.0 + + + + 83.0 + + + + 84.0 + + + + 85.0 + + + + 85.0 + + + + 85.0 + + + + 84.0 + + + + 85.0 + + + + 85.0 + + + + 85.0 + + + + 85.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 85.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 85.0 + + + + 85.0 + + + + 86.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 85.0 + + + + 85.0 + + + + 85.0 + + + + 85.0 + + + + 84.0 + + + + 86.0 + + + + 85.0 + + + + 86.0 + + + + 86.0 + + + + 86.0 + + + + 86.0 + + + + 88.0 + + + + 87.0 + + + + 87.0 + + + + 89.0 + + + + 89.0 + + + + 89.0 + + + + 89.0 + + + + 91.0 + + + + 91.0 + + + + 91.0 + + + + 91.0 + + + + 91.0 + + + + 93.0 + + + + 93.0 + + + + 94.0 + + + + 94.0 + + + + 95.0 + + + + 95.0 + + + + 98.0 + + + + 98.0 + + + + 96.0 + + + + 95.0 + + + + 94.0 + + + + 94.0 + + + + 95.0 + + + + 95.0 + + + + 96.0 + + + + 96.0 + + + + 96.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 96.0 + + + + 96.0 + + + + 96.0 + + + + 97.0 + + + + 97.0 + + + + 97.0 + + + + 97.0 + + + + 97.0 + + + + 98.0 + + + + 97.0 + + + + 97.0 + + + + 97.0 + + + + 97.0 + + + + 96.0 + + + + 96.0 + + + + 95.0 + + + + 96.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 94.0 + + + + 94.0 + + + + 94.0 + + + + 94.0 + + + + 94.0 + + + + 93.0 + + + + 91.0 + + + + 90.0 + + + + 90.0 + + + + 88.0 + + + + 88.0 + + + + 88.0 + + + + 89.0 + + + + 89.0 + + + + 90.0 + + + + 91.0 + + + + 90.0 + + + + 90.0 + + + + 89.0 + + + + 88.0 + + + + 89.0 + + + + 89.0 + + + + 89.0 + + + + 90.0 + + + + 90.0 + + + + 90.0 + + + + 89.0 + + + + 88.0 + + + + 88.0 + + + + 89.0 + + + + 89.0 + + + + 91.0 + + + + 91.0 + + + + 91.0 + + + + 91.0 + + + + 91.0 + + + + 91.0 + + + + 91.0 + + + + 90.0 + + + + 89.0 + + + + 87.0 + + + + 88.0 + + + + 87.0 + + + + 87.0 + + + + 86.0 + + + + 87.0 + + + + 87.0 + + + + 86.0 + + + + 84.0 + + + + 82.0 + + + + 81.0 + + + + 82.0 + + + + 83.0 + + + + 82.0 + + + + 82.0 + + + + 83.0 + + + + 84.0 + + + + 83.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 81.0 + + + + 81.0 + + + + 82.0 + + + + 82.0 + + + + 83.0 + + + + 82.0 + + + + 83.0 + + + + 83.0 + + + + 82.0 + + + + 82.0 + + + + 80.0 + + + + 81.0 + + + + 82.0 + + + + 81.0 + + + + 82.0 + + + + 82.0 + + + + 82.0 + + + + 83.0 + + + + 84.0 + + + + 83.0 + + + + 83.0 + + + + 83.0 + + + + 84.0 + + + + 86.0 + + + + 86.0 + + + + 87.0 + + + + 87.0 + + + + 85.0 + + + + 85.0 + + + + 85.0 + + + + 85.0 + + + + 85.0 + + + + 89.0 + + + + 89.0 + + + + 89.0 + + + + 89.0 + + + + 90.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 86.0 + + + + 86.0 + + + + 86.0 + + + + 87.0 + + + + 87.0 + + + + 87.0 + + + + 86.0 + + + + 87.0 + + + + 89.0 + + + + 90.0 + + + + 90.0 + + + + 91.0 + + + + 92.0 + + + + 94.0 + + + + 94.0 + + + + 93.0 + + + + 89.0 + + + + 89.0 + + + + 89.0 + + + + 88.0 + + + + 88.0 + + + + 85.0 + + + + 83.0 + + + + 84.0 + + + + 85.0 + + + + 84.0 + + + + 86.0 + + + + 86.0 + + + + 86.0 + + + + 86.0 + + + + 85.0 + + + + 85.0 + + + + 84.0 + + + + 84.0 + + + + 84.0 + + + + 82.0 + + + + 83.0 + + + + 84.0 + + + + 83.0 + + + + 83.0 + + + + 83.0 + + + + 83.0 + + + + 83.0 + + + + 83.0 + + + + 84.0 + + + + 84.0 + + + + 85.0 + + + + 86.0 + + + + 87.0 + + + + 87.0 + + + + 89.0 + + + + 89.0 + + + + 90.0 + + + + 90.0 + + + + 91.0 + + + + 92.0 + + + + 92.0 + + + + 95.0 + + + + 95.0 + + + + 98.0 + + + + 98.0 + + + + 97.0 + + + + 97.0 + + + + 96.0 + + + + 96.0 + + + + 98.0 + + + + 98.0 + + + + 98.0 + + + + 98.0 + + + + 100.0 + + + + 102.0 + + + + 102.0 + + + + 103.0 + + + + 104.0 + + + + 105.0 + + + + 105.0 + + + + 106.0 + + + + 106.0 + + + + 106.0 + + + + 111.0 + + + + 110.0 + + + + 110.0 + + + + 111.0 + + + + 111.0 + + + + 112.0 + + + + 112.0 + + + + 114.0 + + + + 114.0 + + + + 114.0 + + + + 114.0 + + + + 112.0 + + + + 112.0 + + + + 113.0 + + + + 113.0 + + + + 112.0 + + + + 113.0 + + + + 113.0 + + + + 114.0 + + + + 114.0 + + + + 115.0 + + + + 117.0 + + + + 117.0 + + + + 117.0 + + + + 117.0 + + + + 119.0 + + + + 119.0 + + + + 117.0 + + + + 117.0 + + + + 117.0 + + + + 117.0 + + + + 122.0 + + + + 122.0 + + + + 120.0 + + + + 121.0 + + + + 120.0 + + + + 120.0 + + + + 122.0 + + + + 122.0 + + + + 124.0 + + + + 125.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 125.0 + + + + 126.0 + + + + 127.0 + + + + 127.0 + + + + 126.0 + + + + 125.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 125.0 + + + + 125.0 + + + + 125.0 + + + + 125.0 + + + + 125.0 + + + + 125.0 + + + + 125.0 + + + + 125.0 + + + + 125.0 + + + + 128.0 + + + + 128.0 + + + + 129.0 + + + + 129.0 + + + + 131.0 + + + + 131.0 + + + + 132.0 + + + + 132.0 + + + + 131.0 + + + + 131.0 + + + + 130.0 + + + + 130.0 + + + + 129.0 + + + + 128.0 + + + + 128.0 + + + + 127.0 + + + + 127.0 + + + + 127.0 + + + + 126.0 + + + + 125.0 + + + + 123.0 + + + + 122.0 + + + + 120.0 + + + + 120.0 + + + + 120.0 + + + + 120.0 + + + + 119.0 + + + + 119.0 + + + + 119.0 + + + + 117.0 + + + + 116.0 + + + + 116.0 + + + + 115.0 + + + + 115.0 + + + + 114.0 + + + + 114.0 + + + + 113.0 + + + + 112.0 + + + + 112.0 + + + + 111.0 + + + + 111.0 + + + + 112.0 + + + + 112.0 + + + + 111.0 + + + + 110.0 + + + + 109.0 + + + + 108.0 + + + + 108.0 + + + + 108.0 + + + + 108.0 + + + + 109.0 + + + + 110.0 + + + + 109.0 + + + + 110.0 + + + + 111.0 + + + + 112.0 + + + + 111.0 + + + + 112.0 + + + + 112.0 + + + + 111.0 + + + + 111.0 + + + + 111.0 + + + + 111.0 + + + + 113.0 + + + + 113.0 + + + + 114.0 + + + + 114.0 + + + + 115.0 + + + + 114.0 + + + + 116.0 + + + + 118.0 + + + + 120.0 + + + + 120.0 + + + + 120.0 + + + + 121.0 + + + + 121.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 121.0 + + + + 122.0 + + + + 123.0 + + + + 123.0 + + + + 125.0 + + + + 125.0 + + + + 125.0 + + + + 126.0 + + + + 126.0 + + + + 125.0 + + + + 124.0 + + + + 125.0 + + + + 126.0 + + + + 125.0 + + + + 125.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 128.0 + + + + 127.0 + + + + 126.0 + + + + 125.0 + + + + 126.0 + + + + 126.0 + + + + 125.0 + + + + 126.0 + + + + 126.0 + + + + 127.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 126.0 + + + + 125.0 + + + + 125.0 + + + + 126.0 + + + + 127.0 + + + + 127.0 + + + + 129.0 + + + + 129.0 + + + + 130.0 + + + + 130.0 + + + + 130.0 + + + + 130.0 + + + + 130.0 + + + + 131.0 + + + + 132.0 + + + + 132.0 + + + + 130.0 + + + + 130.0 + + + + 131.0 + + + + 131.0 + + + + 131.0 + + + + 131.0 + + + + 131.0 + + + + 131.0 + + + + 131.0 + + + + 131.0 + + + + 132.0 + + + + 132.0 + + + + 133.0 + + + + 133.0 + + + + 132.0 + + + + 133.0 + + + + 133.0 + + + + 134.0 + + + + 134.0 + + + + 134.0 + + + + 134.0 + + + + 135.0 + + + + 135.0 + + + + 134.0 + + + + 134.0 + + + + 133.0 + + + + 133.0 + + + + 133.0 + + + + 133.0 + + + + 133.0 + + + + 133.0 + + + + 133.0 + + + + 134.0 + + + + 135.0 + + + + 136.0 + + + + 136.0 + + + + 136.0 + + + + 136.0 + + + + 135.0 + + + + 135.0 + + + + 135.0 + + + + 135.0 + + + + 136.0 + + + + 136.0 + + + + 135.0 + + + + 135.0 + + + + 136.0 + + + + 135.0 + + + + 136.0 + + + + 136.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 136.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 138.0 + + + + 140.0 + + + + 141.0 + + + + 141.0 + + + + 140.0 + + + + 140.0 + + + + 139.0 + + + + 138.0 + + + + 139.0 + + + + 139.0 + + + + 140.0 + + + + 140.0 + + + + 139.0 + + + + 138.0 + + + + 138.0 + + + + 137.0 + + + + 138.0 + + + + 137.0 + + + + 137.0 + + + + 136.0 + + + + 136.0 + + + + 135.0 + + + + 136.0 + + + + 137.0 + + + + 136.0 + + + + 136.0 + + + + 135.0 + + + + 135.0 + + + + 135.0 + + + + 135.0 + + + + 135.0 + + + + 136.0 + + + + 136.0 + + + + 136.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 138.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 138.0 + + + + 138.0 + + + + 138.0 + + + + 137.0 + + + + 137.0 + + + + 138.0 + + + + 138.0 + + + + 138.0 + + + + 137.0 + + + + 138.0 + + + + 138.0 + + + + 138.0 + + + + 139.0 + + + + 139.0 + + + + 140.0 + + + + 140.0 + + + + 140.0 + + + + 140.0 + + + + 139.0 + + + + 138.0 + + + + 138.0 + + + + 138.0 + + + + 138.0 + + + + 138.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 138.0 + + + + 139.0 + + + + 139.0 + + + + 138.0 + + + + 138.0 + + + + 137.0 + + + + 137.0 + + + + 138.0 + + + + 137.0 + + + + 137.0 + + + + 138.0 + + + + 139.0 + + + + 138.0 + + + + 138.0 + + + + 139.0 + + + + 140.0 + + + + 139.0 + + + + 140.0 + + + + 139.0 + + + + 141.0 + + + + 142.0 + + + + 140.0 + + + + 140.0 + + + + 140.0 + + + + 140.0 + + + + 140.0 + + + + 140.0 + + + + 141.0 + + + + 140.0 + + + + 143.0 + + + + 142.0 + + + + 143.0 + + + + 142.0 + + + + 143.0 + + + + 143.0 + + + + 144.0 + + + + 144.0 + + + + 143.0 + + + + 142.0 + + + + 144.0 + + + + 143.0 + + + + 143.0 + + + + 142.0 + + + + 145.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 146.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 144.0 + + + + 144.0 + + + + 143.0 + + + + 143.0 + + + + 142.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 142.0 + + + + 142.0 + + + + 141.0 + + + + 142.0 + + + + 142.0 + + + + 143.0 + + + + 143.0 + + + + 144.0 + + + + 145.0 + + + + 145.0 + + + + 144.0 + + + + 144.0 + + + + 143.0 + + + + 143.0 + + + + 144.0 + + + + 144.0 + + + + 144.0 + + + + 144.0 + + + + 144.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 148.0 + + + + 148.0 + + + + 151.0 + + + + 153.0 + + + + 153.0 + + + + 152.0 + + + + 152.0 + + + + 149.0 + + + + 147.0 + + + + 148.0 + + + + 148.0 + + + + 148.0 + + + + 148.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 150.0 + + + + 150.0 + + + + 150.0 + + + + 150.0 + + + + 151.0 + + + + 151.0 + + + + 151.0 + + + + 151.0 + + + + 151.0 + + + + 147.0 + + + + 146.0 + + + + 146.0 + + + + 144.0 + + + + 143.0 + + + + 152.0 + + + + 154.0 + + + + 154.0 + + + + 150.0 + + + + 150.0 + + + + 148.0 + + + + 148.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 148.0 + + + + 148.0 + + + + 149.0 + + + + 150.0 + + + + 150.0 + + + + 151.0 + + + + 150.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 150.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 148.0 + + + + 148.0 + + + + 148.0 + + + + 148.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 148.0 + + + + 148.0 + + + + 149.0 + + + + 148.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 148.0 + + + + 148.0 + + + + 147.0 + + + + 146.0 + + + + 148.0 + + + + 149.0 + + + + 145.0 + + + + 146.0 + + + + 146.0 + + + + 148.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 150.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 149.0 + + + + 148.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 148.0 + + + + 148.0 + + + + 147.0 + + + + 146.0 + + + + 147.0 + + + + 147.0 + + + + 149.0 + + + + 149.0 + + + + 148.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 148.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 145.0 + + + + 145.0 + + + + 144.0 + + + + 149.0 + + + + 149.0 + + + + 150.0 + + + + 150.0 + + + + 151.0 + + + + 151.0 + + + + 150.0 + + + + 149.0 + + + + 150.0 + + + + 150.0 + + + + 149.0 + + + + 148.0 + + + + 148.0 + + + + 148.0 + + + + 148.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 148.0 + + + + 148.0 + + + + 149.0 + + + + 149.0 + + + + 151.0 + + + + 150.0 + + + + 151.0 + + + + 151.0 + + + + 151.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 149.0 + + + + 148.0 + + + + 148.0 + + + + 148.0 + + + + 148.0 + + + + 149.0 + + + + 150.0 + + + + 151.0 + + + + 152.0 + + + + 151.0 + + + + 151.0 + + + + 152.0 + + + + 152.0 + + + + 151.0 + + + + 152.0 + + + + 152.0 + + + + 151.0 + + + + 151.0 + + + + 151.0 + + + + 152.0 + + + + 152.0 + + + + 151.0 + + + + 151.0 + + + + 151.0 + + + + 151.0 + + + + 151.0 + + + + 150.0 + + + + 152.0 + + + + 151.0 + + + + 153.0 + + + + 153.0 + + + + 154.0 + + + + 155.0 + + + + 154.0 + + + + 154.0 + + + + 154.0 + + + + 154.0 + + + + 154.0 + + + + 155.0 + + + + 155.0 + + + + 155.0 + + + + 155.0 + + + + 155.0 + + + + 155.0 + + + + 156.0 + + + + 157.0 + + + + 157.0 + + + + 157.0 + + + + 154.0 + + + + 155.0 + + + + 157.0 + + + + 157.0 + + + + 157.0 + + + + 159.0 + + + + 160.0 + + + + 164.0 + + + + 164.0 + + + + 163.0 + + + + 164.0 + + + + 163.0 + + + + 163.0 + + + + 164.0 + + + + 159.0 + + + + 161.0 + + + + 161.0 + + + + 162.0 + + + + 162.0 + + + + 161.0 + + + + 161.0 + + + + 160.0 + + + + 154.0 + + + + 155.0 + + + + 155.0 + + + + 154.0 + + + + 155.0 + + + + 150.0 + + + + 150.0 + + + + 149.0 + + + + 149.0 + + + + 150.0 + + + + 150.0 + + + + 151.0 + + + + 150.0 + + + + 150.0 + + + + 149.0 + + + + 146.0 + + + + 153.0 + + + + 152.0 + + + + 148.0 + + + + 149.0 + + + + 147.0 + + + + 144.0 + + + + 141.0 + + + + 142.0 + + + + 143.0 + + + + 144.0 + + + + 153.0 + + + + 153.0 + + + + 149.0 + + + + 145.0 + + + + 144.0 + + + + 143.0 + + + + 143.0 + + + + 145.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 144.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 147.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 146.0 + + + + 146.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 144.0 + + + + 144.0 + + + + 144.0 + + + + 143.0 + + + + 142.0 + + + + 141.0 + + + + 142.0 + + + + 144.0 + + + + 144.0 + + + + 146.0 + + + + 148.0 + + + + 148.0 + + + + 149.0 + + + + 149.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 147.0 + + + + 148.0 + + + + 148.0 + + + + 148.0 + + + + 147.0 + + + + 147.0 + + + + 146.0 + + + + 146.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 146.0 + + + + 145.0 + + + + 145.0 + + + + 141.0 + + + + 140.0 + + + + 140.0 + + + + 142.0 + + + + 143.0 + + + + 144.0 + + + + 145.0 + + + + 144.0 + + + + 146.0 + + + + 146.0 + + + + 144.0 + + + + 145.0 + + + + 145.0 + + + + 146.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 144.0 + + + + 145.0 + + + + 145.0 + + + + 145.0 + + + + 143.0 + + + + 142.0 + + + + 142.0 + + + + 142.0 + + + + 142.0 + + + + 143.0 + + + + 143.0 + + + + 144.0 + + + + 144.0 + + + + 144.0 + + + + 144.0 + + + + 146.0 + + + + 146.0 + + + + 146.0 + + + + 145.0 + + + + 144.0 + + + + 144.0 + + + + 144.0 + + + + 145.0 + + + + 144.0 + + + + 144.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 144.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 142.0 + + + + 142.0 + + + + 142.0 + + + + 140.0 + + + + 140.0 + + + + 139.0 + + + + 139.0 + + + + 141.0 + + + + 141.0 + + + + 142.0 + + + + 141.0 + + + + 141.0 + + + + 141.0 + + + + 139.0 + + + + 140.0 + + + + 140.0 + + + + 138.0 + + + + 139.0 + + + + 140.0 + + + + 139.0 + + + + 140.0 + + + + 139.0 + + + + 140.0 + + + + 140.0 + + + + 141.0 + + + + 140.0 + + + + 140.0 + + + + 139.0 + + + + 139.0 + + + + 140.0 + + + + 140.0 + + + + 140.0 + + + + 139.0 + + + + 142.0 + + + + 141.0 + + + + 139.0 + + + + 139.0 + + + + 139.0 + + + + 140.0 + + + + 139.0 + + + + 139.0 + + + + 139.0 + + + + 140.0 + + + + 140.0 + + + + 141.0 + + + + 139.0 + + + + 139.0 + + + + 139.0 + + + + 139.0 + + + + 139.0 + + + + 140.0 + + + + 138.0 + + + + 139.0 + + + + 140.0 + + + + 140.0 + + + + 140.0 + + + + 144.0 + + + + 144.0 + + + + 142.0 + + + + 142.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 143.0 + + + + 142.0 + + + + 142.0 + + + + 142.0 + + + + 142.0 + + + + 142.0 + + + + 142.0 + + + + 141.0 + + + + 141.0 + + + + 141.0 + + + + 141.0 + + + + 139.0 + + + + 139.0 + + + + 141.0 + + + + 141.0 + + + + 142.0 + + + + 141.0 + + + + 140.0 + + + + 140.0 + + + + 139.0 + + + + 139.0 + + + + 139.0 + + + + 139.0 + + + + 141.0 + + + + 142.0 + + + + 141.0 + + + + 140.0 + + + + 139.0 + + + + 135.0 + + + + 134.0 + + + + 134.0 + + + + 135.0 + + + + 135.0 + + + + 136.0 + + + + 136.0 + + + + 138.0 + + + + 136.0 + + + + 136.0 + + + + 135.0 + + + + 135.0 + + + + 134.0 + + + + 136.0 + + + + 135.0 + + + + 135.0 + + + + 134.0 + + + + 134.0 + + + + 134.0 + + + + 133.0 + + + + 132.0 + + + + 132.0 + + + + 132.0 + + + + 132.0 + + + + 132.0 + + + + 132.0 + + + + 132.0 + + + + 132.0 + + + + 132.0 + + + + 133.0 + + + + 133.0 + + + + 133.0 + + + + 132.0 + + + + 133.0 + + + + 133.0 + + + + 132.0 + + + + 133.0 + + + + 133.0 + + + + 133.0 + + + + 132.0 + + + + 131.0 + + + + 132.0 + + + + 132.0 + + + + 131.0 + + + + 133.0 + + + + 132.0 + + + + 132.0 + + + + 132.0 + + + + 133.0 + + + + 133.0 + + + + 134.0 + + + + 137.0 + + + + 137.0 + + + + 137.0 + + + + 136.0 + + + + 136.0 + + + + 136.0 + + + + 135.0 + + + + 135.0 + + + + 136.0 + + + + 136.0 + + + + 136.0 + + + + 133.0 + + + + 132.0 + + + + 129.0 + + + + 129.0 + + + + 129.0 + + + + 130.0 + + + + 130.0 + + + + 130.0 + + + + 129.0 + + + + 130.0 + + + + 130.0 + + + + 130.0 + + + + 129.0 + + + + 129.0 + + + + 128.0 + + + + 128.0 + + + + 126.0 + + + + 125.0 + + + + 126.0 + + + + 125.0 + + + + 125.0 + + + + 125.0 + + + + 123.0 + + + + 123.0 + + + + 123.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 121.0 + + + + 121.0 + + + + 121.0 + + + + 121.0 + + + + 120.0 + + + + 120.0 + + + + 120.0 + + + + 120.0 + + + + 120.0 + + + + 119.0 + + + + 119.0 + + + + 120.0 + + + + 119.0 + + + + 120.0 + + + + 121.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 123.0 + + + + 121.0 + + + + 121.0 + + + + 121.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 122.0 + + + + 120.0 + + + + 118.0 + + + + 117.0 + + + + 120.0 + + + + 119.0 + + + + 119.0 + + + + 117.0 + + + + 117.0 + + + + 119.0 + + + + 118.0 + + + + 119.0 + + + + 118.0 + + + + 119.0 + + + + 118.0 + + + + 118.0 + + + + 118.0 + + + + 119.0 + + + + 115.0 + + + + 118.0 + + + + 118.0 + + + + 118.0 + + + + 116.0 + + + + 113.0 + + + + 114.0 + + + + 114.0 + + + + 113.0 + + + + 112.0 + + + + 111.0 + + + + 111.0 + + + + 111.0 + + + + 111.0 + + + + 111.0 + + + + 111.0 + + + + 110.0 + + + + 111.0 + + + + 110.0 + + + + 109.0 + + + + 108.0 + + + + 109.0 + + + + 108.0 + + + + 108.0 + + + + 108.0 + + + + 108.0 + + + + 109.0 + + + + 108.0 + + + + 109.0 + + + + 107.0 + + + + 106.0 + + + + 107.0 + + + + 107.0 + + + + 106.0 + + + + 103.0 + + + + 103.0 + + + + 103.0 + + + + 103.0 + + + + 104.0 + + + + 102.0 + + + + 104.0 + + + + 104.0 + + + + 104.0 + + + + 104.0 + + + + 104.0 + + + + 104.0 + + + + 104.0 + + + + 104.0 + + + + 104.0 + + + + 105.0 + + + + 105.0 + + + + 104.0 + + + + 104.0 + + + + 103.0 + + + + 103.0 + + + + 103.0 + + + + 103.0 + + + + 102.0 + + + + 101.0 + + + + 101.0 + + + + 100.0 + + + + 100.0 + + + + 100.0 + + + + 99.0 + + + + 100.0 + + + + 99.0 + + + + 99.0 + + + + 99.0 + + + + 100.0 + + + + 99.0 + + + + 99.0 + + + + 99.0 + + + + 99.0 + + + + 99.0 + + + + 99.0 + + + + 99.0 + + + + 102.0 + + + + 99.0 + + + + 97.0 + + + + 97.0 + + + + 96.0 + + + + 96.0 + + + + 96.0 + + + + 95.0 + + + + 94.0 + + + + 94.0 + + + + 94.0 + + + + 95.0 + + + + 96.0 + + + + 95.0 + + + + 96.0 + + + + 96.0 + + + + 96.0 + + + + 96.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 96.0 + + + + 97.0 + + + + 97.0 + + + + 99.0 + + + + 97.0 + + + + 97.0 + + + + 98.0 + + + + 97.0 + + + + 98.0 + + + + 97.0 + + + + 99.0 + + + + 100.0 + + + + 99.0 + + + + 99.0 + + + + 100.0 + + + + 100.0 + + + + 99.0 + + + + 99.0 + + + + 99.0 + + + + 98.0 + + + + 97.0 + + + + 97.0 + + + + 97.0 + + + + 96.0 + + + + 95.0 + + + + 95.0 + + + + 94.0 + + + + 94.0 + + + + 94.0 + + + + 96.0 + + + + 95.0 + + + + 94.0 + + + + 93.0 + + + + 92.0 + + + + 94.0 + + + + 93.0 + + + + 93.0 + + + + 92.0 + + + + 91.0 + + + + 91.0 + + + + 92.0 + + + + 92.0 + + + + 90.0 + + + + 101.0 + + + + 102.0 + + + + 99.0 + + + + 99.0 + + + + 99.0 + + + + 99.0 + + + + 94.0 + + + + 94.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 95.0 + + + + 96.0 + + + + 98.0 + + + + 100.0 + + + + 99.0 + + + + 98.0 + + + + 98.0 + + + + 98.0 + + + + 98.0 + + + + 98.0 + + + + 98.0 + + + + 103.0 + + + + 104.0 + + + + 103.0 + + + + 103.0 + + + + 104.0 + + + + 104.0 + + + + 102.0 + + + + 102.0 + + + + 102.0 + + + + 102.0 + + + + 105.0 + + + + 105.0 + + + + 106.0 + + + + 109.0 + + + + 108.0 + + + + 106.0 + + + + 106.0 + + + + 106.0 + + + + + diff --git a/osm.pb b/osm.pb index 67914e6..7ff071a 100644 --- a/osm.pb +++ b/osm.pb @@ -90,12 +90,12 @@ Module OSM Gadget.i ; Canvas Gadget Id TargetLocation.Location ; Latitude and Longitude from focus point - *Drawing.DrawingParameters ; Focus Tile coord + *Drawing.DrawingParameters ; Drawing parameters based on focus point CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) Position.Pixel ; Actual focus Point coords in pixels - MoveStartingPoint.Pixel ; Start mouse position coords when dragging the map + MoveStartingPoint.Pixel ; Start mouse position coords when dragging the map ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/ ZoomMin.i ; Min Zoom supported by server @@ -123,7 +123,7 @@ Module OSM Global OSM.OSM, Null.i - ;- *** CURL specific *** + ;- *** CURL specific *** Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl @@ -222,7 +222,7 @@ Module OSM EndProcedure ;- *** - + Procedure InitOSM() Protected Result.i @@ -245,17 +245,17 @@ Module OSM Global Proxy = #True -;- => Use this to customise your preferences -; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") -; If Proxy -; PreferenceGroup("PROXY") -; WritePreferenceString("ProxyURL", "myproxy.fr") -; WritePreferenceString("ProxyPort", "myproxyport") -; WritePreferenceString("ProxyUser", "myproxyname") -; EndIf -; If Result -; ClosePreferences() -; EndIf + ;- => Use this to customise your preferences + ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") + ; If Proxy + ; PreferenceGroup("PROXY") + ; WritePreferenceString("ProxyURL", "myproxy.fr") + ; WritePreferenceString("ProxyPort", "myproxyport") + ; WritePreferenceString("ProxyUser", "myproxyname") + ; EndIf + ; If Result + ; ClosePreferences() + ; EndIf Result = OpenPreferences(GetHomeDirectory() + "OSM.prefs") If Proxy @@ -498,10 +498,10 @@ Module OSM If OSM\EmergencyQuit = 0 ;Quit before drawing StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) If IsImage(*Tile\nImage) - MovePathCursor(x,y) - DrawVectorImage(ImageID(*Tile\nImage)) - MovePathCursor(x,y) - DrawVectorText(Str(x) + ", " + Str(y)) + MovePathCursor(x,y) + DrawVectorImage(ImageID(*Tile\nImage)) + MovePathCursor(x,y) + DrawVectorText(Str(x) + ", " + Str(y)) Else Debug "Image missing" OSM\Dirty = #True ;Signal that this image is missing so we should have to redraw @@ -512,7 +512,7 @@ Module OSM EndProcedure - Procedure DrawTiles() + Procedure DrawTiles(*Drawing.DrawingParameters) Protected x.i, y.i @@ -538,22 +538,25 @@ Module OSM If *NewTile With *NewTile + ;Keep a track of tiles (especially to free memory) AddElement(OSM\TilesThreads()) OSM\TilesThreads()\Tile = *NewTile + + ;New tile parameters \x = CenterX + x * OSM\TileSize \y = CenterY + y * OSM\TileSize \OSMTileX = tx + x \OSMTileY = ty + y \OSMZoom = OSM\Zoom - ;Check if the image exists, if not, load it in the background + ;Check if the image exists \nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY) If \nImage = -1 + ;If not, load it in the background \GetImageThread = CreateThread(@GetImageThread(), *NewTile) - OSM\TilesThreads()\GetImageThread = \GetImageThread + Debug " Creating get image thread nb " + Str(\GetImageThread) EndIf - Debug " Creating get image thread nb " + Str(\GetImageThread) DrawTile(*NewTile) EndWith @@ -565,6 +568,8 @@ Module OSM Next Next + ;Free tile memory when the loading thread has finished + ;TODO : exit this proc from drawtiles in a special "free ressources" task ForEach OSM\TilesThreads() If IsThread(OSM\TilesThreads()\GetImageThread) = 0 FreeMemory(OSM\TilesThreads()\Tile) @@ -574,10 +579,10 @@ Module OSM EndProcedure - Procedure DrawTrack() - Protected Pixel.Pixel - Protected Location.Location - If ListSize(OSM\track())>0 + Procedure DrawTrack() + Protected Pixel.Pixel + Protected Location.Location + If ListSize(OSM\track())>0 ForEach OSM\track() If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0 @@ -587,14 +592,14 @@ Module OSM Else AddPathLine(Pixel\X,Pixel\Y) EndIf - + EndIf Next - VectorSourceColor(RGBA(0, 255, 0, 150)) - StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) - - EndIf + VectorSourceColor(RGBA(0, 255, 0, 150)) + StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) + + EndIf EndProcedure Procedure Pointer(x.l,y.l,color.l=#Red) @@ -621,7 +626,7 @@ Module OSM Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2 - DrawTiles() + DrawTiles(*Drawing) LockMutex(OSM\DrawingMutex) StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) @@ -634,7 +639,7 @@ Module OSM ;- Redraw ;If something was not correctly drawn, redraw after a while - If OSM\Dirty + If OSM\Dirty And OSM\EmergencyQuit = #False Debug "Something was dirty ! We try again to redraw" ;Delay(250) @@ -770,91 +775,88 @@ EndModule ;Demonstration CompilerIf #PB_Compiler_IsMainFile -Enumeration - #Window_0 - #Map - #Button_0 - #Button_1 - #Button_2 - #Button_3 - #Button_4 - #Button_5 - #Combo_0 - #Text_0 - #Text_1 - #Text_2 - #Text_3 - #Text_4 - #String_0 - #String_1 - #Gdt_LoadGpx -EndEnumeration - + Enumeration + #Window_0 + #Map + #Button_0 + #Button_1 + #Button_2 + #Button_3 + #Button_4 + #Button_5 + #Combo_0 + #Text_0 + #Text_1 + #Text_2 + #Text_3 + #Text_4 + #String_0 + #String_1 + #Gdt_LoadGpx + EndEnumeration + Structure Location Longitude.d Latitude.d EndStructure - -Procedure UpdateLocation(*Location.Location) - SetGadgetText(#String_0,StrD(*Location\Latitude)) - SetGadgetText(#String_1,StrD(*Location\Longitude)) - ProcedureReturn 0 -EndProcedure -;- Main -If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered ) - OSM::InitOSM() - LoadFont(0, "Wingdings", 12) - LoadFont(1, "Arial", 12, #PB_Font_Bold) - - OSM::OSMGadget(#Map, 10, 10, 512, 512) - - TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ") - ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Button_0, FontID(0)) - ButtonGadget(#Button_1, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Button_1, FontID(0)) - ButtonGadget(#Button_2, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Button_2, FontID(0)) - ButtonGadget(#Button_3, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Button_3, FontID(0)) - TextGadget(#Text_2, 530, 160, 60, 15, "Zoom : ") - ButtonGadget(#Button_4, 550, 180, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1)) - ButtonGadget(#Button_5, 600, 180, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1)) - TextGadget(#Text_3, 530, 230, 60, 15, "Latitude : ") - StringGadget(#String_0, 600, 230, 90, 20, "") - TextGadget(#Text_4, 530, 250, 60, 15, "Longitude : ") - StringGadget(#String_1, 600, 250, 90, 20, "") - ButtonGadget(#Gdt_LoadGpx, 530, 280, 150, 30, "Load GPX") - - Define Event.i, Gadget.i, Quit.b = #False - Define pfValue.d - OSM::SetLocation(49.04599, 2.03347, 17) - OSM::SetCallBackLocation(@UpdateLocation()) - - Repeat - Event = WaitWindowEvent() + Procedure UpdateLocation(*Location.Location) + SetGadgetText(#String_0,StrD(*Location\Latitude)) + SetGadgetText(#String_1,StrD(*Location\Longitude)) + ProcedureReturn 0 + EndProcedure + ;- Main + If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered ) - OSM::Event(Event) - Select Event - Case #PB_Event_CloseWindow : Quit = 1 - Case #PB_Event_Gadget ;{ - Gadget = EventGadget() - Select Gadget - Case #Button_4 - OSM::SetZoom(1) - Case #Button_5 - OSM::SetZoom( - 1) - Case #Gdt_LoadGpx - OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) - EndSelect - EndSelect - Until Quit = #True -EndIf -<<<<<<< HEAD -======= + OSM::InitOSM() + LoadFont(0, "Wingdings", 12) + LoadFont(1, "Arial", 12, #PB_Font_Bold) + + OSM::OSMGadget(#Map, 10, 10, 512, 512) + + TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ") + ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Button_0, FontID(0)) + ButtonGadget(#Button_1, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Button_1, FontID(0)) + ButtonGadget(#Button_2, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Button_2, FontID(0)) + ButtonGadget(#Button_3, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Button_3, FontID(0)) + TextGadget(#Text_2, 530, 160, 60, 15, "Zoom : ") + ButtonGadget(#Button_4, 550, 180, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1)) + ButtonGadget(#Button_5, 600, 180, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1)) + TextGadget(#Text_3, 530, 230, 60, 15, "Latitude : ") + StringGadget(#String_0, 600, 230, 90, 20, "") + TextGadget(#Text_4, 530, 250, 60, 15, "Longitude : ") + StringGadget(#String_1, 600, 250, 90, 20, "") + ButtonGadget(#Gdt_LoadGpx, 530, 280, 150, 30, "Load GPX") + + Define Event.i, Gadget.i, Quit.b = #False + Define pfValue.d + OSM::SetLocation(49.04599, 2.03347, 17) + OSM::SetCallBackLocation(@UpdateLocation()) + + Repeat + Event = WaitWindowEvent() + + OSM::Event(Event) + Select Event + Case #PB_Event_CloseWindow : Quit = 1 + Case #PB_Event_Gadget ;{ + Gadget = EventGadget() + Select Gadget + Case #Button_4 + OSM::SetZoom(1) + Case #Button_5 + OSM::SetZoom( - 1) + Case #Gdt_LoadGpx + OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) + EndSelect + EndSelect + Until Quit = #True + EndIf CompilerEndIf -; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 726 -; FirstLine = 683 + +; IDE Options = PureBasic 5.42 LTS (Windows - x64) +; CursorPosition = 831 +; FirstLine = 803 ; Folding = ----- ; EnableUnicode -; EnableThread -; EnableXP ->>>>>>> refs/remotes/origin/master +; EnableXP \ No newline at end of file From e53f53a975315dcf18dfe2ca487dc01bb11c22b3 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 25 Jul 2016 13:41:15 +0200 Subject: [PATCH 04/35] Bugfix --- osm.pb | 119 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 49 deletions(-) diff --git a/osm.pb b/osm.pb index 7ff071a..0211d38 100644 --- a/osm.pb +++ b/osm.pb @@ -90,9 +90,10 @@ Module OSM Gadget.i ; Canvas Gadget Id TargetLocation.Location ; Latitude and Longitude from focus point + TargetTile.Tile ; Focus tile coords *Drawing.DrawingParameters ; Drawing parameters based on focus point - CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) + CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) Position.Pixel ; Actual focus Point coords in pixels MoveStartingPoint.Pixel ; Start mouse position coords when dragging the map @@ -112,7 +113,7 @@ Module OSM Dirty.i ;To signal that drawing need a refresh LoadingMutex.i DrawingMutex.i - ;CurlMutex.i ;seems that I can't thread curl ! :((((( + ;CurlMutex.i ;seems that I can't thread curl ! :((((( List TilesThreads.TileThread() MapImageMutex.i ; Mutex to lock @@ -243,7 +244,7 @@ Module OSM ;-*** PROXY - Global Proxy = #True + Global Proxy = #False ;- => Use this to customise your preferences ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") @@ -272,7 +273,7 @@ Module OSM curl_global_init(#CURL_GLOBAL_ALL); EndProcedure - ;- ** + ;- *** Procedure OSMGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) If Gadget = #PB_Any @@ -283,7 +284,7 @@ Module OSM EndIf EndProcedure - + ;*** Converts coords to tile.decimal Procedure LatLon2XY(*Location.Location, *Tile.Tile) Protected n.d = Pow(2.0, OSM\Zoom) Protected LatRad.d = Radian(*Location\Latitude) @@ -293,6 +294,7 @@ Module OSM Debug "Tile X : " + Str(*Tile\x) + " ; Tile Y : " + Str(*Tile\y) EndProcedure + ;*** Converts tile.decimal to coords Procedure XY2LatLon(*Tile.Tile, *Location.Location) Protected n.d = Pow(2.0, OSM\Zoom) Protected LatitudeRad.d @@ -306,8 +308,8 @@ Module OSM Protected mapHeight.l = Pow(2,OSM\Zoom+8) Protected x1.l,y1.l - Protected deltaX = OSM\Position\x - Int(OSM\TargetTile\x) * OSM\TileSize ;Get the position into the tile - Protected deltaY = OSM\Position\y - Int(OSM\TargetTile\y) * OSM\TileSize + ;Protected deltaX = OSM\Position\x - Int(OSM\TargetTile\x) * OSM\TileSize ;Get the position into the tile + ;Protected deltaY = OSM\Position\y - Int(OSM\TargetTile\y) * OSM\TileSize ; get x value x1 = (*Location\Longitude+180)*(mapWidth/360) @@ -326,8 +328,8 @@ Module OSM mercN = Log(Tan((#PI/4)+(latRad/2))) ; y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)); - *Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1) + deltaX - *Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1) + deltaY + *Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1); + deltaX + *Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1);+ deltaY EndProcedure Procedure LoadGpxFile(file.s) @@ -489,8 +491,8 @@ Module OSM Procedure DrawTile(*Tile.Tile) - Protected x = *Tile\x - OSM\DeltaX - Protected y = *Tile\y - OSM\DeltaY + Protected x = *Tile\x ; - OSM\DeltaX + Protected y = *Tile\y ; - OSM\DeltaY Debug " Drawing tile nb " + " X : " + Str(x) + " Y : " + Str(y) @@ -498,9 +500,9 @@ Module OSM If OSM\EmergencyQuit = 0 ;Quit before drawing StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) If IsImage(*Tile\nImage) - MovePathCursor(x,y) + MovePathCursor(x, y) DrawVectorImage(ImageID(*Tile\nImage)) - MovePathCursor(x,y) + MovePathCursor(x, y) DrawVectorText(Str(x) + ", " + Str(y)) Else Debug "Image missing" @@ -516,8 +518,8 @@ Module OSM Protected x.i, y.i - Protected tx = Int(OSM\TargetTile\x) ;Don't forget the Int() ! - Protected ty = Int(OSM\TargetTile\y) + Protected tx = Int(*Drawing\x) ;Don't forget the Int() ! + Protected ty = Int(*Drawing\y) Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2 @@ -543,8 +545,8 @@ Module OSM OSM\TilesThreads()\Tile = *NewTile ;New tile parameters - \x = CenterX + x * OSM\TileSize - \y = CenterY + y * OSM\TileSize + \x = CenterX + x * OSM\TileSize - *Drawing\DeltaX + \y = CenterY + y * OSM\TileSize - *Drawing\DeltaY \OSMTileX = tx + x \OSMTileY = ty + y \OSMZoom = OSM\Zoom @@ -579,7 +581,7 @@ Module OSM EndProcedure - Procedure DrawTrack() + Procedure DrawTrack(*Drawing.DrawingParameters) Protected Pixel.Pixel Protected Location.Location If ListSize(OSM\track())>0 @@ -588,9 +590,9 @@ Module OSM If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0 getPixelCoorfromLocation(@OSM\track(),@Pixel) If ListIndex(OSM\track())=0 - MovePathCursor(Pixel\X,Pixel\Y) + MovePathCursor(Pixel\X + *Drawing\DeltaX, Pixel\Y + *Drawing\DeltaY) Else - AddPathLine(Pixel\X,Pixel\Y) + AddPathLine(Pixel\X + *Drawing\DeltaX, Pixel\Y + *Drawing\DeltaY) EndIf EndIf @@ -630,7 +632,7 @@ Module OSM LockMutex(OSM\DrawingMutex) StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) - DrawTrack() + DrawTrack(*Drawing) Pointer(CenterX, CenterY, #Red) StopVectorDrawing() UnlockMutex(OSM\DrawingMutex) @@ -642,36 +644,46 @@ Module OSM If OSM\Dirty And OSM\EmergencyQuit = #False Debug "Something was dirty ! We try again to redraw" ;Delay(250) - *Drawing\PassNb + 1 CreateThread(@DrawingThread(), *Drawing) EndIf *Drawing\PassNb - 1 If *Drawing\PassNb = 0 - FreeMemory(*TargetTile) + FreeMemory(*Drawing) EndIf EndProcedure Procedure SetLocation(latitude.d, longitude.d, zoom = 15) + Protected *Drawing.DrawingParameters + If zoom > OSM\ZoomMax : zoom = OSM\ZoomMax : EndIf If zoom < OSM\ZoomMin : zoom = OSM\ZoomMin : EndIf OSM\Zoom = zoom OSM\TargetLocation\Latitude = latitude OSM\TargetLocation\Longitude = longitude LatLon2XY(@OSM\TargetLocation, @OSM\TargetTile) - OSM\Position\x = OSM\TargetTile\x * OSM\TileSize ;Convert X, Y in tile.decimal into real pixels - OSM\Position\y = OSM\TargetTile\y * OSM\TileSize - OSM\DeltaX = OSM\Position\x - Int(OSM\Position\x / OSM\TileSize) * OSM\TileSize - OSM\DeltaY = OSM\Position\y - Int(OSM\Position\y / OSM\TileSize) * OSM\TileSize - CreateThread(@DrawingThread(), Null) + ;*** Creates a drawing thread and fill parameters + *Drawing = AllocateMemory(SizeOf(DrawingParameters)) + ;Convert X, Y in tile.decimal into real pixels + *Drawing\x = OSM\TargetTile\x ;* OSM\TileSize + *Drawing\y = OSM\TargetTile\y ;* OSM\TileSize + ;Position in the tile + *Drawing\DeltaX = *Drawing\x - Int(*Drawing\x) * OSM\TileSize + *Drawing\DeltaY = *Drawing\y - Int(*Drawing\y) * OSM\TileSize + OSM\EmergencyQuit = #False + *Drawing\PassNb = 1 + CreateThread(@DrawingThread(), *Drawing) + ;*** EndProcedure Procedure SetZoom(Zoom.i, mode.i = #PB_Relative) + Protected *Drawing.DrawingParameters + Select mode Case #PB_Relative OSM\Zoom = OSM\Zoom + zoom @@ -682,11 +694,18 @@ Module OSM If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf LatLon2XY(@OSM\TargetLocation, @OSM\TargetTile) - OSM\Position\x = OSM\TargetTile\x * OSM\TileSize ;Convert X, Y in tile.decimal into real pixels - OSM\Position\y = OSM\TargetTile\y * OSM\TileSize - OSM\DeltaX = OSM\Position\x - Int(OSM\Position\x / OSM\TileSize) * OSM\TileSize - OSM\DeltaY = OSM\Position\y - Int(OSM\Position\y / OSM\TileSize) * OSM\TileSize - CreateThread(@DrawingThread(), Null) + ;*** Creates a drawing thread and fill parameters + *Drawing = AllocateMemory(SizeOf(DrawingParameters)) + ;Convert X, Y in tile.decimal into real pixels + *Drawing\x = OSM\TargetTile\x ;* OSM\TileSize + *Drawing\y = OSM\TargetTile\y ;* OSM\TileSize + ;Position in the tile + *Drawing\DeltaX = *Drawing\x - Int(*Drawing\x) * OSM\TileSize + *Drawing\DeltaY = *Drawing\y - Int(*Drawing\y) * OSM\TileSize + OSM\EmergencyQuit = #False + *Drawing\PassNb = 1 + CreateThread(@DrawingThread(), *Drawing) + ;*** EndProcedure @@ -699,7 +718,6 @@ Module OSM Protected Gadget.i Protected MouseX.i, MouseY.i Protected OldX.i, OldY.i - Protected TileX.d, TileY.d Protected *Drawing.DrawingParameters If IsGadget(OSM\Gadget) And GadgetType(OSM\Gadget) = #PB_GadgetType_Canvas @@ -725,25 +743,27 @@ Module OSM ;New move values OSM\Position\x - MouseX OSM\Position\y - MouseY + ;-*** Creates a drawing thread and fill parameters + *Drawing = AllocateMemory(SizeOf(DrawingParameters)) ;OSM tile position in tile.decimal - TileX = OSM\Position\x / OSM\TileSize - TileY = OSM\Position\y / OSM\TileSize - *Drawing = AllocateMemory(SizeOf(*DrawingParameters)) + *Drawing\x = OSM\Position\x / OSM\TileSize + *Drawing\y = OSM\Position\y / OSM\TileSize ;Pixel shift - *Drawing\DeltaX = OSM\Position\x - Int(TileX) * OSM\TileSize - *Drawing\DeltaY = OSM\Position\y - Int(TileY) * OSM\TileSize + *Drawing\DeltaX = OSM\Position\x - Int(*Drawing\x) * OSM\TileSize + *Drawing\DeltaY = OSM\Position\y - Int(*Drawing\y) * OSM\TileSize ;Moved to a new tile ? - If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) - Debug "--- New tile" - *Drawing\x = TileX - *Drawing\y = TileY - Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) - XY2LatLon(*Drawing, @OSM\TargetLocation) - Debug "OSM\TargetTile\x " + StrD(*Drawing\x) + " ; OSM\TargetTile\y " + StrD(*Drawing\y) - EndIf + ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) + ;Debug "--- New tile" + ;*Drawing\x = TileX + ;*Drawing\y = TileY + Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) + XY2LatLon(*Drawing, @OSM\TargetLocation) + Debug "OSM\TargetTile\x " + StrD(*Drawing\x) + " ; OSM\TargetTile\y " + StrD(*Drawing\y) + ;EndIf OSM\EmergencyQuit = #False *Drawing\PassNb = 1 CreateThread(@DrawingThread(), *Drawing) + ;- *** OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) ;If CallBackLocation send Location to function @@ -855,8 +875,9 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 831 -; FirstLine = 803 +; CursorPosition = 750 +; FirstLine = 724 ; Folding = ----- ; EnableUnicode +; EnableThread ; EnableXP \ No newline at end of file From b2e0383e7cd7a58485edbb3902d710079b7ff2b6 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 25 Jul 2016 14:11:12 +0200 Subject: [PATCH 05/35] Bugfix --- osm.pb | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/osm.pb b/osm.pb index 0211d38..de7a45a 100644 --- a/osm.pb +++ b/osm.pb @@ -458,7 +458,7 @@ Module OSM LockMutex(OSM\LoadingMutex) - If OSM\EmergencyQuit = 0 + If OSM\EmergencyQuit = #False LockMutex(OSM\MemCache\Mutex) *CacheImagePtr = AddElement(OSM\MemCache\Image()) Debug " CacheImagePtr : " + Str(*CacheImagePtr) @@ -468,11 +468,11 @@ Module OSM OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro UnlockMutex(OSM\MemCache\Mutex) nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) - If nImage = -1 And OSM\EmergencyQuit = 0 + If nImage = -1 And OSM\EmergencyQuit = #False nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) EndIf LockMutex(OSM\MemCache\Mutex) - If nImage <> -1 And OSM\EmergencyQuit = 0 + If nImage <> -1 And OSM\EmergencyQuit = #False Debug "Adding tile " + Str(nImage) + " to mem cache" ;AddTileToMemCache(Zoom, XTile, YTile, nImage) OSM\MemCache\Image()\nImage = nImage @@ -494,10 +494,12 @@ Module OSM Protected x = *Tile\x ; - OSM\DeltaX Protected y = *Tile\y ; - OSM\DeltaY - Debug " Drawing tile nb " + " X : " + Str(x) + " Y : " + Str(y) + Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) + Debug " at coords " + Str(x) + "," + Str(y) + LockMutex(OSM\DrawingMutex) - If OSM\EmergencyQuit = 0 ;Quit before drawing + If OSM\EmergencyQuit = #False ;Quit before drawing StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) If IsImage(*Tile\nImage) MovePathCursor(x, y) @@ -668,11 +670,11 @@ Module OSM ;*** Creates a drawing thread and fill parameters *Drawing = AllocateMemory(SizeOf(DrawingParameters)) ;Convert X, Y in tile.decimal into real pixels - *Drawing\x = OSM\TargetTile\x ;* OSM\TileSize - *Drawing\y = OSM\TargetTile\y ;* OSM\TileSize + *Drawing\x = OSM\TargetTile\x + *Drawing\y = OSM\TargetTile\y ;Position in the tile - *Drawing\DeltaX = *Drawing\x - Int(*Drawing\x) * OSM\TileSize - *Drawing\DeltaY = *Drawing\y - Int(*Drawing\y) * OSM\TileSize + *Drawing\DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) + *Drawing\DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) OSM\EmergencyQuit = #False *Drawing\PassNb = 1 CreateThread(@DrawingThread(), *Drawing) @@ -697,11 +699,11 @@ Module OSM ;*** Creates a drawing thread and fill parameters *Drawing = AllocateMemory(SizeOf(DrawingParameters)) ;Convert X, Y in tile.decimal into real pixels - *Drawing\x = OSM\TargetTile\x ;* OSM\TileSize - *Drawing\y = OSM\TargetTile\y ;* OSM\TileSize + *Drawing\x = OSM\TargetTile\x + *Drawing\y = OSM\TargetTile\y ;Position in the tile - *Drawing\DeltaX = *Drawing\x - Int(*Drawing\x) * OSM\TileSize - *Drawing\DeltaY = *Drawing\y - Int(*Drawing\y) * OSM\TileSize + *Drawing\DeltaX = *Drawing\x * OSM\TileSize - Int(*Drawing\x) * OSM\TileSize + *Drawing\DeltaY = *Drawing\y * OSM\TileSize - Int(*Drawing\y) * OSM\TileSize OSM\EmergencyQuit = #False *Drawing\PassNb = 1 CreateThread(@DrawingThread(), *Drawing) @@ -734,7 +736,7 @@ Module OSM Case #PB_EventType_MouseMove If OSM\MoveStartingPoint\x <> - 1 ;Need a refresh - ;OSM\EmergencyQuit = #True + OSM\EmergencyQuit = #True MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y ;Old move values @@ -875,8 +877,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 750 -; FirstLine = 724 +; CursorPosition = 754 +; FirstLine = 726 ; Folding = ----- ; EnableUnicode ; EnableThread From 04215118597c6b6d0cb99c35b3b169633ea2b432 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 25 Jul 2016 18:21:52 +0200 Subject: [PATCH 06/35] Semaphores are back Drawing thread is now always running waiting for semaphore signal --- osm.pb | 170 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 87 insertions(+), 83 deletions(-) diff --git a/osm.pb b/osm.pb index de7a45a..ce3c32a 100644 --- a/osm.pb +++ b/osm.pb @@ -58,7 +58,11 @@ Module OSM OSMZoom.i DeltaX.i DeltaY.i - PassNb.i + Mutex.i + Semaphore.i + Dirty.i + PassNB.i + End.i EndStructure Structure TileThread @@ -91,7 +95,7 @@ Module OSM TargetLocation.Location ; Latitude and Longitude from focus point TargetTile.Tile ; Focus tile coords - *Drawing.DrawingParameters ; Drawing parameters based on focus point + Drawing.DrawingParameters ; Drawing parameters based on focus point CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) @@ -108,8 +112,7 @@ Module OSM MemCache.TileMemCach ; Image in memory cache List MapImageIndex.ImgMemCach() ; Index from MemCache\Image() to construct map - DrawingThreadMutex.i ;Only one main drawing thread - EmergencyQuit.i + Moving.i Dirty.i ;To signal that drawing need a refresh LoadingMutex.i DrawingMutex.i @@ -238,9 +241,10 @@ Module OSM OSM\LoadingMutex = CreateMutex() OSM\DrawingMutex = CreateMutex() ;OSM\CurlMutex = CreateMutex() - OSM\DrawingThreadMutex = CreateMutex() - OSM\EmergencyQuit = #False + OSM\Moving = #False OSM\Dirty = #False + OSM\Drawing\Semaphore = CreateSemaphore() + OSM\Drawing\Mutex = CreateMutex() ;-*** PROXY @@ -271,6 +275,7 @@ Module OSM EndIf curl_global_init(#CURL_GLOBAL_ALL); + CreateThread(@DrawingThread(), @OSM\Drawing) EndProcedure ;- *** @@ -458,7 +463,7 @@ Module OSM LockMutex(OSM\LoadingMutex) - If OSM\EmergencyQuit = #False + If OSM\Moving = #False LockMutex(OSM\MemCache\Mutex) *CacheImagePtr = AddElement(OSM\MemCache\Image()) Debug " CacheImagePtr : " + Str(*CacheImagePtr) @@ -468,11 +473,11 @@ Module OSM OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro UnlockMutex(OSM\MemCache\Mutex) nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) - If nImage = -1 And OSM\EmergencyQuit = #False + If nImage = -1 And OSM\Moving = #False nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) EndIf LockMutex(OSM\MemCache\Mutex) - If nImage <> -1 And OSM\EmergencyQuit = #False + If nImage <> -1 And OSM\Moving = #False Debug "Adding tile " + Str(nImage) + " to mem cache" ;AddTileToMemCache(Zoom, XTile, YTile, nImage) OSM\MemCache\Image()\nImage = nImage @@ -496,10 +501,9 @@ Module OSM Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) Debug " at coords " + Str(x) + "," + Str(y) - LockMutex(OSM\DrawingMutex) - If OSM\EmergencyQuit = #False ;Quit before drawing + If OSM\Moving = #False ;Quit before drawing StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) If IsImage(*Tile\nImage) MovePathCursor(x, y) @@ -508,7 +512,7 @@ Module OSM DrawVectorText(Str(x) + ", " + Str(y)) Else Debug "Image missing" - OSM\Dirty = #True ;Signal that this image is missing so we should have to redraw + OSM\Drawing\Dirty = #True ;Signal that this image is missing so we should have to redraw EndIf StopVectorDrawing() EndIf @@ -534,7 +538,7 @@ Module OSM For y = - ny To ny For x = - nx To nx - If OSM\EmergencyQuit + If OSM\Moving Break 2 EndIf @@ -622,70 +626,69 @@ Module OSM Procedure DrawingThread(*Drawing.DrawingParameters) - Debug "--------- Main drawing thread ------------" - OSM\Dirty = #False - - LockMutex(OSM\DrawingThreadMutex) ; Only one main drawing thread at once - - Protected CenterX = GadgetWidth(OSM\Gadget) / 2 - Protected CenterY = GadgetHeight(OSM\Gadget) / 2 - - DrawTiles(*Drawing) - - LockMutex(OSM\DrawingMutex) - StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) - DrawTrack(*Drawing) - Pointer(CenterX, CenterY, #Red) - StopVectorDrawing() - UnlockMutex(OSM\DrawingMutex) - - UnlockMutex(OSM\DrawingThreadMutex) - - ;- Redraw - ;If something was not correctly drawn, redraw after a while - If OSM\Dirty And OSM\EmergencyQuit = #False - Debug "Something was dirty ! We try again to redraw" - ;Delay(250) - *Drawing\PassNb + 1 - CreateThread(@DrawingThread(), *Drawing) - EndIf - - *Drawing\PassNb - 1 - If *Drawing\PassNb = 0 - FreeMemory(*Drawing) - EndIf + Repeat + + WaitSemaphore(OSM\Drawing\Semaphore) + + Debug "--------- Main drawing thread ------------" + + LockMutex(OSM\Drawing\Mutex) ; Only one main drawing thread at once + + OSM\Drawing\Dirty = #False + + Protected CenterX = GadgetWidth(OSM\Gadget) / 2 + Protected CenterY = GadgetHeight(OSM\Gadget) / 2 + + DrawTiles(*Drawing) + + LockMutex(OSM\DrawingMutex) + StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) + DrawTrack(*Drawing) + Pointer(CenterX, CenterY, #Red) + StopVectorDrawing() + UnlockMutex(OSM\DrawingMutex) + + ;- Redraw + ;If something was not correctly drawn, redraw after a while + If OSM\Drawing\Dirty And OSM\Moving = #False + Debug "Something was dirty ! We try again to redraw" + ;Delay(250) + OSM\Drawing\PassNb + 1 + SignalSemaphore(OSM\Drawing\Semaphore) + EndIf + + UnlockMutex(OSM\Drawing\Mutex) + + Until OSM\Drawing\End EndProcedure Procedure SetLocation(latitude.d, longitude.d, zoom = 15) - - Protected *Drawing.DrawingParameters - + If zoom > OSM\ZoomMax : zoom = OSM\ZoomMax : EndIf If zoom < OSM\ZoomMin : zoom = OSM\ZoomMin : EndIf OSM\Zoom = zoom OSM\TargetLocation\Latitude = latitude OSM\TargetLocation\Longitude = longitude LatLon2XY(@OSM\TargetLocation, @OSM\TargetTile) - ;*** Creates a drawing thread and fill parameters - *Drawing = AllocateMemory(SizeOf(DrawingParameters)) ;Convert X, Y in tile.decimal into real pixels - *Drawing\x = OSM\TargetTile\x - *Drawing\y = OSM\TargetTile\y + OSM\Position\X = OSM\TargetTile\X * OSM\TileSize + OSM\Position\Y = OSM\TargetTile\Y * OSM\TileSize + ;*** Creates a drawing thread and fill parameters + LockMutex(OSM\Drawing\Mutex) + OSM\Drawing\x = OSM\TargetTile\x + OSM\Drawing\y = OSM\TargetTile\y ;Position in the tile - *Drawing\DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) - *Drawing\DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) - OSM\EmergencyQuit = #False - *Drawing\PassNb = 1 - CreateThread(@DrawingThread(), *Drawing) + OSM\Drawing\DeltaX = OSM\Drawing\x * OSM\TileSize - (Int(OSM\Drawing\x) * OSM\TileSize) + OSM\Drawing\DeltaY = OSM\Drawing\y * OSM\TileSize - (Int(OSM\Drawing\y) * OSM\TileSize) + UnlockMutex(OSM\Drawing\Mutex) + SignalSemaphore(OSM\Drawing\Semaphore) ;*** EndProcedure Procedure SetZoom(Zoom.i, mode.i = #PB_Relative) - - Protected *Drawing.DrawingParameters - + Select mode Case #PB_Relative OSM\Zoom = OSM\Zoom + zoom @@ -696,17 +699,17 @@ Module OSM If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf LatLon2XY(@OSM\TargetLocation, @OSM\TargetTile) + OSM\Position\X = OSM\TargetTile\X * OSM\TileSize + OSM\Position\Y = OSM\TargetTile\Y * OSM\TileSize ;*** Creates a drawing thread and fill parameters - *Drawing = AllocateMemory(SizeOf(DrawingParameters)) - ;Convert X, Y in tile.decimal into real pixels - *Drawing\x = OSM\TargetTile\x - *Drawing\y = OSM\TargetTile\y + LockMutex(OSM\Drawing\Mutex) + OSM\Drawing\x = OSM\TargetTile\x + OSM\Drawing\y = OSM\TargetTile\y ;Position in the tile - *Drawing\DeltaX = *Drawing\x * OSM\TileSize - Int(*Drawing\x) * OSM\TileSize - *Drawing\DeltaY = *Drawing\y * OSM\TileSize - Int(*Drawing\y) * OSM\TileSize - OSM\EmergencyQuit = #False - *Drawing\PassNb = 1 - CreateThread(@DrawingThread(), *Drawing) + OSM\Drawing\DeltaX = OSM\Drawing\x * OSM\TileSize - (Int(OSM\Drawing\x) * OSM\TileSize) + OSM\Drawing\DeltaY = OSM\Drawing\y * OSM\TileSize - (Int(OSM\Drawing\y) * OSM\TileSize) + UnlockMutex(OSM\Drawing\Mutex) + SignalSemaphore(OSM\Drawing\Semaphore) ;*** EndProcedure @@ -736,7 +739,7 @@ Module OSM Case #PB_EventType_MouseMove If OSM\MoveStartingPoint\x <> - 1 ;Need a refresh - OSM\EmergencyQuit = #True + OSM\Moving = #True MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y ;Old move values @@ -745,26 +748,26 @@ Module OSM ;New move values OSM\Position\x - MouseX OSM\Position\y - MouseY - ;-*** Creates a drawing thread and fill parameters - *Drawing = AllocateMemory(SizeOf(DrawingParameters)) + ;-*** Sill parameters and signal the drawing thread + LockMutex(OSM\Drawing\Mutex) ;OSM tile position in tile.decimal - *Drawing\x = OSM\Position\x / OSM\TileSize - *Drawing\y = OSM\Position\y / OSM\TileSize + OSM\Drawing\x = OSM\Position\x / OSM\TileSize + OSM\Drawing\y = OSM\Position\y / OSM\TileSize ;Pixel shift - *Drawing\DeltaX = OSM\Position\x - Int(*Drawing\x) * OSM\TileSize - *Drawing\DeltaY = OSM\Position\y - Int(*Drawing\y) * OSM\TileSize + OSM\Drawing\DeltaX = OSM\Position\x - Int(OSM\Drawing\x) * OSM\TileSize + OSM\Drawing\DeltaY = OSM\Position\y - Int(OSM\Drawing\y) * OSM\TileSize ;Moved to a new tile ? ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) ;Debug "--- New tile" ;*Drawing\x = TileX ;*Drawing\y = TileY Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) - XY2LatLon(*Drawing, @OSM\TargetLocation) - Debug "OSM\TargetTile\x " + StrD(*Drawing\x) + " ; OSM\TargetTile\y " + StrD(*Drawing\y) + XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) + Debug "OSM\TargetTile\x " + StrD(OSM\Drawing\x) + " ; OSM\TargetTile\y " + StrD(OSM\Drawing\y) ;EndIf - OSM\EmergencyQuit = #False - *Drawing\PassNb = 1 - CreateThread(@DrawingThread(), *Drawing) + OSM\Drawing\PassNb = 1 + UnlockMutex(OSM\Drawing\Mutex) + SignalSemaphore(OSM\Drawing\Semaphore) ;- *** OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) @@ -774,6 +777,7 @@ Module OSM EndIf EndIf Case #PB_EventType_LeftButtonUp + OSM\Moving = #False OSM\MoveStartingPoint\x = - 1 OSM\TargetTile\x = OSM\Position\x / OSM\TileSize OSM\TargetTile\y = OSM\Position\y / OSM\TileSize @@ -877,8 +881,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 754 -; FirstLine = 726 +; CursorPosition = 659 +; FirstLine = 626 ; Folding = ----- ; EnableUnicode ; EnableThread From c32b604d1317f4bfd86dfd777c5d6395ec1da9e3 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 25 Jul 2016 21:32:50 +0200 Subject: [PATCH 07/35] Bugfix --- osm.pb | 99 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 45 insertions(+), 54 deletions(-) diff --git a/osm.pb b/osm.pb index ce3c32a..024ac95 100644 --- a/osm.pb +++ b/osm.pb @@ -241,7 +241,6 @@ Module OSM OSM\LoadingMutex = CreateMutex() OSM\DrawingMutex = CreateMutex() ;OSM\CurlMutex = CreateMutex() - OSM\Moving = #False OSM\Dirty = #False OSM\Drawing\Semaphore = CreateSemaphore() OSM\Drawing\Mutex = CreateMutex() @@ -463,32 +462,30 @@ Module OSM LockMutex(OSM\LoadingMutex) - If OSM\Moving = #False - LockMutex(OSM\MemCache\Mutex) - *CacheImagePtr = AddElement(OSM\MemCache\Image()) - Debug " CacheImagePtr : " + Str(*CacheImagePtr) - OSM\MemCache\Image()\xTile = *Tile\OSMTileX - OSM\MemCache\Image()\yTile = *Tile\OSMTileY - OSM\MemCache\Image()\Zoom = *Tile\OSMZoom - OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro - UnlockMutex(OSM\MemCache\Mutex) - nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) - If nImage = -1 And OSM\Moving = #False - nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) - EndIf - LockMutex(OSM\MemCache\Mutex) - If nImage <> -1 And OSM\Moving = #False - Debug "Adding tile " + Str(nImage) + " to mem cache" - ;AddTileToMemCache(Zoom, XTile, YTile, nImage) - OSM\MemCache\Image()\nImage = nImage - Debug "Image nb " + Str(nImage) + " successfully added to mem cache" - Else - Debug "Error GetImageThread procedure, tile not loaded - Zoom:" + Str(*Tile\OSMZoom) + " X:" + Str(*Tile\OSMTileX) + " Y:" + Str(*Tile\OSMTileY) - DeleteElement(OSM\MemCache\Image()) - nImage = -1 - EndIf - UnlockMutex(OSM\MemCache\Mutex) + LockMutex(OSM\MemCache\Mutex) + *CacheImagePtr = AddElement(OSM\MemCache\Image()) + Debug " CacheImagePtr : " + Str(*CacheImagePtr) + OSM\MemCache\Image()\xTile = *Tile\OSMTileX + OSM\MemCache\Image()\yTile = *Tile\OSMTileY + OSM\MemCache\Image()\Zoom = *Tile\OSMZoom + OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro + UnlockMutex(OSM\MemCache\Mutex) + nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) + If nImage = -1 + nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) EndIf + LockMutex(OSM\MemCache\Mutex) + If nImage <> -1 + Debug "Adding tile " + Str(nImage) + " to mem cache" + ;AddTileToMemCache(Zoom, XTile, YTile, nImage) + OSM\MemCache\Image()\nImage = nImage + Debug "Image nb " + Str(nImage) + " successfully added to mem cache" + Else + Debug "Error GetImageThread procedure, tile not loaded - Zoom:" + Str(*Tile\OSMZoom) + " X:" + Str(*Tile\OSMTileX) + " Y:" + Str(*Tile\OSMTileY) + DeleteElement(OSM\MemCache\Image()) + nImage = -1 + EndIf + UnlockMutex(OSM\MemCache\Mutex) *Tile\nImage = nImage UnlockMutex(OSM\LoadingMutex) @@ -503,19 +500,17 @@ Module OSM Debug " at coords " + Str(x) + "," + Str(y) LockMutex(OSM\DrawingMutex) - If OSM\Moving = #False ;Quit before drawing - StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) - If IsImage(*Tile\nImage) - MovePathCursor(x, y) - DrawVectorImage(ImageID(*Tile\nImage)) - MovePathCursor(x, y) - DrawVectorText(Str(x) + ", " + Str(y)) - Else - Debug "Image missing" - OSM\Drawing\Dirty = #True ;Signal that this image is missing so we should have to redraw - EndIf - StopVectorDrawing() + StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) + If IsImage(*Tile\nImage) + MovePathCursor(x, y) + DrawVectorImage(ImageID(*Tile\nImage)) + MovePathCursor(x, y) + DrawVectorText(Str(x) + ", " + Str(y)) + Else + Debug "Image missing" + OSM\Drawing\Dirty = #True ;Signal that this image is missing so we should have to redraw EndIf + StopVectorDrawing() UnlockMutex(OSM\DrawingMutex) EndProcedure @@ -538,9 +533,10 @@ Module OSM For y = - ny To ny For x = - nx To nx - If OSM\Moving - Break 2 - EndIf + ;Was quiting the loop if a move occured, giving maybe smoother movement + ;If OSM\Moving + ; Break 2 + ;EndIf Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile)) If *NewTile @@ -633,24 +629,21 @@ Module OSM Debug "--------- Main drawing thread ------------" LockMutex(OSM\Drawing\Mutex) ; Only one main drawing thread at once - OSM\Drawing\Dirty = #False - Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2 DrawTiles(*Drawing) - LockMutex(OSM\DrawingMutex) StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) DrawTrack(*Drawing) Pointer(CenterX, CenterY, #Red) StopVectorDrawing() UnlockMutex(OSM\DrawingMutex) - + ;- Redraw ;If something was not correctly drawn, redraw after a while - If OSM\Drawing\Dirty And OSM\Moving = #False + If OSM\Drawing\Dirty Debug "Something was dirty ! We try again to redraw" ;Delay(250) OSM\Drawing\PassNb + 1 @@ -659,12 +652,13 @@ Module OSM UnlockMutex(OSM\Drawing\Mutex) + Until OSM\Drawing\End EndProcedure Procedure SetLocation(latitude.d, longitude.d, zoom = 15) - + If zoom > OSM\ZoomMax : zoom = OSM\ZoomMax : EndIf If zoom < OSM\ZoomMin : zoom = OSM\ZoomMin : EndIf OSM\Zoom = zoom @@ -688,7 +682,7 @@ Module OSM EndProcedure Procedure SetZoom(Zoom.i, mode.i = #PB_Relative) - + Select mode Case #PB_Relative OSM\Zoom = OSM\Zoom + zoom @@ -738,10 +732,9 @@ Module OSM OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) Case #PB_EventType_MouseMove If OSM\MoveStartingPoint\x <> - 1 - ;Need a refresh - OSM\Moving = #True MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y + OSM\Moving = #True ;Old move values OldX = OSM\Position\x OldY = OSM\Position\y @@ -759,8 +752,6 @@ Module OSM ;Moved to a new tile ? ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) ;Debug "--- New tile" - ;*Drawing\x = TileX - ;*Drawing\y = TileY Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) Debug "OSM\TargetTile\x " + StrD(OSM\Drawing\x) + " ; OSM\TargetTile\y " + StrD(OSM\Drawing\y) @@ -881,8 +872,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 659 -; FirstLine = 626 +; CursorPosition = 635 +; FirstLine = 614 ; Folding = ----- ; EnableUnicode ; EnableThread From 3cd42fbee63e68b5199a5541407a79a887b533f2 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 25 Jul 2016 22:52:32 +0200 Subject: [PATCH 08/35] Cleaning --- osm.pb | 118 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/osm.pb b/osm.pb index 024ac95..d6e31e8 100644 --- a/osm.pb +++ b/osm.pb @@ -56,8 +56,6 @@ Module OSM OSMTileX.i OSMTileY.i OSMZoom.i - DeltaX.i - DeltaY.i Mutex.i Semaphore.i Dirty.i @@ -94,7 +92,6 @@ Module OSM Gadget.i ; Canvas Gadget Id TargetLocation.Location ; Latitude and Longitude from focus point - TargetTile.Tile ; Focus tile coords Drawing.DrawingParameters ; Drawing parameters based on focus point CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) @@ -312,8 +309,8 @@ Module OSM Protected mapHeight.l = Pow(2,OSM\Zoom+8) Protected x1.l,y1.l - ;Protected deltaX = OSM\Position\x - Int(OSM\TargetTile\x) * OSM\TileSize ;Get the position into the tile - ;Protected deltaY = OSM\Position\y - Int(OSM\TargetTile\y) * OSM\TileSize + ;Protected deltaX = OSM\Position\x - Int(OSM\Drawing\x) * OSM\TileSize ;Get the position into the tile + ;Protected deltaY = OSM\Position\y - Int(OSM\Drawing\y) * OSM\TileSize ; get x value x1 = (*Location\Longitude+180)*(mapWidth/360) @@ -493,8 +490,8 @@ Module OSM Procedure DrawTile(*Tile.Tile) - Protected x = *Tile\x ; - OSM\DeltaX - Protected y = *Tile\y ; - OSM\DeltaY + Protected x = *Tile\x + Protected y = *Tile\y Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) Debug " at coords " + Str(x) + "," + Str(y) @@ -528,6 +525,10 @@ Module OSM Protected nx = CenterX / OSM\TileSize ;How many tiles around the point Protected ny = CenterY / OSM\TileSize + ;Pixel shift, aka position in the tile + Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) + Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) + Debug "Drawing tiles" For y = - ny To ny @@ -547,8 +548,8 @@ Module OSM OSM\TilesThreads()\Tile = *NewTile ;New tile parameters - \x = CenterX + x * OSM\TileSize - *Drawing\DeltaX - \y = CenterY + y * OSM\TileSize - *Drawing\DeltaY + \x = CenterX + x * OSM\TileSize - DeltaX + \y = CenterY + y * OSM\TileSize - DeltaY \OSMTileX = tx + x \OSMTileY = ty + y \OSMZoom = OSM\Zoom @@ -584,17 +585,21 @@ Module OSM EndProcedure Procedure DrawTrack(*Drawing.DrawingParameters) + Protected Pixel.Pixel Protected Location.Location + Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) + Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) + If ListSize(OSM\track())>0 ForEach OSM\track() If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0 getPixelCoorfromLocation(@OSM\track(),@Pixel) If ListIndex(OSM\track())=0 - MovePathCursor(Pixel\X + *Drawing\DeltaX, Pixel\Y + *Drawing\DeltaY) + MovePathCursor(Pixel\X + DeltaX, Pixel\Y + DeltaY) Else - AddPathLine(Pixel\X + *Drawing\DeltaX, Pixel\Y + *Drawing\DeltaY) + AddPathLine(Pixel\X + DeltaX, Pixel\Y + DeltaY) EndIf EndIf @@ -603,10 +608,12 @@ Module OSM VectorSourceColor(RGBA(0, 255, 0, 150)) StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) - EndIf + EndIf + EndProcedure - Procedure Pointer(x.l,y.l,color.l=#Red) + Procedure Pointer(x.i, y.i, color.l = #Red) + color=RGBA(255, 0, 0, 255) VectorSourceColor(color) MovePathCursor(x, y) @@ -618,18 +625,20 @@ Module OSM AddPathCircle(0,-16,5,0,360,#PB_Path_Relative) VectorSourceColor(color) FillPath(#PB_Path_Preserve):VectorSourceColor(RGBA(0, 0, 0, 255)):StrokePath(1) + EndProcedure Procedure DrawingThread(*Drawing.DrawingParameters) Repeat - WaitSemaphore(OSM\Drawing\Semaphore) + WaitSemaphore(*Drawing\Semaphore) Debug "--------- Main drawing thread ------------" - LockMutex(OSM\Drawing\Mutex) ; Only one main drawing thread at once - OSM\Drawing\Dirty = #False + LockMutex(*Drawing\Mutex) ; Only one main drawing thread at once + + *Drawing\Dirty = #False Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2 @@ -643,39 +652,37 @@ Module OSM ;- Redraw ;If something was not correctly drawn, redraw after a while - If OSM\Drawing\Dirty + If *Drawing\Dirty Debug "Something was dirty ! We try again to redraw" ;Delay(250) - OSM\Drawing\PassNb + 1 - SignalSemaphore(OSM\Drawing\Semaphore) + *Drawing\PassNb + 1 + SignalSemaphore(*Drawing\Semaphore) EndIf - UnlockMutex(OSM\Drawing\Mutex) + UnlockMutex(*Drawing\Mutex) - - Until OSM\Drawing\End + Until *Drawing\End EndProcedure Procedure SetLocation(latitude.d, longitude.d, zoom = 15) - If zoom > OSM\ZoomMax : zoom = OSM\ZoomMax : EndIf - If zoom < OSM\ZoomMin : zoom = OSM\ZoomMin : EndIf - OSM\Zoom = zoom OSM\TargetLocation\Latitude = latitude OSM\TargetLocation\Longitude = longitude - LatLon2XY(@OSM\TargetLocation, @OSM\TargetTile) - ;Convert X, Y in tile.decimal into real pixels - OSM\Position\X = OSM\TargetTile\X * OSM\TileSize - OSM\Position\Y = OSM\TargetTile\Y * OSM\TileSize - ;*** Creates a drawing thread and fill parameters + + OSM\Zoom = zoom + + If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf + If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf + LockMutex(OSM\Drawing\Mutex) - OSM\Drawing\x = OSM\TargetTile\x - OSM\Drawing\y = OSM\TargetTile\y - ;Position in the tile - OSM\Drawing\DeltaX = OSM\Drawing\x * OSM\TileSize - (Int(OSM\Drawing\x) * OSM\TileSize) - OSM\Drawing\DeltaY = OSM\Drawing\y * OSM\TileSize - (Int(OSM\Drawing\y) * OSM\TileSize) + LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) + ;Convert X, Y in tile.decimal into real pixels + OSM\Position\X = OSM\Drawing\x * OSM\TileSize + OSM\Position\Y = OSM\Drawing\y * OSM\TileSize + OSM\Drawing\PassNb = 1 UnlockMutex(OSM\Drawing\Mutex) + ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) ;*** @@ -692,17 +699,16 @@ Module OSM If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf - LatLon2XY(@OSM\TargetLocation, @OSM\TargetTile) - OSM\Position\X = OSM\TargetTile\X * OSM\TileSize - OSM\Position\Y = OSM\TargetTile\Y * OSM\TileSize - ;*** Creates a drawing thread and fill parameters + LockMutex(OSM\Drawing\Mutex) - OSM\Drawing\x = OSM\TargetTile\x - OSM\Drawing\y = OSM\TargetTile\y - ;Position in the tile - OSM\Drawing\DeltaX = OSM\Drawing\x * OSM\TileSize - (Int(OSM\Drawing\x) * OSM\TileSize) - OSM\Drawing\DeltaY = OSM\Drawing\y * OSM\TileSize - (Int(OSM\Drawing\y) * OSM\TileSize) + LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) + ;Convert X, Y in tile.decimal into real pixels + OSM\Position\X = OSM\Drawing\x * OSM\TileSize + OSM\Position\Y = OSM\Drawing\y * OSM\TileSize + ;*** Creates a drawing thread and fill parameters + OSM\Drawing\PassNb = 1 UnlockMutex(OSM\Drawing\Mutex) + ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) ;*** @@ -741,25 +747,23 @@ Module OSM ;New move values OSM\Position\x - MouseX OSM\Position\y - MouseY - ;-*** Sill parameters and signal the drawing thread + ;-*** Fill parameters and signal the drawing thread LockMutex(OSM\Drawing\Mutex) ;OSM tile position in tile.decimal OSM\Drawing\x = OSM\Position\x / OSM\TileSize OSM\Drawing\y = OSM\Position\y / OSM\TileSize - ;Pixel shift - OSM\Drawing\DeltaX = OSM\Position\x - Int(OSM\Drawing\x) * OSM\TileSize - OSM\Drawing\DeltaY = OSM\Position\y - Int(OSM\Drawing\y) * OSM\TileSize + OSM\Drawing\PassNb = 1 ;Moved to a new tile ? ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) ;Debug "--- New tile" Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) - Debug "OSM\TargetTile\x " + StrD(OSM\Drawing\x) + " ; OSM\TargetTile\y " + StrD(OSM\Drawing\y) + Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) ;EndIf - OSM\Drawing\PassNb = 1 UnlockMutex(OSM\Drawing\Mutex) + ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) - ;- *** + ;- *** OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) ;If CallBackLocation send Location to function @@ -770,12 +774,12 @@ Module OSM Case #PB_EventType_LeftButtonUp OSM\Moving = #False OSM\MoveStartingPoint\x = - 1 - OSM\TargetTile\x = OSM\Position\x / OSM\TileSize - OSM\TargetTile\y = OSM\Position\y / OSM\TileSize + OSM\Drawing\x = OSM\Position\x / OSM\TileSize + OSM\Drawing\y = OSM\Position\y / OSM\TileSize Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) - XY2LatLon(@OSM\TargetTile, @OSM\TargetLocation) + XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) ;Draw() - Debug "OSM\TargetTile\x " + StrD(OSM\TargetTile\x) + " ; OSM\TargetTile\y " + StrD(OSM\TargetTile\y) + Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) ;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude)) ;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude)) EndSelect @@ -872,8 +876,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 635 -; FirstLine = 614 +; CursorPosition = 331 +; FirstLine = 328 ; Folding = ----- ; EnableUnicode ; EnableThread From 8c2f59801bc12b98d7d1889f59f4a65ff83f5352 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 25 Jul 2016 23:01:22 +0200 Subject: [PATCH 09/35] Track bugfix --- osm.pb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/osm.pb b/osm.pb index d6e31e8..bc396c3 100644 --- a/osm.pb +++ b/osm.pb @@ -309,8 +309,8 @@ Module OSM Protected mapHeight.l = Pow(2,OSM\Zoom+8) Protected x1.l,y1.l - ;Protected deltaX = OSM\Position\x - Int(OSM\Drawing\x) * OSM\TileSize ;Get the position into the tile - ;Protected deltaY = OSM\Position\y - Int(OSM\Drawing\y) * OSM\TileSize + Protected deltaX = OSM\Position\x - Int(OSM\Drawing\x) * OSM\TileSize ;Get the position into the tile + Protected deltaY = OSM\Position\y - Int(OSM\Drawing\y) * OSM\TileSize ; get x value x1 = (*Location\Longitude+180)*(mapWidth/360) @@ -329,8 +329,8 @@ Module OSM mercN = Log(Tan((#PI/4)+(latRad/2))) ; y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)); - *Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1); + deltaX - *Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1);+ deltaY + *Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1) - deltaX + *Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1) - deltaY EndProcedure Procedure LoadGpxFile(file.s) @@ -595,7 +595,7 @@ Module OSM ForEach OSM\track() If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0 - getPixelCoorfromLocation(@OSM\track(),@Pixel) + getPixelCoorfromLocation(@OSM\track(), @Pixel) If ListIndex(OSM\track())=0 MovePathCursor(Pixel\X + DeltaX, Pixel\Y + DeltaY) Else @@ -768,7 +768,7 @@ Module OSM OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) ;If CallBackLocation send Location to function If OSM\CallBackLocation>0 - CallFunctionFast(OSM\CallBackLocation,@OSM\TargetLocation) + CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) EndIf EndIf Case #PB_EventType_LeftButtonUp @@ -822,10 +822,11 @@ CompilerIf #PB_Compiler_IsMainFile EndStructure Procedure UpdateLocation(*Location.Location) - SetGadgetText(#String_0,StrD(*Location\Latitude)) - SetGadgetText(#String_1,StrD(*Location\Longitude)) + SetGadgetText(#String_0, StrD(*Location\Latitude)) + SetGadgetText(#String_1, StrD(*Location\Longitude)) ProcedureReturn 0 EndProcedure + ;- Main If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered ) @@ -876,8 +877,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 331 -; FirstLine = 328 +; CursorPosition = 332 +; FirstLine = 531 ; Folding = ----- ; EnableUnicode ; EnableThread From b5ae9895a684f8ba254a11f5246e16d37eff18cd Mon Sep 17 00:00:00 2001 From: djes Date: Tue, 26 Jul 2016 20:46:18 +0200 Subject: [PATCH 10/35] No more flickering, bugfix --- osm.pb | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/osm.pb b/osm.pb index bc396c3..cc82b73 100644 --- a/osm.pb +++ b/osm.pb @@ -112,7 +112,6 @@ Module OSM Moving.i Dirty.i ;To signal that drawing need a refresh LoadingMutex.i - DrawingMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :((((( List TilesThreads.TileThread() @@ -236,7 +235,6 @@ Module OSM OSM\TileSize = 256 OSM\MemCache\Mutex = CreateMutex() OSM\LoadingMutex = CreateMutex() - OSM\DrawingMutex = CreateMutex() ;OSM\CurlMutex = CreateMutex() OSM\Dirty = #False OSM\Drawing\Semaphore = CreateSemaphore() @@ -429,15 +427,10 @@ Module OSM Debug "Image buffer " + Str(*Buffer) If *Buffer - LockMutex(OSM\LoadingMutex) nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) - UnlockMutex(OSM\LoadingMutex) - If IsImage(nImage) Debug "Load from web " + TileURL + " as Tile nb " + nImage - LockMutex(OSM\LoadingMutex) SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG) - UnlockMutex(OSM\LoadingMutex) FreeMemory(*Buffer) Else Debug "Can't catch image " + TileURL @@ -458,7 +451,6 @@ Module OSM Protected nImage.i = -1 LockMutex(OSM\LoadingMutex) - LockMutex(OSM\MemCache\Mutex) *CacheImagePtr = AddElement(OSM\MemCache\Image()) Debug " CacheImagePtr : " + Str(*CacheImagePtr) @@ -496,8 +488,6 @@ Module OSM Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) Debug " at coords " + Str(x) + "," + Str(y) - LockMutex(OSM\DrawingMutex) - StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) If IsImage(*Tile\nImage) MovePathCursor(x, y) DrawVectorImage(ImageID(*Tile\nImage)) @@ -507,8 +497,6 @@ Module OSM Debug "Image missing" OSM\Drawing\Dirty = #True ;Signal that this image is missing so we should have to redraw EndIf - StopVectorDrawing() - UnlockMutex(OSM\DrawingMutex) EndProcedure @@ -642,13 +630,11 @@ Module OSM Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2 - DrawTiles(*Drawing) - LockMutex(OSM\DrawingMutex) StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) + DrawTiles(*Drawing) DrawTrack(*Drawing) Pointer(CenterX, CenterY, #Red) StopVectorDrawing() - UnlockMutex(OSM\DrawingMutex) ;- Redraw ;If something was not correctly drawn, redraw after a while @@ -755,10 +741,7 @@ Module OSM OSM\Drawing\PassNb = 1 ;Moved to a new tile ? ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) - ;Debug "--- New tile" - Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) - Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) ;EndIf UnlockMutex(OSM\Drawing\Mutex) ;Start drawing @@ -877,8 +860,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 332 -; FirstLine = 531 +; CursorPosition = 635 +; FirstLine = 613 ; Folding = ----- ; EnableUnicode ; EnableThread From e104fe08232146c6e358112e177209763c3d145a Mon Sep 17 00:00:00 2001 From: djes Date: Tue, 26 Jul 2016 21:54:04 +0200 Subject: [PATCH 11/35] last --- osm.pb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/osm.pb b/osm.pb index cc82b73..6e36f6e 100644 --- a/osm.pb +++ b/osm.pb @@ -514,8 +514,8 @@ Module OSM Protected ny = CenterY / OSM\TileSize ;Pixel shift, aka position in the tile - Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) - Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) + Protected DeltaX = *Drawing\x * OSM\TileSize - (tx * OSM\TileSize) + Protected DeltaY = *Drawing\y * OSM\TileSize - (ty * OSM\TileSize) Debug "Drawing tiles" @@ -636,6 +636,8 @@ Module OSM Pointer(CenterX, CenterY, #Red) StopVectorDrawing() + UnlockMutex(*Drawing\Mutex) + ;- Redraw ;If something was not correctly drawn, redraw after a while If *Drawing\Dirty @@ -644,9 +646,7 @@ Module OSM *Drawing\PassNb + 1 SignalSemaphore(*Drawing\Semaphore) EndIf - - UnlockMutex(*Drawing\Mutex) - + Until *Drawing\End EndProcedure @@ -860,8 +860,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 635 -; FirstLine = 613 +; CursorPosition = 514 +; FirstLine = 496 ; Folding = ----- ; EnableUnicode ; EnableThread From b71a1500adb7e9da6741500323c97612e04dadcd Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 27 Jul 2016 15:11:27 +0200 Subject: [PATCH 12/35] Cleaning --- osm.pb | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/osm.pb b/osm.pb index 6e36f6e..6f1d97d 100644 --- a/osm.pb +++ b/osm.pb @@ -56,7 +56,6 @@ Module OSM OSMTileX.i OSMTileY.i OSMZoom.i - Mutex.i Semaphore.i Dirty.i PassNB.i @@ -238,7 +237,6 @@ Module OSM ;OSM\CurlMutex = CreateMutex() OSM\Dirty = #False OSM\Drawing\Semaphore = CreateSemaphore() - OSM\Drawing\Mutex = CreateMutex() ;-*** PROXY @@ -623,9 +621,7 @@ Module OSM WaitSemaphore(*Drawing\Semaphore) Debug "--------- Main drawing thread ------------" - - LockMutex(*Drawing\Mutex) ; Only one main drawing thread at once - + *Drawing\Dirty = #False Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2 @@ -636,8 +632,6 @@ Module OSM Pointer(CenterX, CenterY, #Red) StopVectorDrawing() - UnlockMutex(*Drawing\Mutex) - ;- Redraw ;If something was not correctly drawn, redraw after a while If *Drawing\Dirty @@ -661,13 +655,11 @@ Module OSM If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf - LockMutex(OSM\Drawing\Mutex) LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) ;Convert X, Y in tile.decimal into real pixels OSM\Position\X = OSM\Drawing\x * OSM\TileSize OSM\Position\Y = OSM\Drawing\y * OSM\TileSize OSM\Drawing\PassNb = 1 - UnlockMutex(OSM\Drawing\Mutex) ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) ;*** @@ -686,14 +678,12 @@ Module OSM If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf - LockMutex(OSM\Drawing\Mutex) LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) ;Convert X, Y in tile.decimal into real pixels OSM\Position\X = OSM\Drawing\x * OSM\TileSize OSM\Position\Y = OSM\Drawing\y * OSM\TileSize ;*** Creates a drawing thread and fill parameters OSM\Drawing\PassNb = 1 - UnlockMutex(OSM\Drawing\Mutex) ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) ;*** @@ -734,7 +724,6 @@ Module OSM OSM\Position\x - MouseX OSM\Position\y - MouseY ;-*** Fill parameters and signal the drawing thread - LockMutex(OSM\Drawing\Mutex) ;OSM tile position in tile.decimal OSM\Drawing\x = OSM\Position\x / OSM\TileSize OSM\Drawing\y = OSM\Position\y / OSM\TileSize @@ -743,7 +732,6 @@ Module OSM ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) ;EndIf - UnlockMutex(OSM\Drawing\Mutex) ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) ;- *** @@ -860,8 +848,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 514 -; FirstLine = 496 +; CursorPosition = 45 +; FirstLine = 32 ; Folding = ----- ; EnableUnicode ; EnableThread From 767261b3e13fbde7efe540649b51777ef4b9a9ac Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 27 Jul 2016 15:37:21 +0200 Subject: [PATCH 13/35] Thyphoon adds and code cleaning --- osm.pb | 203 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 165 insertions(+), 38 deletions(-) diff --git a/osm.pb b/osm.pb index 6f1d97d..c71600c 100644 --- a/osm.pb +++ b/osm.pb @@ -21,13 +21,15 @@ UsePNGImageEncoder() DeclareModule OSM Declare InitOSM() - Declare OSMGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) + Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) Declare Event(Event.l) Declare SetLocation(latitude.d, longitude.d, zoom = 15) Declare DrawingThread(Null) Declare SetZoom(Zoom.i, mode.i = #PB_Relative) + Declare ZoomToArea() Declare SetCallBackLocation(*CallBackLocation) Declare LoadGpxFile(file.s); + Declare AddMarker(Latitude.d,Longitude.d,color.l=-1) EndDeclareModule Module OSM @@ -86,6 +88,10 @@ Module OSM Semaphore.i EndStructure + Structure Marker + Location.Location + color.l + EndStructure ;-OSM Structure Structure OSM Gadget.i ; Canvas Gadget Id @@ -117,7 +123,8 @@ Module OSM MapImageMutex.i ; Mutex to lock List track.Location() ;to display a GPX track - + List Marker.Marker() ; To diplay marker + EditMarkerIndex.l EndStructure Global OSM.OSM, Null.i @@ -272,7 +279,7 @@ Module OSM EndProcedure ;- *** - Procedure OSMGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) + Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) If Gadget = #PB_Any OSM\Gadget = CanvasGadget(OSM\Gadget, X, Y, Width, Height) Else @@ -300,7 +307,7 @@ Module OSM *Location\Latitude = Degree(LatitudeRad) EndProcedure - Procedure getPixelCoorfromLocation(*Location.Location, *Pixel.Pixel) ; TODO to Optimize + Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.Pixel) ; TODO to Optimize Protected mapWidth.l = Pow(2,OSM\Zoom+8) Protected mapHeight.l = Pow(2,OSM\Zoom+8) Protected x1.l,y1.l @@ -517,8 +524,8 @@ Module OSM Debug "Drawing tiles" - For y = - ny To ny - For x = - nx To nx + For y = - ny - 1 To ny + 1 + For x = - nx - 1 To nx + 1 ;Was quiting the loop if a move occured, giving maybe smoother movement ;If OSM\Moving @@ -568,6 +575,22 @@ Module OSM EndIf Next + EndProcedure + + Procedure Pointer(x.i, y.i, color.l = #Red) + + color=RGBA(255, 0, 0, 255) + VectorSourceColor(color) + MovePathCursor(x, y) + AddPathLine(-8,-16,#PB_Path_Relative) + AddPathCircle(8,0,8,180,0,#PB_Path_Relative) + AddPathLine(-8,16,#PB_Path_Relative) + ;FillPath(#PB_Path_Preserve) + ;ClipPath(#PB_Path_Preserve) + AddPathCircle(0,-16,5,0,360,#PB_Path_Relative) + VectorSourceColor(color) + FillPath(#PB_Path_Preserve):VectorSourceColor(RGBA(0, 0, 0, 255)):StrokePath(1) + EndProcedure Procedure DrawTrack(*Drawing.DrawingParameters) @@ -581,7 +604,7 @@ Module OSM ForEach OSM\track() If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0 - getPixelCoorfromLocation(@OSM\track(), @Pixel) + GetPixelCoordFromLocation(@OSM\track(), @Pixel) If ListIndex(OSM\track())=0 MovePathCursor(Pixel\X + DeltaX, Pixel\Y + DeltaY) Else @@ -598,20 +621,30 @@ Module OSM EndProcedure - Procedure Pointer(x.i, y.i, color.l = #Red) - - color=RGBA(255, 0, 0, 255) - VectorSourceColor(color) - MovePathCursor(x, y) - AddPathLine(-8,-16,#PB_Path_Relative) - AddPathCircle(8,0,8,180,0,#PB_Path_Relative) - AddPathLine(-8,16,#PB_Path_Relative) - ;FillPath(#PB_Path_Preserve) - ;ClipPath(#PB_Path_Preserve) - AddPathCircle(0,-16,5,0,360,#PB_Path_Relative) - VectorSourceColor(color) - FillPath(#PB_Path_Preserve):VectorSourceColor(RGBA(0, 0, 0, 255)):StrokePath(1) + + ; Add a Marker To the Map + Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1) + AddElement(OSM\Marker()) + OSM\Marker()\Location\Latitude=Latitude + OSM\Marker()\Location\Longitude=Longitude + OSM\Marker()\color=color + EndProcedure + + ; Draw all markers on the screen ! + Procedure DrawMarker(*Drawing.DrawingParameters) + Protected Pixel.Pixel + Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) + Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) + + ForEach OSM\Marker() + If OSM\Marker()\Location\Latitude<>0 And OSM\Marker()\Location\Longitude<>0 + GetPixelCoordFromLocation(OSM\Marker()\Location,@Pixel) + If Pixel\X+ DeltaX>0 And Pixel\Y+ DeltaY>0 And Pixel\X+ DeltaX= (b)) * (a) + Bool((b) > (a)) * (b)) + EndMacro + + + Procedure ZoomToArea() + ;Source => http://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map + ;bounding box in long/lat coords (x=long, y=lat) + Protected MinY.d,MaxY.d,MinX.d,MaxX.d + ForEach OSM\track() + If ListIndex(OSM\track())=0 Or OSM\track()\LongitudeMaxX + MaxX=OSM\track()\Longitude + EndIf + If ListIndex(OSM\track())=0 Or OSM\track()\LatitudeMaxY + MaxY=OSM\track()\Latitude + EndIf + Next + Protected DeltaX.d=MaxX-MinX ;assumption ! In original code DeltaX have no source + Protected centerX.d=MinX+DeltaX/2 ; assumption ! In original code CenterX have no source + Protected paddingFactor.f= 1.2 ;paddingFactor: this can be used to get the "120%" effect ThomM refers to. Value of 1.2 would get you the 120%. + + Protected ry1.d = Log((Sin(Radian(MinY)) + 1) / Cos(Radian(MinY))) + Protected ry2.d = Log((Sin(Radian(MaxY)) + 1) / Cos(Radian(MaxY))) + Protected ryc.d = (ry1 + ry2) / 2 + Protected centerY.d = Degree(ATan(SinH(ryc))) + + Protected resolutionHorizontal.d = DeltaX / GadgetWidth(OSM\Gadget) + + Protected vy0.d = Log(Tan(#PI*(0.25 + centerY/360))); + Protected vy1.d = Log(Tan(#PI*(0.25 + MaxY/360))) ; + Protected viewHeightHalf.d = GadgetHeight(OSM\Gadget)/2; + Protected zoomFactorPowered.d = viewHeightHalf / (40.7436654315252*(vy1 - vy0)) + Protected resolutionVertical.d = 360.0 / (zoomFactorPowered * OSM\TileSize) + If resolutionHorizontal<>0 And resolutionVertical<>0 + Protected resolution.d = Max(resolutionHorizontal, resolutionVertical)* paddingFactor + Protected zoom.d = Log(360 / (resolution * OSM\TileSize))/Log(2) + + Protected lon.d = centerX; + Protected lat.d = centerY; + + SetLocation(lat,lon, Round(zoom,#PB_Round_Down)) + Else + SetLocation(OSM\TargetLocation\Latitude,OSM\TargetLocation\Longitude, 15) + EndIf + EndProcedure Procedure SetZoom(Zoom.i, mode.i = #PB_Relative) @@ -764,16 +859,17 @@ Module OSM EndProcedure EndModule - -;Demonstration +;-Exemple CompilerIf #PB_Compiler_IsMainFile + InitNetwork() + Enumeration #Window_0 #Map - #Button_0 - #Button_1 - #Button_2 - #Button_3 + #Gdt_Left + #Gdt_Right + #Gdt_Up + #Gdt_Down #Button_4 #Button_5 #Combo_0 @@ -785,6 +881,7 @@ CompilerIf #PB_Compiler_IsMainFile #String_0 #String_1 #Gdt_LoadGpx + #Gdt_AddMarker EndEnumeration Structure Location @@ -798,20 +895,36 @@ CompilerIf #PB_Compiler_IsMainFile ProcedureReturn 0 EndProcedure - ;- Main - If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered ) - + Procedure ResizeAll() + ResizeGadget(#Map,10,10,WindowWidth(#Window_0)-198,WindowHeight(#Window_0)-59) + ResizeGadget(#Text_1,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_Left,WindowWidth(#Window_0)-150,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_Right,WindowWidth(#Window_0)-90,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_Up,WindowWidth(#Window_0)-110,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_Down,WindowWidth(#Window_0)-110,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Text_2,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Button_4,WindowWidth(#Window_0)-150,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Button_5,WindowWidth(#Window_0)-100,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Text_3,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#String_0,WindowWidth(#Window_0)-100,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#String_1,WindowWidth(#Window_0)-100,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Text_4,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_AddMarker,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) + EndProcedure + + If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) OSM::InitOSM() LoadFont(0, "Wingdings", 12) LoadFont(1, "Arial", 12, #PB_Font_Bold) - OSM::OSMGadget(#Map, 10, 10, 512, 512) + OSM::MapGadget(#Map, 10, 10, 512, 512) TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ") - ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Button_0, FontID(0)) - ButtonGadget(#Button_1, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Button_1, FontID(0)) - ButtonGadget(#Button_2, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Button_2, FontID(0)) - ButtonGadget(#Button_3, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Button_3, FontID(0)) + ButtonGadget(#Gdt_Left, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Gdt_Left, FontID(0)) + ButtonGadget(#Gdt_Right, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Gdt_Right, FontID(0)) + ButtonGadget(#Gdt_Up, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Gdt_Up, FontID(0)) + ButtonGadget(#Gdt_Down, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Gdt_Down, FontID(0)) TextGadget(#Text_2, 530, 160, 60, 15, "Zoom : ") ButtonGadget(#Button_4, 550, 180, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1)) ButtonGadget(#Button_5, 600, 180, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1)) @@ -819,7 +932,8 @@ CompilerIf #PB_Compiler_IsMainFile StringGadget(#String_0, 600, 230, 90, 20, "") TextGadget(#Text_4, 530, 250, 60, 15, "Longitude : ") StringGadget(#String_1, 600, 250, 90, 20, "") - ButtonGadget(#Gdt_LoadGpx, 530, 280, 150, 30, "Load GPX") + ButtonGadget(#Gdt_AddMarker, 530, 280, 150, 30, "Add Marker") + ButtonGadget(#Gdt_LoadGpx, 530, 310, 150, 30, "Load GPX") Define Event.i, Gadget.i, Quit.b = #False Define pfValue.d @@ -835,22 +949,35 @@ CompilerIf #PB_Compiler_IsMainFile Case #PB_Event_Gadget ;{ Gadget = EventGadget() Select Gadget + Case #Gdt_Up + ;OSM::Move(0,-0.5) + Case #Gdt_Down + ;OSM::Move(0,0.5) + Case #Gdt_Left + ;OSM::Move(-0.5,0) + Case #Gdt_Right + ;OSM::Move(0.5,0) Case #Button_4 OSM::SetZoom(1) Case #Button_5 OSM::SetZoom( - 1) Case #Gdt_LoadGpx OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) + OSM::ZoomToArea() ; <-To center the view, and to viex all the track + Case #Gdt_AddMarker + OSM:: AddMarker(ValD(GetGadgetText(#String_0)),ValD(GetGadgetText(#String_1)),RGBA(Random(255),Random(255),Random(255),255)) EndSelect + Case #PB_Event_SizeWindow + ResizeAll() EndSelect Until Quit = #True EndIf CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 45 -; FirstLine = 32 -; Folding = ----- +; CursorPosition = 661 +; FirstLine = 642 +; Folding = ------ ; EnableUnicode ; EnableThread ; EnableXP \ No newline at end of file From b93f22adb1bc05bb6ebf672f500239e3603330ae Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 27 Jul 2016 16:53:45 +0200 Subject: [PATCH 14/35] Avoiding some mutexes --- osm.pb | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/osm.pb b/osm.pb index c71600c..76bb40d 100644 --- a/osm.pb +++ b/osm.pb @@ -116,7 +116,6 @@ Module OSM Moving.i Dirty.i ;To signal that drawing need a refresh - LoadingMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :((((( List TilesThreads.TileThread() @@ -240,7 +239,6 @@ Module OSM OSM\MoveStartingPoint\x = - 1 OSM\TileSize = 256 OSM\MemCache\Mutex = CreateMutex() - OSM\LoadingMutex = CreateMutex() ;OSM\CurlMutex = CreateMutex() OSM\Dirty = #False OSM\Drawing\Semaphore = CreateSemaphore() @@ -372,7 +370,6 @@ Module OSM Debug "Check if we have this image in memory" - LockMutex(OSM\LoadingMutex) LockMutex(OSM\MemCache\Mutex) ForEach OSM\MemCache\Image() If Zoom = OSM\MemCache\Image()\Zoom And OSM\MemCache\Image()\xTile = XTile And OSM\MemCache\Image()\yTile = YTile @@ -384,7 +381,6 @@ Module OSM EndIf Next UnlockMutex(OSM\MemCache\Mutex) - UnlockMutex(OSM\LoadingMutex) ProcedureReturn nImage @@ -455,20 +451,23 @@ Module OSM Protected *CacheImagePtr Protected nImage.i = -1 - LockMutex(OSM\LoadingMutex) - LockMutex(OSM\MemCache\Mutex) + LockMutex(OSM\MemCache\Mutex) + ;Push and pop as we are threaded + PushListPosition(OSM\MemCache\Image()) *CacheImagePtr = AddElement(OSM\MemCache\Image()) Debug " CacheImagePtr : " + Str(*CacheImagePtr) OSM\MemCache\Image()\xTile = *Tile\OSMTileX OSM\MemCache\Image()\yTile = *Tile\OSMTileY OSM\MemCache\Image()\Zoom = *Tile\OSMZoom OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro + PopListPosition(OSM\MemCache\Image()) UnlockMutex(OSM\MemCache\Mutex) nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) If nImage = -1 nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) EndIf LockMutex(OSM\MemCache\Mutex) + ChangeCurrentElement(OSM\MemCache\Image(), *CacheImagePtr) If nImage <> -1 Debug "Adding tile " + Str(nImage) + " to mem cache" ;AddTileToMemCache(Zoom, XTile, YTile, nImage) @@ -481,7 +480,6 @@ Module OSM EndIf UnlockMutex(OSM\MemCache\Mutex) *Tile\nImage = nImage - UnlockMutex(OSM\LoadingMutex) EndProcedure @@ -673,10 +671,11 @@ Module OSM ;Delay(250) *Drawing\PassNb + 1 SignalSemaphore(*Drawing\Semaphore) -; Else -; ;Clean the semaphore -; Repeat -; Until TrySemaphore(*Drawing\Semaphore) = 0 + ;TODO : Could be nice to avoid multiple redraws when not moving anymore + ; Else +; ;Clean the semaphore +; Repeat +; Until TrySemaphore(*Drawing\Semaphore) = 0 EndIf Until *Drawing\End @@ -975,8 +974,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 661 -; FirstLine = 642 +; CursorPosition = 672 +; FirstLine = 646 ; Folding = ------ ; EnableUnicode ; EnableThread From 8b817c2525ff4ca8203998c90e6f2a324dda80c7 Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 27 Jul 2016 20:26:09 +0200 Subject: [PATCH 15/35] Better loading with better mutex handling --- osm.pb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/osm.pb b/osm.pb index 76bb40d..c9b9006 100644 --- a/osm.pb +++ b/osm.pb @@ -58,6 +58,7 @@ Module OSM OSMTileX.i OSMTileY.i OSMZoom.i + Mutex.i Semaphore.i Dirty.i PassNB.i @@ -241,6 +242,7 @@ Module OSM OSM\MemCache\Mutex = CreateMutex() ;OSM\CurlMutex = CreateMutex() OSM\Dirty = #False + OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Semaphore = CreateSemaphore() ;-*** PROXY @@ -370,7 +372,7 @@ Module OSM Debug "Check if we have this image in memory" - LockMutex(OSM\MemCache\Mutex) + ;TODO : use maps ForEach OSM\MemCache\Image() If Zoom = OSM\MemCache\Image()\Zoom And OSM\MemCache\Image()\xTile = XTile And OSM\MemCache\Image()\yTile = YTile nImage = OSM\MemCache\Image()\nImage @@ -380,7 +382,6 @@ Module OSM ; DeleteElement(OSM\MemCache\Image()) EndIf Next - UnlockMutex(OSM\MemCache\Mutex) ProcedureReturn nImage @@ -394,6 +395,7 @@ Module OSM Debug "Check if we have this image on HDD" If FileSize(OSM\HDDCachePath + cacheFile) > 0 + nImage = LoadImage(#PB_Any, OSM\HDDCachePath + CacheFile) If IsImage(nImage) @@ -522,6 +524,8 @@ Module OSM Debug "Drawing tiles" + ;We're locking the cache to launch all drawings with existing tiles (the loading threads will be launched but delayed after the drawing) + LockMutex(OSM\MemCache\Mutex) For y = - ny - 1 To ny + 1 For x = - nx - 1 To nx + 1 @@ -548,7 +552,7 @@ Module OSM ;Check if the image exists \nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY) If \nImage = -1 - ;If not, load it in the background + ;If not, load it in the background (but after the drawing thanks to the mutex) \GetImageThread = CreateThread(@GetImageThread(), *NewTile) OSM\TilesThreads()\GetImageThread = \GetImageThread Debug " Creating get image thread nb " + Str(\GetImageThread) @@ -563,6 +567,7 @@ Module OSM EndIf Next Next + UnlockMutex(OSM\MemCache\Mutex) ;Free tile memory when the loading thread has finished ;TODO : exit this proc from drawtiles in a special "free ressources" task @@ -666,17 +671,18 @@ Module OSM ;- Redraw ;If something was not correctly drawn, redraw after a while + ;Be sure that we're not modifying while moving + LockMutex(OSM\Drawing\Mutex) If *Drawing\Dirty Debug "Something was dirty ! We try again to redraw" ;Delay(250) *Drawing\PassNb + 1 SignalSemaphore(*Drawing\Semaphore) - ;TODO : Could be nice to avoid multiple redraws when not moving anymore - ; Else -; ;Clean the semaphore -; Repeat -; Until TrySemaphore(*Drawing\Semaphore) = 0 + Else + ;Clean the semaphore to avoid multiple unuseful redraws + Repeat : Until TrySemaphore(*Drawing\Semaphore) = 0 EndIf + UnlockMutex(OSM\Drawing\Mutex) Until *Drawing\End @@ -819,9 +825,11 @@ Module OSM OSM\Position\y - MouseY ;-*** Fill parameters and signal the drawing thread ;OSM tile position in tile.decimal + LockMutex(OSM\Drawing\Mutex) OSM\Drawing\x = OSM\Position\x / OSM\TileSize OSM\Drawing\y = OSM\Position\y / OSM\TileSize OSM\Drawing\PassNb = 1 + UnlockMutex(OSM\Drawing\Mutex) ;Moved to a new tile ? ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) @@ -974,8 +982,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 672 -; FirstLine = 646 +; CursorPosition = 374 +; FirstLine = 348 ; Folding = ------ ; EnableUnicode ; EnableThread From 85b49e255d6ea162ce020b54ca7910f4113621e8 Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 27 Jul 2016 21:16:38 +0200 Subject: [PATCH 16/35] Images cache using map instead of list --- osm.pb | 68 +++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/osm.pb b/osm.pb index c9b9006..fe98c4f 100644 --- a/osm.pb +++ b/osm.pb @@ -77,14 +77,11 @@ Module OSM Structure ImgMemCach nImage.i - Zoom.i - XTile.i - YTile.i Usage.i EndStructure Structure TileMemCach - List Image.ImgMemCach() + Map Images.ImgMemCach() Mutex.i Semaphore.i EndStructure @@ -239,7 +236,6 @@ Module OSM OSM\ZoomMax = 18 OSM\MoveStartingPoint\x = - 1 OSM\TileSize = 256 - OSM\MemCache\Mutex = CreateMutex() ;OSM\CurlMutex = CreateMutex() OSM\Dirty = #False OSM\Drawing\Mutex = CreateMutex() @@ -367,23 +363,18 @@ Module OSM EndProcedure Procedure.i GetTileFromMem(Zoom.i, XTile.i, YTile.i) - - Protected nImage.i = -1 - + + Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0") + Debug "Check if we have this image in memory" - ;TODO : use maps - ForEach OSM\MemCache\Image() - If Zoom = OSM\MemCache\Image()\Zoom And OSM\MemCache\Image()\xTile = XTile And OSM\MemCache\Image()\yTile = YTile - nImage = OSM\MemCache\Image()\nImage - Debug "Load from MEM Tile X : " + Str(XTile) + " ; Tile Y : " + Str(YTile) + " nImage:" + Str(nImage) - Break; - ;ElseIf Zoom<>OSM\MemCache\Image()\Zoom - ; DeleteElement(OSM\MemCache\Image()) - EndIf - Next - - ProcedureReturn nImage + If FindMapElement(OSM\MemCache\Images(), key) + Debug "Key : " + key + " found !" + ProcedureReturn OSM\MemCache\Images()\nImage + Else + Debug "Key : " + key + " not found !" + ProcedureReturn -1 + EndIf EndProcedure @@ -450,37 +441,24 @@ Module OSM Procedure GetImageThread(*Tile.Tile) - Protected *CacheImagePtr Protected nImage.i = -1 - - LockMutex(OSM\MemCache\Mutex) - ;Push and pop as we are threaded - PushListPosition(OSM\MemCache\Image()) - *CacheImagePtr = AddElement(OSM\MemCache\Image()) - Debug " CacheImagePtr : " + Str(*CacheImagePtr) - OSM\MemCache\Image()\xTile = *Tile\OSMTileX - OSM\MemCache\Image()\yTile = *Tile\OSMTileY - OSM\MemCache\Image()\Zoom = *Tile\OSMZoom - OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro - PopListPosition(OSM\MemCache\Image()) - UnlockMutex(OSM\MemCache\Mutex) + Protected key.s = "Z" + RSet(Str(*Tile\OSMZoom), 4, "0") + "X" + RSet(Str(*Tile\OSMTileX), 8, "0") + "Y" + RSet(Str(*Tile\OSMTileY), 8, "0") + + ;Adding the image to the cache if possible + AddMapElement(OSM\MemCache\Images(), key) nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) If nImage = -1 nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) EndIf - LockMutex(OSM\MemCache\Mutex) - ChangeCurrentElement(OSM\MemCache\Image(), *CacheImagePtr) If nImage <> -1 - Debug "Adding tile " + Str(nImage) + " to mem cache" - ;AddTileToMemCache(Zoom, XTile, YTile, nImage) - OSM\MemCache\Image()\nImage = nImage + OSM\MemCache\Images(key)\nImage = nImage Debug "Image nb " + Str(nImage) + " successfully added to mem cache" + Debug "With the following key : " + key Else - Debug "Error GetImageThread procedure, tile not loaded - Zoom:" + Str(*Tile\OSMZoom) + " X:" + Str(*Tile\OSMTileX) + " Y:" + Str(*Tile\OSMTileY) - DeleteElement(OSM\MemCache\Image()) + Debug "Error GetImageThread procedure, image not loaded - " + key nImage = -1 EndIf - UnlockMutex(OSM\MemCache\Mutex) + ;Define this tile image nb *Tile\nImage = nImage EndProcedure @@ -524,8 +502,6 @@ Module OSM Debug "Drawing tiles" - ;We're locking the cache to launch all drawings with existing tiles (the loading threads will be launched but delayed after the drawing) - LockMutex(OSM\MemCache\Mutex) For y = - ny - 1 To ny + 1 For x = - nx - 1 To nx + 1 @@ -557,6 +533,7 @@ Module OSM OSM\TilesThreads()\GetImageThread = \GetImageThread Debug " Creating get image thread nb " + Str(\GetImageThread) EndIf + DrawTile(*NewTile) EndWith @@ -567,7 +544,6 @@ Module OSM EndIf Next Next - UnlockMutex(OSM\MemCache\Mutex) ;Free tile memory when the loading thread has finished ;TODO : exit this proc from drawtiles in a special "free ressources" task @@ -982,8 +958,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 374 -; FirstLine = 348 +; CursorPosition = 481 +; FirstLine = 455 ; Folding = ------ ; EnableUnicode ; EnableThread From 7e9de1049605967b2c3ff0a06bcbb5df982dc738 Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 27 Jul 2016 21:31:29 +0200 Subject: [PATCH 17/35] Cleaning --- osm.pb | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/osm.pb b/osm.pb index fe98c4f..8ee059d 100644 --- a/osm.pb +++ b/osm.pb @@ -82,14 +82,13 @@ Module OSM Structure TileMemCach Map Images.ImgMemCach() - Mutex.i - Semaphore.i EndStructure Structure Marker Location.Location color.l EndStructure + ;-OSM Structure Structure OSM Gadget.i ; Canvas Gadget Id @@ -109,16 +108,13 @@ Module OSM TileSize.i ; Tile size downloaded on the server ex : 256 HDDCachePath.S ; Path where to load and save tiles downloaded from server - MemCache.TileMemCach ; Image in memory cache - List MapImageIndex.ImgMemCach() ; Index from MemCache\Image() to construct map + MemCache.TileMemCach ; Images in memory cache Moving.i Dirty.i ;To signal that drawing need a refresh - ;CurlMutex.i ;seems that I can't thread curl ! :((((( + ;CurlMutex.i ;seems that I can't thread curl ! :((((( List TilesThreads.TileThread() - MapImageMutex.i ; Mutex to lock - List track.Location() ;to display a GPX track List Marker.Marker() ; To diplay marker EditMarkerIndex.l @@ -363,9 +359,9 @@ Module OSM EndProcedure Procedure.i GetTileFromMem(Zoom.i, XTile.i, YTile.i) - + Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0") - + Debug "Check if we have this image in memory" If FindMapElement(OSM\MemCache\Images(), key) @@ -443,7 +439,7 @@ Module OSM Protected nImage.i = -1 Protected key.s = "Z" + RSet(Str(*Tile\OSMZoom), 4, "0") + "X" + RSet(Str(*Tile\OSMTileX), 8, "0") + "Y" + RSet(Str(*Tile\OSMTileY), 8, "0") - + ;Adding the image to the cache if possible AddMapElement(OSM\MemCache\Images(), key) nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) @@ -556,7 +552,7 @@ Module OSM EndProcedure - Procedure Pointer(x.i, y.i, color.l = #Red) + Procedure Pointer(x.i, y.i, color.l = #Red) color=RGBA(255, 0, 0, 255) VectorSourceColor(color) @@ -578,7 +574,7 @@ Module OSM Protected Location.Location Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) - + If ListSize(OSM\track())>0 ForEach OSM\track() @@ -615,7 +611,7 @@ Module OSM Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) - + ForEach OSM\Marker() If OSM\Marker()\Location\Latitude<>0 And OSM\Marker()\Location\Longitude<>0 GetPixelCoordFromLocation(OSM\Marker()\Location,@Pixel) @@ -633,11 +629,12 @@ Module OSM WaitSemaphore(*Drawing\Semaphore) Debug "--------- Main drawing thread ------------" - - *Drawing\Dirty = #False + Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2 + *Drawing\Dirty = #False + StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) DrawTiles(*Drawing) DrawTrack(*Drawing) @@ -647,8 +644,7 @@ Module OSM ;- Redraw ;If something was not correctly drawn, redraw after a while - ;Be sure that we're not modifying while moving - LockMutex(OSM\Drawing\Mutex) + LockMutex(OSM\Drawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore) If *Drawing\Dirty Debug "Something was dirty ! We try again to redraw" ;Delay(250) @@ -656,10 +652,10 @@ Module OSM SignalSemaphore(*Drawing\Semaphore) Else ;Clean the semaphore to avoid multiple unuseful redraws - Repeat : Until TrySemaphore(*Drawing\Semaphore) = 0 + Repeat : Until TrySemaphore(*Drawing\Semaphore) = 0 EndIf UnlockMutex(OSM\Drawing\Mutex) - + Until *Drawing\End EndProcedure @@ -685,16 +681,15 @@ Module OSM EndProcedure - Macro Min(a,b) + Macro Min(a,b) (Bool((a) <= (b)) * (a) + Bool((b) < (a)) * (b)) EndMacro Macro Max(a,b) (Bool((a) >= (b)) * (a) + Bool((b) > (a)) * (b)) EndMacro - - - Procedure ZoomToArea() + + Procedure ZoomToArea() ;Source => http://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map ;bounding box in long/lat coords (x=long, y=lat) Protected MinY.d,MaxY.d,MinX.d,MaxX.d @@ -766,10 +761,10 @@ Module OSM EndProcedure - Procedure SetCallBackLocation(CallBackLocation.i) - OSM\CallBackLocation=CallBackLocation + OSM\CallBackLocation = CallBackLocation EndProcedure + Procedure Event(Event.l) Protected Gadget.i @@ -958,8 +953,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 481 -; FirstLine = 455 +; CursorPosition = 757 +; FirstLine = 705 ; Folding = ------ ; EnableUnicode ; EnableThread From a961f0137843447823bfecb57c7afd8ba39ae038 Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 27 Jul 2016 21:50:18 +0200 Subject: [PATCH 18/35] Cleaning --- osm.pb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osm.pb b/osm.pb index 8ee059d..a68f75b 100644 --- a/osm.pb +++ b/osm.pb @@ -241,7 +241,7 @@ Module OSM Global Proxy = #False - ;- => Use this to customise your preferences + ;- => Use this to customize your preferences ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") ; If Proxy ; PreferenceGroup("PROXY") @@ -524,7 +524,7 @@ Module OSM ;Check if the image exists \nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY) If \nImage = -1 - ;If not, load it in the background (but after the drawing thanks to the mutex) + ;If not, load it in the background \GetImageThread = CreateThread(@GetImageThread(), *NewTile) OSM\TilesThreads()\GetImageThread = \GetImageThread Debug " Creating get image thread nb " + Str(\GetImageThread) @@ -953,8 +953,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 757 -; FirstLine = 705 +; CursorPosition = 242 +; FirstLine = 222 ; Folding = ------ ; EnableUnicode ; EnableThread From 3cca54085216a8315e14a86950f8d5f50cc1693c Mon Sep 17 00:00:00 2001 From: djes Date: Thu, 28 Jul 2016 20:59:25 +0200 Subject: [PATCH 19/35] cleanup --- osm.pb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/osm.pb b/osm.pb index a68f75b..44f41e1 100644 --- a/osm.pb +++ b/osm.pb @@ -237,11 +237,11 @@ Module OSM OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Semaphore = CreateSemaphore() - ;-*** PROXY + ;- Proxy details Global Proxy = #False - ;- => Use this to customize your preferences + ;Use this to customize your preferences ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") ; If Proxy ; PreferenceGroup("PROXY") @@ -254,6 +254,7 @@ Module OSM ; EndIf Result = OpenPreferences(GetHomeDirectory() + "OSM.prefs") + If Proxy PreferenceGroup("PROXY") Global ProxyURL$ = ReadPreferenceString("ProxyURL", "") ;InputRequester("ProxyServer", "Do you use a Proxy Server? Then enter the full url:", "") @@ -264,12 +265,13 @@ Module OSM If Result ClosePreferences() EndIf - + curl_global_init(#CURL_GLOBAL_ALL); + + ;- Main drawing thread launching CreateThread(@DrawingThread(), @OSM\Drawing) EndProcedure - ;- *** Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) If Gadget = #PB_Any @@ -402,7 +404,6 @@ Module OSM Protected nImage.i = -1 Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" - ; Test if in cache else download it Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" Debug "Check if we have this image on Web" @@ -474,7 +475,7 @@ Module OSM DrawVectorText(Str(x) + ", " + Str(y)) Else Debug "Image missing" - OSM\Drawing\Dirty = #True ;Signal that this image is missing so we should have to redraw + OSM\Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw EndIf EndProcedure @@ -505,7 +506,7 @@ Module OSM ;If OSM\Moving ; Break 2 ;EndIf - + Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile)) If *NewTile With *NewTile @@ -953,8 +954,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 242 -; FirstLine = 222 +; CursorPosition = 723 +; FirstLine = 671 ; Folding = ------ ; EnableUnicode ; EnableThread From 489e9651b69fb72d2cde18992541ebfdefa64a26 Mon Sep 17 00:00:00 2001 From: djes Date: Thu, 28 Jul 2016 21:39:37 +0200 Subject: [PATCH 20/35] Added marker move by thyphoon --- osm.pb | 136 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 45 deletions(-) diff --git a/osm.pb b/osm.pb index 44f41e1..d5d2e2f 100644 --- a/osm.pb +++ b/osm.pb @@ -29,7 +29,7 @@ DeclareModule OSM Declare ZoomToArea() Declare SetCallBackLocation(*CallBackLocation) Declare LoadGpxFile(file.s); - Declare AddMarker(Latitude.d,Longitude.d,color.l=-1) + Declare AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1) EndDeclareModule Module OSM @@ -85,8 +85,9 @@ Module OSM EndStructure Structure Marker - Location.Location - color.l + Location.Location ; Latitude and Longitude from Marker + color.l ; Color Marker + CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (You must use VectorDrawing lib) EndStructure ;-OSM Structure @@ -236,8 +237,8 @@ Module OSM OSM\Dirty = #False OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Semaphore = CreateSemaphore() - - ;- Proxy details + OSM\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected + ;- Proxy details Global Proxy = #False @@ -265,7 +266,7 @@ Module OSM If Result ClosePreferences() EndIf - + curl_global_init(#CURL_GLOBAL_ALL); ;- Main drawing thread launching @@ -506,7 +507,7 @@ Module OSM ;If OSM\Moving ; Break 2 ;EndIf - + Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile)) If *NewTile With *NewTile @@ -599,11 +600,12 @@ Module OSM ; Add a Marker To the Map - Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1) + Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1) AddElement(OSM\Marker()) OSM\Marker()\Location\Latitude=Latitude OSM\Marker()\Location\Longitude=Longitude OSM\Marker()\color=color + OSM\Marker()\CallBackPointer = CallBackPointer EndProcedure ; Draw all markers on the screen ! @@ -614,10 +616,14 @@ Module OSM Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) ForEach OSM\Marker() - If OSM\Marker()\Location\Latitude<>0 And OSM\Marker()\Location\Longitude<>0 - GetPixelCoordFromLocation(OSM\Marker()\Location,@Pixel) - If Pixel\X+ DeltaX>0 And Pixel\Y+ DeltaY>0 And Pixel\X+ DeltaX 0 And OSM\Marker()\Location\Longitude <> 0 + GetPixelCoordFromLocation(OSM\Marker()\Location, @Pixel) + If Pixel\X + DeltaX > 0 And Pixel\Y + DeltaY > 0 And Pixel\X + DeltaX < GadgetWidth(OSM\Gadget) And Pixel\Y < GadgetHeight(OSM\Gadget) ; Only if visible ^_^ + If OSM\Marker()\CallBackPointer > 0 + CallFunctionFast(OSM\Marker()\CallBackPointer, Pixel\X + DeltaX, Pixel\Y + DeltaY) + Else + Pointer(Pixel\X + DeltaX, Pixel\Y + DeltaY, OSM\Marker()\color) + EndIf EndIf EndIf Next @@ -689,7 +695,7 @@ Module OSM Macro Max(a,b) (Bool((a) >= (b)) * (a) + Bool((b) > (a)) * (b)) EndMacro - + Procedure ZoomToArea() ;Source => http://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map ;bounding box in long/lat coords (x=long, y=lat) @@ -771,6 +777,7 @@ Module OSM Protected Gadget.i Protected MouseX.i, MouseY.i Protected OldX.i, OldY.i + Protected DeltaX.d, DeltaY.d Protected *Drawing.DrawingParameters If IsGadget(OSM\Gadget) And GadgetType(OSM\Gadget) = #PB_GadgetType_Canvas @@ -781,6 +788,19 @@ Module OSM Case OSM\Gadget Select EventType() Case #PB_EventType_LeftButtonDown + ;Check if we select a marker + Protected Pixel.Pixel + ForEach OSM\Marker() + GetPixelCoordFromLocation(@OSM\Marker()\Location, @Pixel) + ;LockMutex(OSM\Drawing\Mutex) + DeltaX = OSM\Drawing\x * OSM\TileSize - (Int(OSM\Drawing\x) * OSM\TileSize) + DeltaY = OSM\Drawing\y * OSM\TileSize - (Int(OSM\Drawing\y) * OSM\TileSize) + ;UnlockMutex(OSM\Drawing\Mutex) + If Pixel\X + DeltaX > GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - 4 And Pixel\X + DeltaX < GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) + 4 And Pixel\Y + DeltaY > GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - 4 And Pixel\Y + DeltaY < GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) + 4 + OSM\EditMarkerIndex = ListIndex(OSM\Marker()) + Break + EndIf + Next ;Mem cursor Coord OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) @@ -789,44 +809,56 @@ Module OSM MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y OSM\Moving = #True - ;Old move values - OldX = OSM\Position\x - OldY = OSM\Position\y - ;New move values - OSM\Position\x - MouseX - OSM\Position\y - MouseY - ;-*** Fill parameters and signal the drawing thread - ;OSM tile position in tile.decimal - LockMutex(OSM\Drawing\Mutex) - OSM\Drawing\x = OSM\Position\x / OSM\TileSize - OSM\Drawing\y = OSM\Position\y / OSM\TileSize - OSM\Drawing\PassNb = 1 - UnlockMutex(OSM\Drawing\Mutex) - ;Moved to a new tile ? - ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) - XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) - ;EndIf + ;move Marker + If OSM\EditMarkerIndex > -1 + SelectElement(OSM\Marker(), OSM\EditMarkerIndex) + Protected Tile.Tile + LatLon2XY(@OSM\Marker()\Location, @Tile) + Debug MouseX + Tile\x + MouseX / OSM\TileSize + Tile\y + MouseY / OSM\TileSize + XY2LatLon(@Tile, @OSM\Marker()\Location) + Else + ;New move values + OSM\Position\x - MouseX + OSM\Position\y - MouseY + ;-*** Fill parameters and signal the drawing thread + ;OSM tile position in tile.decimal + LockMutex(OSM\Drawing\Mutex) + OSM\Drawing\x = OSM\Position\x / OSM\TileSize + OSM\Drawing\y = OSM\Position\y / OSM\TileSize + OSM\Drawing\PassNb = 1 + UnlockMutex(OSM\Drawing\Mutex) + ;Moved to a new tile ? + ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) + XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) + ;EndIf + ;If CallBackLocation send Location to function + If OSM\CallBackLocation > 0 + CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) + EndIf + EndIf ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) ;- *** OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - ;If CallBackLocation send Location to function - If OSM\CallBackLocation>0 - CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) - EndIf - EndIf + EndIf Case #PB_EventType_LeftButtonUp OSM\Moving = #False OSM\MoveStartingPoint\x = - 1 - OSM\Drawing\x = OSM\Position\x / OSM\TileSize - OSM\Drawing\y = OSM\Position\y / OSM\TileSize - Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) - XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) - ;Draw() - Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) - ;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude)) - ;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude)) + If OSM\EditMarkerIndex > -1 + OSM\EditMarkerIndex = -1 + Else ;Move Map + OSM\Drawing\x = OSM\Position\x / OSM\TileSize + OSM\Drawing\y = OSM\Position\y / OSM\TileSize + Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) + XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) + ;Draw() + Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) + ;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude)) + ;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude)) + EndIf EndSelect EndSelect EndSelect @@ -874,6 +906,18 @@ CompilerIf #PB_Compiler_IsMainFile ProcedureReturn 0 EndProcedure + Procedure MyPointer(x.i, y.i) + Protected color.l + color=RGBA(0, 255, 0, 255) + VectorSourceColor(color) + MovePathCursor(x, y) + AddPathLine(-16,-32,#PB_Path_Relative) + AddPathCircle(16,0,16,180,0,#PB_Path_Relative) + AddPathLine(-16,32,#PB_Path_Relative) + VectorSourceColor(color) + FillPath(#PB_Path_Preserve):VectorSourceColor(RGBA(0, 0, 0, 255)):StrokePath(1) + EndProcedure + Procedure ResizeAll() ResizeGadget(#Map,10,10,WindowWidth(#Window_0)-198,WindowHeight(#Window_0)-59) ResizeGadget(#Text_1,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) @@ -918,6 +962,8 @@ CompilerIf #PB_Compiler_IsMainFile Define pfValue.d OSM::SetLocation(49.04599, 2.03347, 17) OSM::SetCallBackLocation(@UpdateLocation()) + OSM::AddMarker(49.0446828398,2.0349812508,-1,@MyPointer()) + Repeat Event = WaitWindowEvent() @@ -954,8 +1000,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 723 -; FirstLine = 671 +; CursorPosition = 850 +; FirstLine = 771 ; Folding = ------ ; EnableUnicode ; EnableThread From 6c6941108a017b4c482a3e8ba9ded97517ee17c3 Mon Sep 17 00:00:00 2001 From: djes Date: Thu, 28 Jul 2016 22:31:29 +0200 Subject: [PATCH 21/35] Debug commented --- osm.pb | 70 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/osm.pb b/osm.pb index d5d2e2f..08afb22 100644 --- a/osm.pb +++ b/osm.pb @@ -136,13 +136,13 @@ Module OSM If *ReceiveHTTPToMemoryBuffer = 0 *ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper) If *ReceiveHTTPToMemoryBuffer = 0 - Debug "Problem allocating memory" + ; Debug "Problem allocating memory" End EndIf Else *ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper) If *ReceiveHTTPToMemoryBuffer = 0 - Debug "Problem reallocating memory" + ; Debug "Problem reallocating memory" End EndIf EndIf @@ -179,7 +179,7 @@ Module OSM If Len(ProxyPort$) ProxyURL$ + ":" + ProxyPort$ EndIf - Debug ProxyURL$ + ; Debug ProxyURL$ curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$)) If Len(ProxyUser$) If Len(ProxyPassword$) @@ -201,22 +201,22 @@ Module OSM *ReceiveHTTPToMemoryBuffer = #Null ReceiveHTTPToMemoryBufferPtr = 0 Else - Debug "Problem allocating buffer" + ; Debug "Problem allocating buffer" EndIf ;curl_easy_cleanup(curl) ;Was its original place but moved below as it seems more logical to me. Else - Debug "CURL NOT OK" + ; Debug "CURL NOT OK" EndIf curl_easy_cleanup(curl) Else - Debug "Can't Init CURL" + ; Debug "Can't Init CURL" EndIf EndIf - Debug "Curl Buffer : " + Str(*Buffer) + ; Debug "Curl Buffer : " + Str(*Buffer) ProcedureReturn *Buffer @@ -289,8 +289,8 @@ Module OSM Protected LatRad.d = Radian(*Location\Latitude) *Tile\x = n * ( (*Location\Longitude + 180.0) / 360.0) *Tile\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0 - Debug "Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude) - Debug "Tile X : " + Str(*Tile\x) + " ; Tile Y : " + Str(*Tile\y) + ; Debug "Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude) + ; Debug "Tile X : " + Str(*Tile\x) + " ; Tile Y : " + Str(*Tile\y) EndProcedure ;*** Converts tile.decimal to coords @@ -365,13 +365,13 @@ Module OSM Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0") - Debug "Check if we have this image in memory" + ; Debug "Check if we have this image in memory" If FindMapElement(OSM\MemCache\Images(), key) - Debug "Key : " + key + " found !" + ; Debug "Key : " + key + " found !" ProcedureReturn OSM\MemCache\Images()\nImage Else - Debug "Key : " + key + " not found !" + ; Debug "Key : " + key + " not found !" ProcedureReturn -1 EndIf @@ -382,14 +382,14 @@ Module OSM Protected nImage.i Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" - Debug "Check if we have this image on HDD" + ; Debug "Check if we have this image on HDD" If FileSize(OSM\HDDCachePath + cacheFile) > 0 nImage = LoadImage(#PB_Any, OSM\HDDCachePath + CacheFile) If IsImage(nImage) - Debug "Load from HDD Tile " + CacheFile + ; Debug "Load from HDD Tile " + CacheFile ProcedureReturn nImage EndIf @@ -407,7 +407,7 @@ Module OSM Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" - Debug "Check if we have this image on Web" + ; Debug "Check if we have this image on Web" If Proxy ;LockMutex(OSM\CurlMutex) ;Seems no more necessary @@ -416,21 +416,21 @@ Module OSM Else *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous EndIf - Debug "Image buffer " + Str(*Buffer) + ; Debug "Image buffer " + Str(*Buffer) If *Buffer nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) If IsImage(nImage) - Debug "Load from web " + TileURL + " as Tile nb " + nImage + ; Debug "Load from web " + TileURL + " as Tile nb " + nImage SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG) FreeMemory(*Buffer) Else - Debug "Can't catch image " + TileURL + ; Debug "Can't catch image " + TileURL nImage = -1 ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) EndIf Else - Debug "Problem loading from web " + TileURL + ; Debug "Problem loading from web " + TileURL EndIf ProcedureReturn nImage @@ -450,10 +450,10 @@ Module OSM EndIf If nImage <> -1 OSM\MemCache\Images(key)\nImage = nImage - Debug "Image nb " + Str(nImage) + " successfully added to mem cache" - Debug "With the following key : " + key + ; Debug "Image nb " + Str(nImage) + " successfully added to mem cache" + ; Debug "With the following key : " + key Else - Debug "Error GetImageThread procedure, image not loaded - " + key + ; Debug "Error GetImageThread procedure, image not loaded - " + key nImage = -1 EndIf ;Define this tile image nb @@ -466,8 +466,8 @@ Module OSM Protected x = *Tile\x Protected y = *Tile\y - Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) - Debug " at coords " + Str(x) + "," + Str(y) + ; Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) + ; Debug " at coords " + Str(x) + "," + Str(y) If IsImage(*Tile\nImage) MovePathCursor(x, y) @@ -475,7 +475,7 @@ Module OSM MovePathCursor(x, y) DrawVectorText(Str(x) + ", " + Str(y)) Else - Debug "Image missing" + ; Debug "Image missing" OSM\Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw EndIf @@ -498,7 +498,7 @@ Module OSM Protected DeltaX = *Drawing\x * OSM\TileSize - (tx * OSM\TileSize) Protected DeltaY = *Drawing\y * OSM\TileSize - (ty * OSM\TileSize) - Debug "Drawing tiles" + ; Debug "Drawing tiles" For y = - ny - 1 To ny + 1 For x = - nx - 1 To nx + 1 @@ -529,7 +529,7 @@ Module OSM ;If not, load it in the background \GetImageThread = CreateThread(@GetImageThread(), *NewTile) OSM\TilesThreads()\GetImageThread = \GetImageThread - Debug " Creating get image thread nb " + Str(\GetImageThread) + ; Debug " Creating get image thread nb " + Str(\GetImageThread) EndIf DrawTile(*NewTile) @@ -537,7 +537,7 @@ Module OSM EndWith Else - Debug" Error, can't create a new tile." + ; Debug" Error, can't create a new tile." Break 2 EndIf Next @@ -635,7 +635,7 @@ Module OSM WaitSemaphore(*Drawing\Semaphore) - Debug "--------- Main drawing thread ------------" + ; Debug "--------- Main drawing thread ------------" Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2 @@ -653,7 +653,7 @@ Module OSM ;If something was not correctly drawn, redraw after a while LockMutex(OSM\Drawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore) If *Drawing\Dirty - Debug "Something was dirty ! We try again to redraw" + ; Debug "Something was dirty ! We try again to redraw" ;Delay(250) *Drawing\PassNb + 1 SignalSemaphore(*Drawing\Semaphore) @@ -814,7 +814,7 @@ Module OSM SelectElement(OSM\Marker(), OSM\EditMarkerIndex) Protected Tile.Tile LatLon2XY(@OSM\Marker()\Location, @Tile) - Debug MouseX + ; Debug MouseX Tile\x + MouseX / OSM\TileSize Tile\y + MouseY / OSM\TileSize XY2LatLon(@Tile, @OSM\Marker()\Location) @@ -852,10 +852,10 @@ Module OSM Else ;Move Map OSM\Drawing\x = OSM\Position\x / OSM\TileSize OSM\Drawing\y = OSM\Position\y / OSM\TileSize - Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) + ; Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) ;Draw() - Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) + ; Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) ;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude)) ;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude)) EndIf @@ -1000,8 +1000,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 850 -; FirstLine = 771 +; CursorPosition = 840 +; FirstLine = 805 ; Folding = ------ ; EnableUnicode ; EnableThread From 5863da28f5bb22c33f9cd459f93ab593ed46bf4d Mon Sep 17 00:00:00 2001 From: djes Date: Thu, 28 Jul 2016 22:52:56 +0200 Subject: [PATCH 22/35] Last version by Thyphoon --- osm.pb | 76 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/osm.pb b/osm.pb index 08afb22..bac3acf 100644 --- a/osm.pb +++ b/osm.pb @@ -93,7 +93,7 @@ Module OSM ;-OSM Structure Structure OSM Gadget.i ; Canvas Gadget Id - + Font.i ; Font to uses when write on the map TargetLocation.Location ; Latitude and Longitude from focus point Drawing.DrawingParameters ; Drawing parameters based on focus point @@ -238,7 +238,8 @@ Module OSM OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Semaphore = CreateSemaphore() OSM\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected - ;- Proxy details + OSM\Font=LoadFont(#PB_Any, "Comic Sans MS", 20, #PB_Font_Bold) + ;- Proxy details Global Proxy = #False @@ -274,6 +275,14 @@ Module OSM EndProcedure + Macro Min(a,b) + (Bool((a) <= (b)) * (a) + Bool((b) < (a)) * (b)) + EndMacro + + Macro Max(a,b) + (Bool((a) >= (b)) * (a) + Bool((b) > (a)) * (b)) + EndMacro + Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) If Gadget = #PB_Any OSM\Gadget = CanvasGadget(OSM\Gadget, X, Y, Width, Height) @@ -302,6 +311,23 @@ Module OSM *Location\Latitude = Degree(LatitudeRad) EndProcedure + ; HaversineAlgorithm + ; http://andrew.hedges.name/experiments/haversine/ + Procedure.d HaversineInKM(*posA.Location,*posB.Location) + Protected eQuatorialEarthRadius.d = 6378.1370;6372.795477598; + Protected dlong.d = (*posB\Longitude - *posA\Longitude); + Protected dlat.d = (*posB\Latitude - *posA\Latitude) ; + Protected alpha.d=dlat/2 + Protected beta.d=dlong/2 + Protected a.d = Sin(Radian(alpha)) * Sin(Radian(alpha)) + Cos(Radian(*posA\Latitude)) * Cos(Radian(*posB\Latitude)) * Sin(Radian(beta)) * Sin(Radian(beta)) + Protected c.d = ASin(Min(1,Sqr(a))); + Protected distance.d = 2*eQuatorialEarthRadius * c + ProcedureReturn distance ; + EndProcedure + + Procedure.d HaversineInM(*posA.Location,*posB.Location) + ProcedureReturn (1000 * HaversineInKM(@*posA,@*posB)); + EndProcedure Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.Pixel) ; TODO to Optimize Protected mapWidth.l = Pow(2,OSM\Zoom+8) Protected mapHeight.l = Pow(2,OSM\Zoom+8) @@ -574,23 +600,46 @@ Module OSM Protected Pixel.Pixel Protected Location.Location + Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) - + Protected km.f, memKm.i + If ListSize(OSM\track())>0 - ForEach OSM\track() + LockMutex(OSM\Drawing\Mutex) + ForEach OSM\track() + ;-Test Distance + If ListIndex(OSM\track())=0 + Location\Latitude=OSM\track()\Latitude + Location\Longitude=OSM\track()\Longitude + Else + km=km+HaversineInKM(@Location,@OSM\track()) ;<- display Distance + Location\Latitude=OSM\track()\Latitude + Location\Longitude=OSM\track()\Longitude + EndIf If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0 - GetPixelCoordFromLocation(@OSM\track(), @Pixel) + GetPixelCoordFromLocation(@OSM\track(),@Pixel) If ListIndex(OSM\track())=0 MovePathCursor(Pixel\X + DeltaX, Pixel\Y + DeltaY) Else AddPathLine(Pixel\X + DeltaX, Pixel\Y + DeltaY) + If Int(km)<>memKm + memKm=Int(km) + If OSM\Zoom>10 + BeginVectorLayer() + VectorFont(FontID(OSM\Font), OSM\Zoom) + VectorSourceColor(RGBA(50, 50, 50, 255)) + DrawVectorText(Str(Int(km))) + EndVectorLayer() + EndIf + EndIf + EndIf - EndIf - Next + UnlockMutex(OSM\Drawing\Mutex) + VectorSourceColor(RGBA(0, 255, 0, 150)) StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) @@ -688,13 +737,6 @@ Module OSM EndProcedure - Macro Min(a,b) - (Bool((a) <= (b)) * (a) + Bool((b) < (a)) * (b)) - EndMacro - - Macro Max(a,b) - (Bool((a) >= (b)) * (a) + Bool((b) > (a)) * (b)) - EndMacro Procedure ZoomToArea() ;Source => http://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map @@ -1000,9 +1042,9 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 840 -; FirstLine = 805 -; Folding = ------ +; CursorPosition = 605 +; FirstLine = 598 +; Folding = ------- ; EnableUnicode ; EnableThread ; EnableXP \ No newline at end of file From dd4ab3ccc5c59f117199e29516353be0ccb58e01 Mon Sep 17 00:00:00 2001 From: djes Date: Fri, 29 Jul 2016 13:36:48 +0200 Subject: [PATCH 23/35] Drawing pointer better handled + thyphoon code cleaning --- osm.pb | 323 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 168 insertions(+), 155 deletions(-) diff --git a/osm.pb b/osm.pb index bac3acf..0a0eeb2 100644 --- a/osm.pb +++ b/osm.pb @@ -41,10 +41,19 @@ Module OSM Latitude.d EndStructure - ;- Tile Structure - Structure Tile + Structure Position x.d y.d + EndStructure + + Structure PixelPosition + x.i + y.i + EndStructure + + ;- Tile Structure + Structure Tile + Position.Position OSMTileX.i OSMTileY.i OSMZoom.i @@ -53,12 +62,17 @@ Module OSM EndStructure Structure DrawingParameters - x.d - y.d + Position.Position + Canvas.i OSMTileX.i OSMTileY.i OSMZoom.i Mutex.i + TargetLocation.Location + CenterX.i + CenterY.i + DeltaX.i + DeltaY.i Semaphore.i Dirty.i PassNB.i @@ -70,11 +84,6 @@ Module OSM *Tile.Tile EndStructure - Structure Pixel - x.i - y.i - EndStructure - Structure ImgMemCach nImage.i Usage.i @@ -99,8 +108,8 @@ Module OSM CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) - Position.Pixel ; Actual focus Point coords in pixels - MoveStartingPoint.Pixel ; Start mouse position coords when dragging the map + Position.PixelPosition ; Actual focus point coords in pixels (global) + MoveStartingPoint.PixelPosition ; Start mouse position coords when dragging the map ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/ ZoomMin.i ; Min Zoom supported by server @@ -136,13 +145,13 @@ Module OSM If *ReceiveHTTPToMemoryBuffer = 0 *ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper) If *ReceiveHTTPToMemoryBuffer = 0 - ; Debug "Problem allocating memory" + ; Debug "Problem allocating memory" End EndIf Else *ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper) If *ReceiveHTTPToMemoryBuffer = 0 - ; Debug "Problem reallocating memory" + ; Debug "Problem reallocating memory" End EndIf EndIf @@ -179,7 +188,7 @@ Module OSM If Len(ProxyPort$) ProxyURL$ + ":" + ProxyPort$ EndIf - ; Debug ProxyURL$ + ; Debug ProxyURL$ curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$)) If Len(ProxyUser$) If Len(ProxyPassword$) @@ -201,22 +210,22 @@ Module OSM *ReceiveHTTPToMemoryBuffer = #Null ReceiveHTTPToMemoryBufferPtr = 0 Else - ; Debug "Problem allocating buffer" + ; Debug "Problem allocating buffer" EndIf ;curl_easy_cleanup(curl) ;Was its original place but moved below as it seems more logical to me. Else - ; Debug "CURL NOT OK" + ; Debug "CURL NOT OK" EndIf curl_easy_cleanup(curl) Else - ; Debug "Can't Init CURL" + ; Debug "Can't Init CURL" EndIf EndIf - ; Debug "Curl Buffer : " + Str(*Buffer) + ; Debug "Curl Buffer : " + Str(*Buffer) ProcedureReturn *Buffer @@ -239,7 +248,7 @@ Module OSM OSM\Drawing\Semaphore = CreateSemaphore() OSM\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected OSM\Font=LoadFont(#PB_Any, "Comic Sans MS", 20, #PB_Font_Bold) - ;- Proxy details + ;- Proxy details Global Proxy = #False @@ -275,7 +284,7 @@ Module OSM EndProcedure - Macro Min(a,b) + Macro Min(a,b) (Bool((a) <= (b)) * (a) + Bool((b) < (a)) * (b)) EndMacro @@ -283,6 +292,12 @@ Module OSM (Bool((a) >= (b)) * (a) + Bool((b) > (a)) * (b)) EndMacro + Procedure.d Distance(x1.d, y1.d, x2.d, y2.d) + Protected Result.d + Result = Sqr( (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) + ProcedureReturn Result + EndProcedure + Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) If Gadget = #PB_Any OSM\Gadget = CanvasGadget(OSM\Gadget, X, Y, Width, Height) @@ -293,27 +308,29 @@ Module OSM EndProcedure ;*** Converts coords to tile.decimal - Procedure LatLon2XY(*Location.Location, *Tile.Tile) + ;Warning, structures used in parameters are not tested + Procedure LatLon2XY(*Location.Location, *Coords.Position) Protected n.d = Pow(2.0, OSM\Zoom) Protected LatRad.d = Radian(*Location\Latitude) - *Tile\x = n * ( (*Location\Longitude + 180.0) / 360.0) - *Tile\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0 - ; Debug "Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude) - ; Debug "Tile X : " + Str(*Tile\x) + " ; Tile Y : " + Str(*Tile\y) + *Coords\x = n * ( (*Location\Longitude + 180.0) / 360.0) + *Coords\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0 + ; Debug "Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude) + ; Debug "Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y) EndProcedure ;*** Converts tile.decimal to coords - Procedure XY2LatLon(*Tile.Tile, *Location.Location) + ;Warning, structures used in parameters are not tested + Procedure XY2LatLon(*Coords.Position, *Location.Location) Protected n.d = Pow(2.0, OSM\Zoom) Protected LatitudeRad.d - *Location\Longitude = *Tile\x / n * 360.0 - 180.0 - LatitudeRad = ATan(SinH(#PI * (1.0 - 2.0 * *Tile\y / n))) + *Location\Longitude = *Coords\x / n * 360.0 - 180.0 + LatitudeRad = ATan(SinH(#PI * (1.0 - 2.0 * *Coords\y / n))) *Location\Latitude = Degree(LatitudeRad) EndProcedure ; HaversineAlgorithm ; http://andrew.hedges.name/experiments/haversine/ - Procedure.d HaversineInKM(*posA.Location,*posB.Location) + Procedure.d HaversineInKM(*posA.Location, *posB.Location) Protected eQuatorialEarthRadius.d = 6378.1370;6372.795477598; Protected dlong.d = (*posB\Longitude - *posA\Longitude); Protected dlat.d = (*posB\Latitude - *posA\Latitude) ; @@ -325,17 +342,15 @@ Module OSM ProcedureReturn distance ; EndProcedure - Procedure.d HaversineInM(*posA.Location,*posB.Location) + Procedure.d HaversineInM(*posA.Location, *posB.Location) ProcedureReturn (1000 * HaversineInKM(@*posA,@*posB)); EndProcedure - Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.Pixel) ; TODO to Optimize + + Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.PixelPosition) ; TODO to Optimize Protected mapWidth.l = Pow(2,OSM\Zoom+8) Protected mapHeight.l = Pow(2,OSM\Zoom+8) Protected x1.l,y1.l - - Protected deltaX = OSM\Position\x - Int(OSM\Drawing\x) * OSM\TileSize ;Get the position into the tile - Protected deltaY = OSM\Position\y - Int(OSM\Drawing\y) * OSM\TileSize - + ; get x value x1 = (*Location\Longitude+180)*(mapWidth/360) ; convert from degrees To radians @@ -353,8 +368,8 @@ Module OSM mercN = Log(Tan((#PI/4)+(latRad/2))) ; y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)); - *Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1) - deltaX - *Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1) - deltaY + *Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1) + *Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1) EndProcedure Procedure LoadGpxFile(file.s) @@ -391,13 +406,13 @@ Module OSM Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0") - ; Debug "Check if we have this image in memory" + ; Debug "Check if we have this image in memory" If FindMapElement(OSM\MemCache\Images(), key) - ; Debug "Key : " + key + " found !" + ; Debug "Key : " + key + " found !" ProcedureReturn OSM\MemCache\Images()\nImage Else - ; Debug "Key : " + key + " not found !" + ; Debug "Key : " + key + " not found !" ProcedureReturn -1 EndIf @@ -408,14 +423,14 @@ Module OSM Protected nImage.i Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" - ; Debug "Check if we have this image on HDD" + ; Debug "Check if we have this image on HDD" If FileSize(OSM\HDDCachePath + cacheFile) > 0 nImage = LoadImage(#PB_Any, OSM\HDDCachePath + CacheFile) If IsImage(nImage) - ; Debug "Load from HDD Tile " + CacheFile + ; Debug "Load from HDD Tile " + CacheFile ProcedureReturn nImage EndIf @@ -433,7 +448,7 @@ Module OSM Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" - ; Debug "Check if we have this image on Web" + ; Debug "Check if we have this image on Web" If Proxy ;LockMutex(OSM\CurlMutex) ;Seems no more necessary @@ -442,21 +457,21 @@ Module OSM Else *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous EndIf - ; Debug "Image buffer " + Str(*Buffer) + ; Debug "Image buffer " + Str(*Buffer) If *Buffer nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) If IsImage(nImage) - ; Debug "Load from web " + TileURL + " as Tile nb " + nImage + ; Debug "Load from web " + TileURL + " as Tile nb " + nImage SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG) FreeMemory(*Buffer) Else - ; Debug "Can't catch image " + TileURL + ; Debug "Can't catch image " + TileURL nImage = -1 ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) EndIf Else - ; Debug "Problem loading from web " + TileURL + ; Debug "Problem loading from web " + TileURL EndIf ProcedureReturn nImage @@ -476,10 +491,10 @@ Module OSM EndIf If nImage <> -1 OSM\MemCache\Images(key)\nImage = nImage - ; Debug "Image nb " + Str(nImage) + " successfully added to mem cache" - ; Debug "With the following key : " + key + ; Debug "Image nb " + Str(nImage) + " successfully added to mem cache" + ; Debug "With the following key : " + key Else - ; Debug "Error GetImageThread procedure, image not loaded - " + key + ; Debug "Error GetImageThread procedure, image not loaded - " + key nImage = -1 EndIf ;Define this tile image nb @@ -489,21 +504,16 @@ Module OSM Procedure DrawTile(*Tile.Tile) - Protected x = *Tile\x - Protected y = *Tile\y + Protected x = *Tile\Position\x + Protected y = *Tile\Position\y - ; Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) - ; Debug " at coords " + Str(x) + "," + Str(y) + ; Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) + ; Debug " at coords " + Str(x) + "," + Str(y) - If IsImage(*Tile\nImage) - MovePathCursor(x, y) - DrawVectorImage(ImageID(*Tile\nImage)) - MovePathCursor(x, y) - DrawVectorText(Str(x) + ", " + Str(y)) - Else - ; Debug "Image missing" - OSM\Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw - EndIf + MovePathCursor(x, y) + DrawVectorImage(ImageID(*Tile\nImage)) + MovePathCursor(x, y) + DrawVectorText(Str(x) + ", " + Str(y)) EndProcedure @@ -511,20 +521,13 @@ Module OSM Protected x.i, y.i - Protected tx = Int(*Drawing\x) ;Don't forget the Int() ! - Protected ty = Int(*Drawing\y) + Protected tx = Int(*Drawing\Position\x) ;Don't forget the Int() ! + Protected ty = Int(*Drawing\Position\y) - Protected CenterX = GadgetWidth(OSM\Gadget) / 2 - Protected CenterY = GadgetHeight(OSM\Gadget) / 2 + Protected nx = *Drawing\CenterX / OSM\TileSize ;How many tiles around the point + Protected ny = *Drawing\CenterY / OSM\TileSize - Protected nx = CenterX / OSM\TileSize ;How many tiles around the point - Protected ny = CenterY / OSM\TileSize - - ;Pixel shift, aka position in the tile - Protected DeltaX = *Drawing\x * OSM\TileSize - (tx * OSM\TileSize) - Protected DeltaY = *Drawing\y * OSM\TileSize - (ty * OSM\TileSize) - - ; Debug "Drawing tiles" + ; Debug "Drawing tiles" For y = - ny - 1 To ny + 1 For x = - nx - 1 To nx + 1 @@ -543,8 +546,8 @@ Module OSM OSM\TilesThreads()\Tile = *NewTile ;New tile parameters - \x = CenterX + x * OSM\TileSize - DeltaX - \y = CenterY + y * OSM\TileSize - DeltaY + \Position\x = *Drawing\CenterX + x * OSM\TileSize - *Drawing\DeltaX + \Position\y = *Drawing\CenterY + y * OSM\TileSize - *Drawing\DeltaY \OSMTileX = tx + x \OSMTileY = ty + y \OSMZoom = OSM\Zoom @@ -555,15 +558,20 @@ Module OSM ;If not, load it in the background \GetImageThread = CreateThread(@GetImageThread(), *NewTile) OSM\TilesThreads()\GetImageThread = \GetImageThread - ; Debug " Creating get image thread nb " + Str(\GetImageThread) + ; Debug " Creating get image thread nb " + Str(\GetImageThread) EndIf - DrawTile(*NewTile) + If IsImage(\nImage) + DrawTile(*NewTile) + Else + ; Debug "Image missing" + *Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw + EndIf EndWith Else - ; Debug" Error, can't create a new tile." + ; Debug" Error, can't create a new tile." Break 2 EndIf Next @@ -598,17 +606,15 @@ Module OSM Procedure DrawTrack(*Drawing.DrawingParameters) - Protected Pixel.Pixel + Protected Pixel.PixelPosition Protected Location.Location - - Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) - Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) + Protected km.f, memKm.i - + If ListSize(OSM\track())>0 - LockMutex(OSM\Drawing\Mutex) - ForEach OSM\track() + LockMutex(OSM\Drawing\Mutex) + ForEach OSM\track() ;-Test Distance If ListIndex(OSM\track())=0 Location\Latitude=OSM\track()\Latitude @@ -618,20 +624,20 @@ Module OSM Location\Latitude=OSM\track()\Latitude Location\Longitude=OSM\track()\Longitude EndIf - If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0 + If *Drawing\TargetLocation\Latitude<>0 And *Drawing\TargetLocation\Longitude<>0 GetPixelCoordFromLocation(@OSM\track(),@Pixel) If ListIndex(OSM\track())=0 - MovePathCursor(Pixel\X + DeltaX, Pixel\Y + DeltaY) + MovePathCursor(Pixel\X, Pixel\Y) Else - AddPathLine(Pixel\X + DeltaX, Pixel\Y + DeltaY) + AddPathLine(Pixel\X, Pixel\Y) If Int(km)<>memKm memKm=Int(km) If OSM\Zoom>10 - BeginVectorLayer() - VectorFont(FontID(OSM\Font), OSM\Zoom) - VectorSourceColor(RGBA(50, 50, 50, 255)) - DrawVectorText(Str(Int(km))) - EndVectorLayer() + BeginVectorLayer() + VectorFont(FontID(OSM\Font), OSM\Zoom) + VectorSourceColor(RGBA(50, 50, 50, 255)) + DrawVectorText(Str(Int(km))) + EndVectorLayer() EndIf EndIf @@ -639,7 +645,7 @@ Module OSM EndIf Next UnlockMutex(OSM\Drawing\Mutex) - + VectorSourceColor(RGBA(0, 255, 0, 150)) StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) @@ -647,7 +653,6 @@ Module OSM EndProcedure - ; Add a Marker To the Map Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1) AddElement(OSM\Marker()) @@ -659,60 +664,72 @@ Module OSM ; Draw all markers on the screen ! Procedure DrawMarker(*Drawing.DrawingParameters) - Protected Pixel.Pixel - - Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize) - Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) + Protected Pixel.PixelPosition ForEach OSM\Marker() If OSM\Marker()\Location\Latitude <> 0 And OSM\Marker()\Location\Longitude <> 0 GetPixelCoordFromLocation(OSM\Marker()\Location, @Pixel) - If Pixel\X + DeltaX > 0 And Pixel\Y + DeltaY > 0 And Pixel\X + DeltaX < GadgetWidth(OSM\Gadget) And Pixel\Y < GadgetHeight(OSM\Gadget) ; Only if visible ^_^ + If Pixel\X > 0 And Pixel\Y > 0 And Pixel\X < GadgetWidth(OSM\Gadget) And Pixel\Y < GadgetHeight(OSM\Gadget) ; Only if visible ^_^ If OSM\Marker()\CallBackPointer > 0 - CallFunctionFast(OSM\Marker()\CallBackPointer, Pixel\X + DeltaX, Pixel\Y + DeltaY) + CallFunctionFast(OSM\Marker()\CallBackPointer, Pixel\X, Pixel\Y) Else - Pointer(Pixel\X + DeltaX, Pixel\Y + DeltaY, OSM\Marker()\color) + Pointer(Pixel\X, Pixel\Y, OSM\Marker()\color) EndIf EndIf EndIf Next + EndProcedure - Procedure DrawingThread(*Drawing.DrawingParameters) + Procedure DrawingThread(*SharedDrawing.DrawingParameters) + + Protected Drawing.DrawingParameters + Protected Px.d, Py.d Repeat - WaitSemaphore(*Drawing\Semaphore) + WaitSemaphore(*SharedDrawing\Semaphore) - ; Debug "--------- Main drawing thread ------------" + ; Debug "--------- Main drawing thread ------------" - Protected CenterX = GadgetWidth(OSM\Gadget) / 2 - Protected CenterY = GadgetHeight(OSM\Gadget) / 2 + ;Creates a copy of the structure to work with, and precalculus some values + LockMutex(*SharedDrawing\Mutex) + CopyStructure(*SharedDrawing, @Drawing, DrawingParameters) + UnlockMutex(*SharedDrawing\Mutex) - *Drawing\Dirty = #False + Drawing\CenterX = GadgetWidth(OSM\Gadget) / 2 + Drawing\CenterY = GadgetHeight(OSM\Gadget) / 2 + ;Pixel shift, aka position in the tile + Px = Drawing\Position\x : Py = Drawing\Position\y + Drawing\DeltaX = Px * OSM\TileSize - (Int(Px) * OSM\TileSize) ;Don't forget the Int() ! + Drawing\DeltaY = Py * OSM\TileSize - (Int(Py) * OSM\TileSize) + Drawing\TargetLocation\Latitude = OSM\TargetLocation\Latitude + Drawing\TargetLocation\Longitude = OSM\TargetLocation\Longitude + + Drawing\Dirty = #False StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) - DrawTiles(*Drawing) - DrawTrack(*Drawing) - DrawMarker(*Drawing) - Pointer(CenterX, CenterY, #Red) + DrawTiles(@Drawing) + DrawTrack(@Drawing) + DrawMarker(@Drawing) + Pointer(Drawing\CenterX, Drawing\CenterY, #Red) StopVectorDrawing() ;- Redraw ;If something was not correctly drawn, redraw after a while - LockMutex(OSM\Drawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore) - If *Drawing\Dirty - ; Debug "Something was dirty ! We try again to redraw" + LockMutex(*SharedDrawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore) + If Drawing\Dirty + ; Debug "Something was dirty ! We try again to redraw" ;Delay(250) - *Drawing\PassNb + 1 - SignalSemaphore(*Drawing\Semaphore) + Drawing\PassNb + 1 + SignalSemaphore(*SharedDrawing\Semaphore) Else ;Clean the semaphore to avoid multiple unuseful redraws - Repeat : Until TrySemaphore(*Drawing\Semaphore) = 0 + Repeat : Until TrySemaphore(*SharedDrawing\Semaphore) = 0 EndIf - UnlockMutex(OSM\Drawing\Mutex) + UnlockMutex(*SharedDrawing\Mutex) - Until *Drawing\End + Until Drawing\End EndProcedure @@ -728,8 +745,8 @@ Module OSM LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) ;Convert X, Y in tile.decimal into real pixels - OSM\Position\X = OSM\Drawing\x * OSM\TileSize - OSM\Position\Y = OSM\Drawing\y * OSM\TileSize + OSM\Position\x = OSM\Drawing\Position\x * OSM\TileSize + OSM\Position\y = OSM\Drawing\Position\y * OSM\TileSize OSM\Drawing\PassNb = 1 ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) @@ -800,8 +817,8 @@ Module OSM LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) ;Convert X, Y in tile.decimal into real pixels - OSM\Position\X = OSM\Drawing\x * OSM\TileSize - OSM\Position\Y = OSM\Drawing\y * OSM\TileSize + OSM\Position\X = OSM\Drawing\Position\x * OSM\TileSize + OSM\Position\Y = OSM\Drawing\Position\y * OSM\TileSize ;*** Creates a drawing thread and fill parameters OSM\Drawing\PassNb = 1 ;Start drawing @@ -818,8 +835,7 @@ Module OSM Protected Gadget.i Protected MouseX.i, MouseY.i - Protected OldX.i, OldY.i - Protected DeltaX.d, DeltaY.d + Protected Marker.Position Protected *Drawing.DrawingParameters If IsGadget(OSM\Gadget) And GadgetType(OSM\Gadget) = #PB_GadgetType_Canvas @@ -831,17 +847,16 @@ Module OSM Select EventType() Case #PB_EventType_LeftButtonDown ;Check if we select a marker - Protected Pixel.Pixel - ForEach OSM\Marker() - GetPixelCoordFromLocation(@OSM\Marker()\Location, @Pixel) - ;LockMutex(OSM\Drawing\Mutex) - DeltaX = OSM\Drawing\x * OSM\TileSize - (Int(OSM\Drawing\x) * OSM\TileSize) - DeltaY = OSM\Drawing\y * OSM\TileSize - (Int(OSM\Drawing\y) * OSM\TileSize) - ;UnlockMutex(OSM\Drawing\Mutex) - If Pixel\X + DeltaX > GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - 4 And Pixel\X + DeltaX < GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) + 4 And Pixel\Y + DeltaY > GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - 4 And Pixel\Y + DeltaY < GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) + 4 + MouseX = OSM\Position\x - GadgetWidth(OSM\Gadget) / 2 + GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) + MouseY = OSM\Position\y - GadgetHeight(OSM\Gadget) / 2 + GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) + ForEach OSM\Marker() + LatLon2XY(@OSM\Marker()\Location, @Marker) + Marker\x * OSM\TileSize + Marker\y * OSM\TileSize + If Distance(Marker\x, Marker\y, MouseX, MouseY) < 8 OSM\EditMarkerIndex = ListIndex(OSM\Marker()) Break - EndIf + EndIf Next ;Mem cursor Coord OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) @@ -855,30 +870,26 @@ Module OSM If OSM\EditMarkerIndex > -1 SelectElement(OSM\Marker(), OSM\EditMarkerIndex) Protected Tile.Tile - LatLon2XY(@OSM\Marker()\Location, @Tile) - ; Debug MouseX - Tile\x + MouseX / OSM\TileSize - Tile\y + MouseY / OSM\TileSize - XY2LatLon(@Tile, @OSM\Marker()\Location) + LatLon2XY(@OSM\Marker()\Location, @Marker) + Marker\x + MouseX / OSM\TileSize + Marker\y + MouseY / OSM\TileSize + XY2LatLon(@Marker, @OSM\Marker()\Location) Else ;New move values OSM\Position\x - MouseX OSM\Position\y - MouseY ;-*** Fill parameters and signal the drawing thread - ;OSM tile position in tile.decimal LockMutex(OSM\Drawing\Mutex) - OSM\Drawing\x = OSM\Position\x / OSM\TileSize - OSM\Drawing\y = OSM\Position\y / OSM\TileSize + ;OSM tile position in tile.decimal + OSM\Drawing\Position\x = OSM\Position\x / OSM\TileSize + OSM\Drawing\Position\y = OSM\Position\y / OSM\TileSize OSM\Drawing\PassNb = 1 - UnlockMutex(OSM\Drawing\Mutex) - ;Moved to a new tile ? - ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) - ;EndIf ;If CallBackLocation send Location to function If OSM\CallBackLocation > 0 CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) EndIf + UnlockMutex(OSM\Drawing\Mutex) EndIf ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) @@ -892,12 +903,14 @@ Module OSM If OSM\EditMarkerIndex > -1 OSM\EditMarkerIndex = -1 Else ;Move Map - OSM\Drawing\x = OSM\Position\x / OSM\TileSize - OSM\Drawing\y = OSM\Position\y / OSM\TileSize - ; Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) + LockMutex(OSM\Drawing\Mutex) + OSM\Drawing\Position\x = OSM\Position\x / OSM\TileSize + OSM\Drawing\Position\y = OSM\Position\y / OSM\TileSize + ; Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) + UnlockMutex(OSM\Drawing\Mutex) ;Draw() - ; Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) + ; Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) ;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude)) ;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude)) EndIf @@ -1042,8 +1055,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 605 -; FirstLine = 598 +; CursorPosition = 697 +; FirstLine = 683 ; Folding = ------- ; EnableUnicode ; EnableThread From d1d24f223cf3ca3c51fb6cc4c656045749f55688 Mon Sep 17 00:00:00 2001 From: djes Date: Fri, 29 Jul 2016 13:44:04 +0200 Subject: [PATCH 24/35] Lil Cleaning --- osm.pb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/osm.pb b/osm.pb index 0a0eeb2..a635ef2 100644 --- a/osm.pb +++ b/osm.pb @@ -669,7 +669,7 @@ Module OSM ForEach OSM\Marker() If OSM\Marker()\Location\Latitude <> 0 And OSM\Marker()\Location\Longitude <> 0 GetPixelCoordFromLocation(OSM\Marker()\Location, @Pixel) - If Pixel\X > 0 And Pixel\Y > 0 And Pixel\X < GadgetWidth(OSM\Gadget) And Pixel\Y < GadgetHeight(OSM\Gadget) ; Only if visible ^_^ + If Pixel\X >= 0 And Pixel\Y >= 0 And Pixel\X < GadgetWidth(OSM\Gadget) And Pixel\Y < GadgetHeight(OSM\Gadget) ; Only if visible ^_^ If OSM\Marker()\CallBackPointer > 0 CallFunctionFast(OSM\Marker()\CallBackPointer, Pixel\X, Pixel\Y) Else @@ -869,7 +869,6 @@ Module OSM ;move Marker If OSM\EditMarkerIndex > -1 SelectElement(OSM\Marker(), OSM\EditMarkerIndex) - Protected Tile.Tile LatLon2XY(@OSM\Marker()\Location, @Marker) Marker\x + MouseX / OSM\TileSize Marker\y + MouseY / OSM\TileSize @@ -1055,8 +1054,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 697 -; FirstLine = 683 +; CursorPosition = 883 +; FirstLine = 869 ; Folding = ------- ; EnableUnicode ; EnableThread From 38f82378c2fa636c028bc5875cd1286e0031b233 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 1 Aug 2016 16:25:58 +0200 Subject: [PATCH 25/35] curl fix --- libcurl.pbi | 17 +++++++++++------ osm.pb | 27 ++++++++++++++------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/libcurl.pbi b/libcurl.pbi index 857542a..3c58846 100644 --- a/libcurl.pbi +++ b/libcurl.pbi @@ -1049,19 +1049,24 @@ Procedure.s curlGetData() EndProcedure Procedure.s str2curl(string.s) - Protected *curlstring - If *curlstring : FreeMemory(*curlstring) : EndIf + Protected *curlstring, newstring.s *curlstring = AllocateMemory(Len(string) + 1) - PokeS(*curlstring,string,-1,#PB_Ascii) - ProcedureReturn PeekS(*curlstring,-1) + If *curlstring + PokeS(*curlstring,string,-1,#PB_Ascii) + newstring = PeekS(*curlstring,-1) + FreeMemory(*curlstring) + ProcedureReturn newstring + Else + ProcedureReturn "" + EndIf EndProcedure ; IDE Options = PureBasic 5.40 LTS Beta 5 (Windows - x86) ; EnableUnicode ; EnableXP ; EnableBuildCount = 0 ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 1041 -; FirstLine = 1003 +; CursorPosition = 1057 +; FirstLine = 1008 ; Folding = -- ; EnableUnicode ; EnableXP \ No newline at end of file diff --git a/osm.pb b/osm.pb index a635ef2..7c8862e 100644 --- a/osm.pb +++ b/osm.pb @@ -122,7 +122,8 @@ Module OSM Moving.i Dirty.i ;To signal that drawing need a refresh - ;CurlMutex.i ;seems that I can't thread curl ! :((((( + CurlMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :((((( + List TilesThreads.TileThread() List track.Location() ;to display a GPX track @@ -242,7 +243,7 @@ Module OSM OSM\ZoomMax = 18 OSM\MoveStartingPoint\x = - 1 OSM\TileSize = 256 - ;OSM\CurlMutex = CreateMutex() + OSM\CurlMutex = CreateMutex() OSM\Dirty = #False OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Semaphore = CreateSemaphore() @@ -250,7 +251,7 @@ Module OSM OSM\Font=LoadFont(#PB_Any, "Comic Sans MS", 20, #PB_Font_Bold) ;- Proxy details - Global Proxy = #False + Global Proxy = #True ;Use this to customize your preferences ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") @@ -448,30 +449,30 @@ Module OSM Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" - ; Debug "Check if we have this image on Web" + Debug "Check if we have this image on Web" If Proxy - ;LockMutex(OSM\CurlMutex) ;Seems no more necessary + LockMutex(OSM\CurlMutex) ;Seems no more necessary *Buffer = CurlReceiveHTTPToMemory(TileURL, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) - ;UnlockMutex(OSM\CurlMutex) + UnlockMutex(OSM\CurlMutex) Else *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous EndIf - ; Debug "Image buffer " + Str(*Buffer) + Debug "Image buffer " + Str(*Buffer) If *Buffer nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) If IsImage(nImage) - ; Debug "Load from web " + TileURL + " as Tile nb " + nImage + Debug "Load from web " + TileURL + " as Tile nb " + nImage SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG) FreeMemory(*Buffer) Else - ; Debug "Can't catch image " + TileURL + Debug "Can't catch image " + TileURL nImage = -1 ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) EndIf Else - ; Debug "Problem loading from web " + TileURL + Debug "Problem loading from web " + TileURL EndIf ProcedureReturn nImage @@ -1053,9 +1054,9 @@ CompilerIf #PB_Compiler_IsMainFile EndIf CompilerEndIf -; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 883 -; FirstLine = 869 +; IDE Options = PureBasic 5.42 LTS (Windows - x86) +; CursorPosition = 245 +; FirstLine = 235 ; Folding = ------- ; EnableUnicode ; EnableThread From c31a131d2903414989565bd17bc1ae76bdae1bc1 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 1 Aug 2016 17:35:05 +0200 Subject: [PATCH 26/35] Curl fix Need to work on mutex (maybe with http://forum.purebasic.com/english/viewtopic.php?f=13&t=61006) --- osm.pb | 56 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/osm.pb b/osm.pb index 7c8862e..a5908bc 100644 --- a/osm.pb +++ b/osm.pb @@ -30,6 +30,8 @@ DeclareModule OSM Declare SetCallBackLocation(*CallBackLocation) Declare LoadGpxFile(file.s); Declare AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1) + Declare Quit() + Declare Error(msg.s) EndDeclareModule Module OSM @@ -124,6 +126,7 @@ Module OSM Dirty.i ;To signal that drawing need a refresh CurlMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :((((( + MainDrawingThread.i List TilesThreads.TileThread() List track.Location() ;to display a GPX track @@ -133,6 +136,10 @@ Module OSM Global OSM.OSM, Null.i + Procedure Error(msg.s) + Debug msg, 2 + EndProcedure + ;- *** CURL specific *** Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s @@ -146,13 +153,13 @@ Module OSM If *ReceiveHTTPToMemoryBuffer = 0 *ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper) If *ReceiveHTTPToMemoryBuffer = 0 - ; Debug "Problem allocating memory" + Debug "Problem allocating memory" End EndIf Else *ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper) If *ReceiveHTTPToMemoryBuffer = 0 - ; Debug "Problem reallocating memory" + Debug "Problem reallocating memory" End EndIf EndIf @@ -171,7 +178,7 @@ Module OSM ;Debug "ReceiveHTTPToMemory" + URL$ + ProxyURL$ + ProxyPort$ + ProxyUser$ + ProxyPassword$ If Len(URL$) - + curl = curl_easy_init() If curl @@ -181,7 +188,8 @@ Module OSM curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$)) curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0) curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0) - curl_easy_setopt(curl, #CURLOPT_HEADER, 0) + curl_easy_setopt(curl, #CURLOPT_HEADER, 0) + curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1) curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout) If Len(ProxyURL$) @@ -201,9 +209,12 @@ Module OSM EndIf curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction()) + LockMutex(OSM\CurlMutex) res = curl_easy_perform(curl) - + UnlockMutex(OSM\CurlMutex) + If res = #CURLE_OK + *Buffer = AllocateMemory(ReceiveHTTPToMemoryBufferPtr) If *Buffer CopyMemory(*ReceiveHTTPToMemoryBuffer, *Buffer, ReceiveHTTPToMemoryBufferPtr) @@ -278,13 +289,34 @@ Module OSM ClosePreferences() EndIf - curl_global_init(#CURL_GLOBAL_ALL); + curl_global_init(#CURL_GLOBAL_WIN32); ;- Main drawing thread launching - CreateThread(@DrawingThread(), @OSM\Drawing) + OSM\MainDrawingThread = CreateThread(@DrawingThread(), @OSM\Drawing) + If OSM\MainDrawingThread = 0 + Error("MapGadget : Can't create main drawing thread") + End + EndIf EndProcedure + Procedure Quit() + ;kill main drawing thread + KillThread(OSM\MainDrawingThread) + + ;wait for loading threads to finish nicely + ResetList( OSM\TilesThreads()) + While NextElement(OSM\TilesThreads()) + If IsThread(OSM\TilesThreads()\GetImageThread) = 0 + FreeMemory(OSM\TilesThreads()\Tile) + DeleteElement(OSM\TilesThreads()) + ResetList( OSM\TilesThreads()) + EndIf + Wend + + curl_global_cleanup() + EndProcedure + Macro Min(a,b) (Bool((a) <= (b)) * (a) + Bool((b) < (a)) * (b)) EndMacro @@ -452,9 +484,9 @@ Module OSM Debug "Check if we have this image on Web" If Proxy - LockMutex(OSM\CurlMutex) ;Seems no more necessary + ;LockMutex(OSM\CurlMutex) *Buffer = CurlReceiveHTTPToMemory(TileURL, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) - UnlockMutex(OSM\CurlMutex) + ;UnlockMutex(OSM\CurlMutex) Else *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous EndIf @@ -1051,12 +1083,14 @@ CompilerIf #PB_Compiler_IsMainFile ResizeAll() EndSelect Until Quit = #True + + OSM::Quit() EndIf CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 245 -; FirstLine = 235 +; CursorPosition = 213 +; FirstLine = 188 ; Folding = ------- ; EnableUnicode ; EnableThread From 8505e67974d5b76998c534d484a61117271bbba3 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 1 Aug 2016 17:48:47 +0200 Subject: [PATCH 27/35] curl fix --- osm.pb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osm.pb b/osm.pb index a5908bc..c86b619 100644 --- a/osm.pb +++ b/osm.pb @@ -208,6 +208,7 @@ Module OSM EndIf EndIf + ;TODO improve with https://github.com/Progi1984/RWrappers/tree/master/LibCurl curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction()) LockMutex(OSM\CurlMutex) res = curl_easy_perform(curl) @@ -1089,7 +1090,7 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 213 +; CursorPosition = 211 ; FirstLine = 188 ; Folding = ------- ; EnableUnicode From 767472053d89612d036c512d4ef4c9b2acfadc5a Mon Sep 17 00:00:00 2001 From: djes Date: Tue, 2 Aug 2016 14:25:31 +0200 Subject: [PATCH 28/35] Curl fix --- libcurl.pbi | 42 ++++---- osm.pb | 268 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 195 insertions(+), 115 deletions(-) diff --git a/libcurl.pbi b/libcurl.pbi index 3c58846..a76dc45 100644 --- a/libcurl.pbi +++ b/libcurl.pbi @@ -1026,27 +1026,27 @@ CompilerIf #PB_Compiler_OS = #PB_OS_Windows EndImport CompilerEndIf -ProcedureC curlWriteData(*ptr, Size, NMemB, *Stream) - ;retreives utf-8/ascii encoded data - Protected SizeProper.i = Size & 255 - Protected NMemBProper.i = NMemB - Protected MyDataS.s - ;Shared ReceivedData.s - - MyDataS = PeekS(*ptr, SizeProper * NMemBProper, #PB_UTF8) - ReceivedData + MyDataS - ProcedureReturn SizeProper * NMemBProper -EndProcedure +; ProcedureC curlWriteData(*ptr, Size, NMemB, *Stream) +; ;retreives utf-8/ascii encoded data +; Protected SizeProper.i = Size & 255 +; Protected NMemBProper.i = NMemB +; Protected MyDataS.s +; ;Shared ReceivedData.s +; +; MyDataS = PeekS(*ptr, SizeProper * NMemBProper, #PB_UTF8) +; ReceivedData + MyDataS +; ProcedureReturn SizeProper * NMemBProper +; EndProcedure -Procedure.s curlGetData() - ;Shared ReceivedData.s - Protected ReturnData.s - - ReturnData.s = ReceivedData.s - ReceivedData.s = "" - - ProcedureReturn ReturnData.s -EndProcedure +; Procedure.s curlGetData() +; ;Shared ReceivedData.s +; Protected ReturnData.s +; +; ReturnData.s = ReceivedData.s +; ReceivedData.s = "" +; +; ProcedureReturn ReturnData.s +; EndProcedure Procedure.s str2curl(string.s) Protected *curlstring, newstring.s @@ -1065,7 +1065,7 @@ EndProcedure ; EnableXP ; EnableBuildCount = 0 ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 1057 +; CursorPosition = 1048 ; FirstLine = 1008 ; Folding = -- ; EnableUnicode diff --git a/osm.pb b/osm.pb index c86b619..559d5cc 100644 --- a/osm.pb +++ b/osm.pb @@ -16,6 +16,7 @@ CompilerEndIf EnableExplicit InitNetwork() +OpenConsole() UsePNGImageDecoder() UsePNGImageEncoder() @@ -124,7 +125,7 @@ Module OSM Moving.i Dirty.i ;To signal that drawing need a refresh - CurlMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :((((( + ;CurlMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :((((( MainDrawingThread.i List TilesThreads.TileThread() @@ -142,55 +143,140 @@ Module OSM ;- *** CURL specific *** - Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s - IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl +; Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s + IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl +; +; ProcedureC ReceiveHTTPWriteToMemoryFunction(*ptr, Size.i, NMemB.i, *Stream) +; +; Protected SizeProper.i = Size & 255 +; Protected NMemBProper.i = NMemB +; +; If *ReceiveHTTPToMemoryBuffer = 0 +; *ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper) +; If *ReceiveHTTPToMemoryBuffer = 0 +; Debug "Problem allocating memory" +; End +; EndIf +; Else +; *ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper) +; If *ReceiveHTTPToMemoryBuffer = 0 +; Debug "Problem reallocating memory" +; End +; EndIf +; EndIf +; +; CopyMemory(*ptr, *ReceiveHTTPToMemoryBuffer + ReceiveHTTPToMemoryBufferPtr, SizeProper * NMemBProper) +; ReceiveHTTPToMemoryBufferPtr + SizeProper * NMemBProper +; +; ProcedureReturn SizeProper * NMemBProper +; +; EndProcedure +; +; Procedure.i CurlReceiveHTTPToMemory(URL$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="") +; +; Protected *Buffer, curl.i, Timeout.i, res.i +; +; ;Debug "ReceiveHTTPToMemory" + URL$ + ProxyURL$ + ProxyPort$ + ProxyUser$ + ProxyPassword$ +; +; If Len(URL$) +; +; curl = curl_easy_init() +; +; If curl +; +; Timeout = 3 +; +; curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$)) +; curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0) +; curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0) +; curl_easy_setopt(curl, #CURLOPT_HEADER, 0) +; curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1) +; curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout) +; +; If Len(ProxyURL$) +; ;curl_easy_setopt(curl, #CURLOPT_HTTPPROXYTUNNEL, #True) +; If Len(ProxyPort$) +; ProxyURL$ + ":" + ProxyPort$ +; EndIf +; ; Debug ProxyURL$ +; curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$)) +; If Len(ProxyUser$) +; If Len(ProxyPassword$) +; ProxyUser$ + ":" + ProxyPassword$ +; EndIf +; ;Debug ProxyUser$ +; curl_easy_setopt(curl, #CURLOPT_PROXYUSERPWD, str2curl(ProxyUser$)) +; EndIf +; EndIf +; +; ;TODO improve with https://github.com/Progi1984/RWrappers/tree/master/LibCurl +; curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction()) +; LockMutex(OSM\CurlMutex) +; res = curl_easy_perform(curl) +; UnlockMutex(OSM\CurlMutex) +; +; If res = #CURLE_OK +; +; *Buffer = AllocateMemory(ReceiveHTTPToMemoryBufferPtr) +; If *Buffer +; CopyMemory(*ReceiveHTTPToMemoryBuffer, *Buffer, ReceiveHTTPToMemoryBufferPtr) +; FreeMemory(*ReceiveHTTPToMemoryBuffer) +; *ReceiveHTTPToMemoryBuffer = #Null +; ReceiveHTTPToMemoryBufferPtr = 0 +; Else +; ; Debug "Problem allocating buffer" +; EndIf +; ;curl_easy_cleanup(curl) ;Was its original place but moved below as it seems more logical to me. +; Else +; ; Debug "CURL NOT OK" +; EndIf +; +; curl_easy_cleanup(curl) +; +; Else +; ; Debug "Can't Init CURL" +; EndIf +; +; EndIf +; +; ; Debug "Curl Buffer : " + Str(*Buffer) +; +; ProcedureReturn *Buffer +; +; EndProcedure - ProcedureC ReceiveHTTPWriteToMemoryFunction(*ptr, Size.i, NMemB.i, *Stream) - - Protected SizeProper.i = Size & 255 - Protected NMemBProper.i = NMemB - - If *ReceiveHTTPToMemoryBuffer = 0 - *ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper) - If *ReceiveHTTPToMemoryBuffer = 0 - Debug "Problem allocating memory" - End - EndIf - Else - *ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper) - If *ReceiveHTTPToMemoryBuffer = 0 - Debug "Problem reallocating memory" - End - EndIf - EndIf - - CopyMemory(*ptr, *ReceiveHTTPToMemoryBuffer + ReceiveHTTPToMemoryBufferPtr, SizeProper * NMemBProper) - ReceiveHTTPToMemoryBufferPtr + SizeProper * NMemBProper - - ProcedureReturn SizeProper * NMemBProper + ProcedureC ReceiveHTTPWriteToFileFunction(*ptr, Size.i, NMemB.i, FileHandle.i) + + ProcedureReturn WriteData(FileHandle, *ptr, Size * NMemB) EndProcedure - Procedure.i CurlReceiveHTTPToMemory(URL$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="") + Procedure.i CurlReceiveHTTPToFile(URL$, DestFileName$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="") Protected *Buffer, curl.i, Timeout.i, res.i + Protected FileHandle.i - ;Debug "ReceiveHTTPToMemory" + URL$ + ProxyURL$ + ProxyPort$ + ProxyUser$ + ProxyPassword$ + Debug "ReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + ProxyPort$ + ProxyUser$ + Debug " to file : " + DestFileName$ - If Len(URL$) - + FileHandle = CreateFile(#PB_Any, DestFileName$) + + If FileHandle And Len(URL$) + curl = curl_easy_init() If curl - Timeout = 3 + Timeout = 120 curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$)) curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0) curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0) curl_easy_setopt(curl, #CURLOPT_HEADER, 0) curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1) - curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout) + curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout) + curl_easy_setopt(curl, #CURLOPT_VERBOSE, 1) + curl_easy_setopt(curl, #CURLOPT_CONNECTTIMEOUT, 0) If Len(ProxyURL$) ;curl_easy_setopt(curl, #CURLOPT_HTTPPROXYTUNNEL, #True) @@ -208,41 +294,30 @@ Module OSM EndIf EndIf - ;TODO improve with https://github.com/Progi1984/RWrappers/tree/master/LibCurl - curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction()) - LockMutex(OSM\CurlMutex) + curl_easy_setopt(curl, #CURLOPT_WRITEDATA, FileHandle) + curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToFileFunction()) + ;LockMutex(OSM\CurlMutex) ;Not any more necessary res = curl_easy_perform(curl) - UnlockMutex(OSM\CurlMutex) - - If res = #CURLE_OK - - *Buffer = AllocateMemory(ReceiveHTTPToMemoryBufferPtr) - If *Buffer - CopyMemory(*ReceiveHTTPToMemoryBuffer, *Buffer, ReceiveHTTPToMemoryBufferPtr) - FreeMemory(*ReceiveHTTPToMemoryBuffer) - *ReceiveHTTPToMemoryBuffer = #Null - ReceiveHTTPToMemoryBufferPtr = 0 - Else - ; Debug "Problem allocating buffer" - EndIf - ;curl_easy_cleanup(curl) ;Was its original place but moved below as it seems more logical to me. - Else - ; Debug "CURL NOT OK" + ;UnlockMutex(OSM\CurlMutex) + If res <> #CURLE_OK + Debug "CURL NOT OK" EndIf curl_easy_cleanup(curl) Else - ; Debug "Can't Init CURL" + Debug "Can't Init CURL" EndIf + CloseFile(FileHandle) + ProcedureReturn FileSize(DestFileName$) + EndIf - ; Debug "Curl Buffer : " + Str(*Buffer) - - ProcedureReturn *Buffer + ProcedureReturn #False EndProcedure + ;- *** Procedure InitOSM() @@ -255,7 +330,7 @@ Module OSM OSM\ZoomMax = 18 OSM\MoveStartingPoint\x = - 1 OSM\TileSize = 256 - OSM\CurlMutex = CreateMutex() + ;OSM\CurlMutex = CreateMutex() OSM\Dirty = #False OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Semaphore = CreateSemaphore() @@ -384,7 +459,7 @@ Module OSM Protected mapWidth.l = Pow(2,OSM\Zoom+8) Protected mapHeight.l = Pow(2,OSM\Zoom+8) Protected x1.l,y1.l - + ; get x value x1 = (*Location\Longitude+180)*(mapWidth/360) ; convert from degrees To radians @@ -452,61 +527,64 @@ Module OSM EndProcedure - Procedure.i GetTileFromHDD(Zoom.i, XTile.i, YTile.i) + Procedure.i GetTileFromHDD(CacheFile.s) Protected nImage.i - Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" - - ; Debug "Check if we have this image on HDD" - - If FileSize(OSM\HDDCachePath + cacheFile) > 0 + + If FileSize(CacheFile) > 0 - nImage = LoadImage(#PB_Any, OSM\HDDCachePath + CacheFile) + nImage = LoadImage(#PB_Any, CacheFile) If IsImage(nImage) - ; Debug "Load from HDD Tile " + CacheFile - ProcedureReturn nImage - EndIf + Debug "Loadimage " + CacheFile + " -> Success !" + ProcedureReturn nImage + EndIf EndIf + Debug "Loadimage " + CacheFile + " -> Failed !" + ProcedureReturn -1 EndProcedure - Procedure.i GetTileFromWeb(Zoom.i, XTile.i, YTile.i) + Procedure.i GetTileFromWeb(Zoom.i, XTile.i, YTile.i, CacheFile.s) Protected *Buffer Protected nImage.i = -1 + Protected FileHandle.i Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" - Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" + ; Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" - Debug "Check if we have this image on Web" + Debug "Check if we have this image on Web" If Proxy - ;LockMutex(OSM\CurlMutex) - *Buffer = CurlReceiveHTTPToMemory(TileURL, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) - ;UnlockMutex(OSM\CurlMutex) - Else - *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous - EndIf - Debug "Image buffer " + Str(*Buffer) - - If *Buffer - nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) - If IsImage(nImage) - Debug "Load from web " + TileURL + " as Tile nb " + nImage - SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG) - FreeMemory(*Buffer) + ;*Buffer = CurlReceiveHTTPToMemory(TileURL, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) + FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) + If FileHandle + nImage = GetTileFromHDD(CacheFile) Else - Debug "Can't catch image " + TileURL - nImage = -1 - ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) + Debug "File " + TileURL + " not correctly received with Curl and proxy" EndIf Else - Debug "Problem loading from web " + TileURL - EndIf + *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous + + If *Buffer + nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) + If IsImage(nImage) + Debug "Load from web " + TileURL + " as Tile nb " + nImage + SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG) + FreeMemory(*Buffer) + Else + Debug "Can't catch image " + TileURL + nImage = -1 + ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) + EndIf + Else + Debug "ReceiveHTTPMemory's buffer is empty" + EndIf + EndIf ProcedureReturn nImage @@ -516,12 +594,13 @@ Module OSM Protected nImage.i = -1 Protected key.s = "Z" + RSet(Str(*Tile\OSMZoom), 4, "0") + "X" + RSet(Str(*Tile\OSMTileX), 8, "0") + "Y" + RSet(Str(*Tile\OSMTileY), 8, "0") + Protected CacheFile.s = OSM\HDDCachePath + "OSM_" + Str(*Tile\OSMZoom) + "_" + Str(*Tile\OSMTileX) + "_" + Str(*Tile\OSMTileY) + ".png" ;Adding the image to the cache if possible AddMapElement(OSM\MemCache\Images(), key) - nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) + nImage = GetTileFromHDD(CacheFile) If nImage = -1 - nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) + nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY, CacheFile) EndIf If nImage <> -1 OSM\MemCache\Images(key)\nImage = nImage @@ -712,7 +791,7 @@ Module OSM EndIf EndIf Next - + EndProcedure Procedure DrawingThread(*SharedDrawing.DrawingParameters) @@ -1090,8 +1169,9 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 211 -; FirstLine = 188 +; ExecutableFormat = Console +; CursorPosition = 146 +; FirstLine = 117 ; Folding = ------- ; EnableUnicode ; EnableThread From 1806be17b01e20f0e611972128f4b8f30d0dcead Mon Sep 17 00:00:00 2001 From: djes Date: Tue, 2 Aug 2016 14:41:11 +0200 Subject: [PATCH 29/35] Code cleaning --- libcurl.pbi | 6 ++- osm.pb | 143 ++++++---------------------------------------------- 2 files changed, 19 insertions(+), 130 deletions(-) diff --git a/libcurl.pbi b/libcurl.pbi index a76dc45..0feb7dc 100644 --- a/libcurl.pbi +++ b/libcurl.pbi @@ -1060,13 +1060,15 @@ Procedure.s str2curl(string.s) ProcedureReturn "" EndIf EndProcedure + + ; IDE Options = PureBasic 5.40 LTS Beta 5 (Windows - x86) ; EnableUnicode ; EnableXP ; EnableBuildCount = 0 ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 1048 -; FirstLine = 1008 +; CursorPosition = 1031 +; FirstLine = 986 ; Folding = -- ; EnableUnicode ; EnableXP \ No newline at end of file diff --git a/osm.pb b/osm.pb index 559d5cc..b6f159b 100644 --- a/osm.pb +++ b/osm.pb @@ -125,7 +125,6 @@ Module OSM Moving.i Dirty.i ;To signal that drawing need a refresh - ;CurlMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :((((( MainDrawingThread.i List TilesThreads.TileThread() @@ -143,107 +142,7 @@ Module OSM ;- *** CURL specific *** -; Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl -; -; ProcedureC ReceiveHTTPWriteToMemoryFunction(*ptr, Size.i, NMemB.i, *Stream) -; -; Protected SizeProper.i = Size & 255 -; Protected NMemBProper.i = NMemB -; -; If *ReceiveHTTPToMemoryBuffer = 0 -; *ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper) -; If *ReceiveHTTPToMemoryBuffer = 0 -; Debug "Problem allocating memory" -; End -; EndIf -; Else -; *ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper) -; If *ReceiveHTTPToMemoryBuffer = 0 -; Debug "Problem reallocating memory" -; End -; EndIf -; EndIf -; -; CopyMemory(*ptr, *ReceiveHTTPToMemoryBuffer + ReceiveHTTPToMemoryBufferPtr, SizeProper * NMemBProper) -; ReceiveHTTPToMemoryBufferPtr + SizeProper * NMemBProper -; -; ProcedureReturn SizeProper * NMemBProper -; -; EndProcedure -; -; Procedure.i CurlReceiveHTTPToMemory(URL$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="") -; -; Protected *Buffer, curl.i, Timeout.i, res.i -; -; ;Debug "ReceiveHTTPToMemory" + URL$ + ProxyURL$ + ProxyPort$ + ProxyUser$ + ProxyPassword$ -; -; If Len(URL$) -; -; curl = curl_easy_init() -; -; If curl -; -; Timeout = 3 -; -; curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$)) -; curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0) -; curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0) -; curl_easy_setopt(curl, #CURLOPT_HEADER, 0) -; curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1) -; curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout) -; -; If Len(ProxyURL$) -; ;curl_easy_setopt(curl, #CURLOPT_HTTPPROXYTUNNEL, #True) -; If Len(ProxyPort$) -; ProxyURL$ + ":" + ProxyPort$ -; EndIf -; ; Debug ProxyURL$ -; curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$)) -; If Len(ProxyUser$) -; If Len(ProxyPassword$) -; ProxyUser$ + ":" + ProxyPassword$ -; EndIf -; ;Debug ProxyUser$ -; curl_easy_setopt(curl, #CURLOPT_PROXYUSERPWD, str2curl(ProxyUser$)) -; EndIf -; EndIf -; -; ;TODO improve with https://github.com/Progi1984/RWrappers/tree/master/LibCurl -; curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction()) -; LockMutex(OSM\CurlMutex) -; res = curl_easy_perform(curl) -; UnlockMutex(OSM\CurlMutex) -; -; If res = #CURLE_OK -; -; *Buffer = AllocateMemory(ReceiveHTTPToMemoryBufferPtr) -; If *Buffer -; CopyMemory(*ReceiveHTTPToMemoryBuffer, *Buffer, ReceiveHTTPToMemoryBufferPtr) -; FreeMemory(*ReceiveHTTPToMemoryBuffer) -; *ReceiveHTTPToMemoryBuffer = #Null -; ReceiveHTTPToMemoryBufferPtr = 0 -; Else -; ; Debug "Problem allocating buffer" -; EndIf -; ;curl_easy_cleanup(curl) ;Was its original place but moved below as it seems more logical to me. -; Else -; ; Debug "CURL NOT OK" -; EndIf -; -; curl_easy_cleanup(curl) -; -; Else -; ; Debug "Can't Init CURL" -; EndIf -; -; EndIf -; -; ; Debug "Curl Buffer : " + Str(*Buffer) -; -; ProcedureReturn *Buffer -; -; EndProcedure ProcedureC ReceiveHTTPWriteToFileFunction(*ptr, Size.i, NMemB.i, FileHandle.i) @@ -256,8 +155,8 @@ Module OSM Protected *Buffer, curl.i, Timeout.i, res.i Protected FileHandle.i - Debug "ReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + ProxyPort$ + ProxyUser$ - Debug " to file : " + DestFileName$ + ;Debug "ReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + ProxyPort$ + ProxyUser$ + ;Debug " to file : " + DestFileName$ FileHandle = CreateFile(#PB_Any, DestFileName$) @@ -296,9 +195,9 @@ Module OSM curl_easy_setopt(curl, #CURLOPT_WRITEDATA, FileHandle) curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToFileFunction()) - ;LockMutex(OSM\CurlMutex) ;Not any more necessary + res = curl_easy_perform(curl) - ;UnlockMutex(OSM\CurlMutex) + If res <> #CURLE_OK Debug "CURL NOT OK" EndIf @@ -330,7 +229,6 @@ Module OSM OSM\ZoomMax = 18 OSM\MoveStartingPoint\x = - 1 OSM\TileSize = 256 - ;OSM\CurlMutex = CreateMutex() OSM\Dirty = #False OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Semaphore = CreateSemaphore() @@ -528,24 +426,16 @@ Module OSM EndProcedure Procedure.i GetTileFromHDD(CacheFile.s) - - Protected nImage.i - + Protected nImage.i If FileSize(CacheFile) > 0 - nImage = LoadImage(#PB_Any, CacheFile) - If IsImage(nImage) - Debug "Loadimage " + CacheFile + " -> Success !" + ;Debug "Loadimage " + CacheFile + " -> Success !" ProcedureReturn nImage EndIf - EndIf - - Debug "Loadimage " + CacheFile + " -> Failed !" - + ;Debug "Loadimage " + CacheFile + " -> Failed !" ProcedureReturn -1 - EndProcedure Procedure.i GetTileFromWeb(Zoom.i, XTile.i, YTile.i, CacheFile.s) @@ -554,18 +444,15 @@ Module OSM Protected nImage.i = -1 Protected FileHandle.i - Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" - ; Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" - - Debug "Check if we have this image on Web" + Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" + ;Debug "Check if we have this image on Web" If Proxy - ;*Buffer = CurlReceiveHTTPToMemory(TileURL, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) If FileHandle nImage = GetTileFromHDD(CacheFile) Else - Debug "File " + TileURL + " not correctly received with Curl and proxy" + ;Debug "File " + TileURL + " not correctly received with Curl and proxy" EndIf Else *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous @@ -573,16 +460,16 @@ Module OSM If *Buffer nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) If IsImage(nImage) - Debug "Load from web " + TileURL + " as Tile nb " + nImage + ;Debug "Load from web " + TileURL + " as Tile nb " + nImage SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG) FreeMemory(*Buffer) Else - Debug "Can't catch image " + TileURL + ;Debug "Can't catch image " + TileURL nImage = -1 ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) EndIf Else - Debug "ReceiveHTTPMemory's buffer is empty" + ;Debug "ReceiveHTTPMemory's buffer is empty" EndIf EndIf @@ -1170,8 +1057,8 @@ CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) ; ExecutableFormat = Console -; CursorPosition = 146 -; FirstLine = 117 +; CursorPosition = 435 +; FirstLine = 448 ; Folding = ------- ; EnableUnicode ; EnableThread From 1d88f06a421b4705d3c2998e799d357aa69f33ed Mon Sep 17 00:00:00 2001 From: djes Date: Tue, 2 Aug 2016 16:26:52 +0200 Subject: [PATCH 30/35] syntax --- osm.pb | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/osm.pb b/osm.pb index b6f159b..06ea904 100644 --- a/osm.pb +++ b/osm.pb @@ -142,10 +142,10 @@ Module OSM ;- *** CURL specific *** - IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl + IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl ProcedureC ReceiveHTTPWriteToFileFunction(*ptr, Size.i, NMemB.i, FileHandle.i) - + ProcedureReturn WriteData(FileHandle, *ptr, Size * NMemB) EndProcedure @@ -175,7 +175,7 @@ Module OSM curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1) curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout) curl_easy_setopt(curl, #CURLOPT_VERBOSE, 1) - curl_easy_setopt(curl, #CURLOPT_CONNECTTIMEOUT, 0) + ;curl_easy_setopt(curl, #CURLOPT_CONNECTTIMEOUT, 60) If Len(ProxyURL$) ;curl_easy_setopt(curl, #CURLOPT_HTTPPROXYTUNNEL, #True) @@ -512,8 +512,29 @@ Module OSM MovePathCursor(x, y) DrawVectorImage(ImageID(*Tile\nImage)) + + EndProcedure + + Procedure DrawLoading(*Tile.Tile) + + Protected x = *Tile\Position\x + Protected y = *Tile\Position\y + Protected Text$ = "Loading" + + ; Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) + ; Debug " at coords " + Str(x) + "," + Str(y) + + BeginVectorLayer() + ;MovePathCursor(x, y) + VectorSourceColor(RGBA(255, 255, 255, 128)) + AddPathBox(x, y, OSM\TileSize, OSM\TileSize) + FillPath() MovePathCursor(x, y) - DrawVectorText(Str(x) + ", " + Str(y)) + VectorFont(FontID(OSM\Font), OSM\TileSize / 20) + VectorSourceColor(RGBA(150, 150, 150, 255)) + MovePathCursor(x + (OSM\TileSize - VectorTextWidth(Text$)) / 2, y + (OSM\TileSize - VectorTextHeight(Text$)) / 2) + DrawVectorText(Text$) + EndVectorLayer() EndProcedure @@ -564,7 +585,8 @@ Module OSM If IsImage(\nImage) DrawTile(*NewTile) Else - ; Debug "Image missing" + ;Debug "Image missing" + DrawLoading(*NewTile) *Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw EndIf @@ -681,6 +703,8 @@ Module OSM EndProcedure + ;-*** Main drawing thread + ; always running, waiting for a semaphore to start refreshing Procedure DrawingThread(*SharedDrawing.DrawingParameters) Protected Drawing.DrawingParameters @@ -692,11 +716,12 @@ Module OSM ; Debug "--------- Main drawing thread ------------" - ;Creates a copy of the structure to work with, and precalculus some values + ;Creates a copy of the structure to work with LockMutex(*SharedDrawing\Mutex) CopyStructure(*SharedDrawing, @Drawing, DrawingParameters) UnlockMutex(*SharedDrawing\Mutex) + ;Precalc some values Drawing\CenterX = GadgetWidth(OSM\Gadget) / 2 Drawing\CenterY = GadgetHeight(OSM\Gadget) / 2 ;Pixel shift, aka position in the tile @@ -715,12 +740,11 @@ Module OSM Pointer(Drawing\CenterX, Drawing\CenterY, #Red) StopVectorDrawing() - ;- Redraw + ;Redraw ;If something was not correctly drawn, redraw after a while LockMutex(*SharedDrawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore) If Drawing\Dirty ; Debug "Something was dirty ! We try again to redraw" - ;Delay(250) Drawing\PassNb + 1 SignalSemaphore(*SharedDrawing\Semaphore) Else @@ -1057,8 +1081,8 @@ CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) ; ExecutableFormat = Console -; CursorPosition = 435 -; FirstLine = 448 +; CursorPosition = 594 +; FirstLine = 569 ; Folding = ------- ; EnableUnicode ; EnableThread From c5e55a6c7463d6a7d2d2a51ba5b754276ea889ec Mon Sep 17 00:00:00 2001 From: djes Date: Tue, 2 Aug 2016 16:31:07 +0200 Subject: [PATCH 31/35] Last typhoon adds :) --- osm.pb | 67 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/osm.pb b/osm.pb index 06ea904..adf9f4b 100644 --- a/osm.pb +++ b/osm.pb @@ -626,16 +626,44 @@ Module OSM EndProcedure +Procedure TrackPointer(x.i, y.i,dist.l) + Protected color.l + color=RGBA(0, 0, 0, 255) + MovePathCursor(x,y) + AddPathLine(-8,-16,#PB_Path_Relative) + AddPathLine(16,0,#PB_Path_Relative) + AddPathLine(-8,16,#PB_Path_Relative) + VectorSourceColor(color) + AddPathCircle(x,y-20,14) + FillPath() + VectorSourceColor(RGBA(255, 255, 255, 255)) + AddPathCircle(x,y-20,12) + FillPath() + VectorFont(FontID(OSM\Font), 13) + MovePathCursor(x-VectorTextWidth(Str(dist))/2, y-20-VectorTextHeight(Str(dist))/2) + VectorSourceColor(RGBA(0, 0, 0, 255)) + DrawVectorText(Str(dist)) +EndProcedure Procedure DrawTrack(*Drawing.DrawingParameters) - Protected Pixel.PixelPosition Protected Location.Location - Protected km.f, memKm.i - If ListSize(OSM\track())>0 - + ;Trace Track LockMutex(OSM\Drawing\Mutex) + ForEach OSM\track() + If *Drawing\TargetLocation\Latitude<>0 And *Drawing\TargetLocation\Longitude<>0 + GetPixelCoordFromLocation(@OSM\track(),@Pixel) + If ListIndex(OSM\track())=0 + MovePathCursor(Pixel\X, Pixel\Y) + Else + AddPathLine(Pixel\X, Pixel\Y) + EndIf + EndIf + Next + VectorSourceColor(RGBA(0, 255, 0, 150)) + StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) + ;Draw Distance ForEach OSM\track() ;-Test Distance If ListIndex(OSM\track())=0 @@ -646,33 +674,18 @@ Module OSM Location\Latitude=OSM\track()\Latitude Location\Longitude=OSM\track()\Longitude EndIf - If *Drawing\TargetLocation\Latitude<>0 And *Drawing\TargetLocation\Longitude<>0 - GetPixelCoordFromLocation(@OSM\track(),@Pixel) - If ListIndex(OSM\track())=0 - MovePathCursor(Pixel\X, Pixel\Y) - Else - AddPathLine(Pixel\X, Pixel\Y) - If Int(km)<>memKm - memKm=Int(km) - If OSM\Zoom>10 - BeginVectorLayer() - VectorFont(FontID(OSM\Font), OSM\Zoom) - VectorSourceColor(RGBA(50, 50, 50, 255)) - DrawVectorText(Str(Int(km))) - EndVectorLayer() - EndIf - EndIf - + GetPixelCoordFromLocation(@OSM\track(),@Pixel) + If Int(km)<>memKm + memKm=Int(km) + If OSM\Zoom>10 + BeginVectorLayer() + TrackPointer(Pixel\X , Pixel\Y,Int(km)) + EndVectorLayer() EndIf - EndIf + EndIf Next UnlockMutex(OSM\Drawing\Mutex) - - VectorSourceColor(RGBA(0, 255, 0, 150)) - StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) - EndIf - EndProcedure ; Add a Marker To the Map From 0f1ab83c8541a1fb0f1fd95721238ec983fe3ff3 Mon Sep 17 00:00:00 2001 From: djes Date: Tue, 2 Aug 2016 17:26:56 +0200 Subject: [PATCH 32/35] Main interface lil fixes --- osm.pb | 68 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/osm.pb b/osm.pb index adf9f4b..989883d 100644 --- a/osm.pb +++ b/osm.pb @@ -24,7 +24,7 @@ DeclareModule OSM Declare InitOSM() Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) Declare Event(Event.l) - Declare SetLocation(latitude.d, longitude.d, zoom = 15) + Declare SetLocation(latitude.d, longitude.d, zoom = 15, mode.i = #PB_Absolute) Declare DrawingThread(Null) Declare SetZoom(Zoom.i, mode.i = #PB_Relative) Declare ZoomToArea() @@ -33,6 +33,7 @@ DeclareModule OSM Declare AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1) Declare Quit() Declare Error(msg.s) + Declare Refresh() EndDeclareModule Module OSM @@ -770,13 +771,25 @@ EndProcedure EndProcedure - Procedure SetLocation(latitude.d, longitude.d, zoom = 15) + Procedure Refresh() - OSM\TargetLocation\Latitude = latitude - OSM\TargetLocation\Longitude = longitude + SignalSemaphore(OSM\Drawing\Semaphore) - OSM\Zoom = zoom + EndProcedure + + Procedure SetLocation(latitude.d, longitude.d, zoom = 15, Mode.i = #PB_Absolute) + Select Mode + Case #PB_Absolute + OSM\TargetLocation\Latitude = latitude + OSM\TargetLocation\Longitude = longitude + OSM\Zoom = zoom + Case #PB_Relative + OSM\TargetLocation\Latitude + latitude + OSM\TargetLocation\Longitude + longitude + OSM\Zoom + zoom + EndSelect + If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf @@ -788,6 +801,9 @@ EndProcedure ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) ;*** + If OSM\CallBackLocation > 0 + CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) + EndIf EndProcedure @@ -861,6 +877,9 @@ EndProcedure ;Start drawing SignalSemaphore(OSM\Drawing\Semaphore) ;*** + If OSM\CallBackLocation > 0 + CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) + EndIf EndProcedure @@ -1012,10 +1031,10 @@ CompilerIf #PB_Compiler_IsMainFile Procedure ResizeAll() ResizeGadget(#Map,10,10,WindowWidth(#Window_0)-198,WindowHeight(#Window_0)-59) ResizeGadget(#Text_1,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) - ResizeGadget(#Gdt_Left,WindowWidth(#Window_0)-150,#PB_Ignore,#PB_Ignore,#PB_Ignore) - ResizeGadget(#Gdt_Right,WindowWidth(#Window_0)-90,#PB_Ignore,#PB_Ignore,#PB_Ignore) - ResizeGadget(#Gdt_Up,WindowWidth(#Window_0)-110,#PB_Ignore,#PB_Ignore,#PB_Ignore) - ResizeGadget(#Gdt_Down,WindowWidth(#Window_0)-110,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_Left, WindowWidth(#Window_0) - 150 ,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_Right,WindowWidth(#Window_0) - 90 ,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_Up, WindowWidth(#Window_0) - 120 ,#PB_Ignore,#PB_Ignore,#PB_Ignore) + ResizeGadget(#Gdt_Down, WindowWidth(#Window_0) - 120 ,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Text_2,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Button_4,WindowWidth(#Window_0)-150,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Button_5,WindowWidth(#Window_0)-100,#PB_Ignore,#PB_Ignore,#PB_Ignore) @@ -1025,8 +1044,10 @@ CompilerIf #PB_Compiler_IsMainFile ResizeGadget(#Text_4,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_AddMarker,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) + OSM::Refresh() EndProcedure + ;- MAIN TEST If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) OSM::InitOSM() LoadFont(0, "Wingdings", 12) @@ -1034,12 +1055,12 @@ CompilerIf #PB_Compiler_IsMainFile OSM::MapGadget(#Map, 10, 10, 512, 512) - TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ") - ButtonGadget(#Gdt_Left, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Gdt_Left, FontID(0)) + TextGadget(#Text_1, 530, 50, 60, 15, "Movements") + ButtonGadget(#Gdt_Left, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Gdt_Left, FontID(0)) ButtonGadget(#Gdt_Right, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Gdt_Right, FontID(0)) - ButtonGadget(#Gdt_Up, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Gdt_Up, FontID(0)) - ButtonGadget(#Gdt_Down, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Gdt_Down, FontID(0)) - TextGadget(#Text_2, 530, 160, 60, 15, "Zoom : ") + ButtonGadget(#Gdt_Up, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Gdt_Up, FontID(0)) + ButtonGadget(#Gdt_Down, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Gdt_Down, FontID(0)) + TextGadget(#Text_2, 530, 160, 60, 15, "Zoom") ButtonGadget(#Button_4, 550, 180, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1)) ButtonGadget(#Button_5, 600, 180, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1)) TextGadget(#Text_3, 530, 230, 60, 15, "Latitude : ") @@ -1051,11 +1072,10 @@ CompilerIf #PB_Compiler_IsMainFile Define Event.i, Gadget.i, Quit.b = #False Define pfValue.d - OSM::SetLocation(49.04599, 2.03347, 17) OSM::SetCallBackLocation(@UpdateLocation()) + OSM::SetLocation(49.04599, 2.03347, 17) OSM::AddMarker(49.0446828398,2.0349812508,-1,@MyPointer()) - Repeat Event = WaitWindowEvent() @@ -1066,19 +1086,19 @@ CompilerIf #PB_Compiler_IsMainFile Gadget = EventGadget() Select Gadget Case #Gdt_Up - ;OSM::Move(0,-0.5) + OSM::SetLocation(0.0001, 0, 0, #PB_Relative) Case #Gdt_Down - ;OSM::Move(0,0.5) + OSM::SetLocation(-0.0001, 0, 0, #PB_Relative) Case #Gdt_Left - ;OSM::Move(-0.5,0) + OSM::SetLocation(0, -0.0001, 0, #PB_Relative) Case #Gdt_Right - ;OSM::Move(0.5,0) + OSM::SetLocation(0, 0.0001, 0, #PB_Relative) Case #Button_4 OSM::SetZoom(1) Case #Button_5 OSM::SetZoom( - 1) Case #Gdt_LoadGpx - OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) + OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) OSM::ZoomToArea() ; <-To center the view, and to viex all the track Case #Gdt_AddMarker OSM:: AddMarker(ValD(GetGadgetText(#String_0)),ValD(GetGadgetText(#String_1)),RGBA(Random(255),Random(255),Random(255),255)) @@ -1094,9 +1114,9 @@ CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) ; ExecutableFormat = Console -; CursorPosition = 594 -; FirstLine = 569 -; Folding = ------- +; CursorPosition = 273 +; FirstLine = 237 +; Folding = -------- ; EnableUnicode ; EnableThread ; EnableXP \ No newline at end of file From 937b620484a14ff4b92218a6694bd2902b763bfb Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 3 Aug 2016 12:01:14 +0200 Subject: [PATCH 33/35] Nicer moves --- osm.pb | 59 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/osm.pb b/osm.pb index 989883d..a370109 100644 --- a/osm.pb +++ b/osm.pb @@ -34,6 +34,9 @@ DeclareModule OSM Declare Quit() Declare Error(msg.s) Declare Refresh() + Declare.d GetLatitude() + Declare.d GetLongitude() + Declare.i GetZoom() EndDeclareModule Module OSM @@ -355,8 +358,8 @@ Module OSM EndProcedure Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.PixelPosition) ; TODO to Optimize - Protected mapWidth.l = Pow(2,OSM\Zoom+8) - Protected mapHeight.l = Pow(2,OSM\Zoom+8) + Protected mapWidth.l = Pow(2, OSM\Zoom + 8) + Protected mapHeight.l = Pow(2, OSM\Zoom + 8) Protected x1.l,y1.l ; get x value @@ -601,7 +604,7 @@ Module OSM Next ;Free tile memory when the loading thread has finished - ;TODO : exit this proc from drawtiles in a special "free ressources" task + ;TODO : get out this proc from drawtiles in a special "free ressources" task ForEach OSM\TilesThreads() If IsThread(OSM\TilesThreads()\GetImageThread) = 0 FreeMemory(OSM\TilesThreads()\Tile) @@ -627,7 +630,7 @@ Module OSM EndProcedure -Procedure TrackPointer(x.i, y.i,dist.l) + Procedure TrackPointer(x.i, y.i,dist.l) Protected color.l color=RGBA(0, 0, 0, 255) MovePathCursor(x,y) @@ -642,9 +645,10 @@ Procedure TrackPointer(x.i, y.i,dist.l) FillPath() VectorFont(FontID(OSM\Font), 13) MovePathCursor(x-VectorTextWidth(Str(dist))/2, y-20-VectorTextHeight(Str(dist))/2) - VectorSourceColor(RGBA(0, 0, 0, 255)) + VectorSourceColor(RGBA(0, 0, 0, 255)) DrawVectorText(Str(dist)) -EndProcedure + EndProcedure + Procedure DrawTrack(*Drawing.DrawingParameters) Protected Pixel.PixelPosition Protected Location.Location @@ -789,7 +793,7 @@ EndProcedure OSM\TargetLocation\Longitude + longitude OSM\Zoom + zoom EndSelect - + If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf @@ -807,7 +811,6 @@ EndProcedure EndProcedure - Procedure ZoomToArea() ;Source => http://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map ;bounding box in long/lat coords (x=long, y=lat) @@ -887,6 +890,30 @@ EndProcedure OSM\CallBackLocation = CallBackLocation EndProcedure + Procedure.d GetLatitude() + Protected Value.d + LockMutex(OSM\Drawing\Mutex) + Value = OSM\TargetLocation\Latitude + UnlockMutex(OSM\Drawing\Mutex) + ProcedureReturn Value + EndProcedure + + Procedure.d GetLongitude() + Protected Value.d + LockMutex(OSM\Drawing\Mutex) + Value = OSM\TargetLocation\Longitude + UnlockMutex(OSM\Drawing\Mutex) + ProcedureReturn Value + EndProcedure + + Procedure.i GetZoom() + Protected Value.d + LockMutex(OSM\Drawing\Mutex) + Value = OSM\Zoom + UnlockMutex(OSM\Drawing\Mutex) + ProcedureReturn Value + EndProcedure + Procedure Event(Event.l) Protected Gadget.i @@ -1046,7 +1073,7 @@ CompilerIf #PB_Compiler_IsMainFile ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) OSM::Refresh() EndProcedure - + ;- MAIN TEST If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) OSM::InitOSM() @@ -1074,7 +1101,7 @@ CompilerIf #PB_Compiler_IsMainFile Define pfValue.d OSM::SetCallBackLocation(@UpdateLocation()) OSM::SetLocation(49.04599, 2.03347, 17) - OSM::AddMarker(49.0446828398,2.0349812508,-1,@MyPointer()) + OSM::AddMarker(49.0446828398, 2.0349812508, -1, @MyPointer()) Repeat Event = WaitWindowEvent() @@ -1086,13 +1113,13 @@ CompilerIf #PB_Compiler_IsMainFile Gadget = EventGadget() Select Gadget Case #Gdt_Up - OSM::SetLocation(0.0001, 0, 0, #PB_Relative) + OSM::SetLocation(10* 360 / Pow(2, OSM::GetZoom() + 8), 0, 0, #PB_Relative) Case #Gdt_Down - OSM::SetLocation(-0.0001, 0, 0, #PB_Relative) + OSM::SetLocation(10* -360 / Pow(2, OSM::GetZoom() + 8), 0, 0, #PB_Relative) Case #Gdt_Left - OSM::SetLocation(0, -0.0001, 0, #PB_Relative) + OSM::SetLocation(0, 10* -360 / Pow(2, OSM::GetZoom() + 8), 0, #PB_Relative) Case #Gdt_Right - OSM::SetLocation(0, 0.0001, 0, #PB_Relative) + OSM::SetLocation(0, 10* 360 / Pow(2, OSM::GetZoom() + 8), 0, #PB_Relative) Case #Button_4 OSM::SetZoom(1) Case #Button_5 @@ -1114,8 +1141,8 @@ CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) ; ExecutableFormat = Console -; CursorPosition = 273 -; FirstLine = 237 +; CursorPosition = 1115 +; FirstLine = 1083 ; Folding = -------- ; EnableUnicode ; EnableThread From 4d1b7c5537cf5e679275a2a052dcf54d088b0e63 Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 3 Aug 2016 12:49:54 +0200 Subject: [PATCH 34/35] Big code cleaning --- osm.pb | 272 +++++++++++++++++++-------------------------------------- 1 file changed, 90 insertions(+), 182 deletions(-) diff --git a/osm.pb b/osm.pb index a370109..b1e3386 100644 --- a/osm.pb +++ b/osm.pb @@ -16,11 +16,14 @@ CompilerEndIf EnableExplicit InitNetwork() -OpenConsole() UsePNGImageDecoder() UsePNGImageEncoder() DeclareModule OSM + ;-Show debug infos + Global Verbose = #True + ;-Proxy ON/OFF + Global Proxy = #True Declare InitOSM() Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) Declare Event(Event.l) @@ -101,9 +104,9 @@ Module OSM EndStructure Structure Marker - Location.Location ; Latitude and Longitude from Marker - color.l ; Color Marker - CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (You must use VectorDrawing lib) + Location.Location ; Marker latitude and longitude + color.l ; Marker color + CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib) EndStructure ;-OSM Structure @@ -112,66 +115,67 @@ Module OSM Font.i ; Font to uses when write on the map TargetLocation.Location ; Latitude and Longitude from focus point Drawing.DrawingParameters ; Drawing parameters based on focus point - + ; CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) - + ; Position.PixelPosition ; Actual focus point coords in pixels (global) MoveStartingPoint.PixelPosition ; Start mouse position coords when dragging the map - + ; ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/ ZoomMin.i ; Min Zoom supported by server ZoomMax.i ; Max Zoom supported by server Zoom.i ; Current zoom TileSize.i ; Tile size downloaded on the server ex : 256 - + ; HDDCachePath.S ; Path where to load and save tiles downloaded from server MemCache.TileMemCach ; Images in memory cache - + ; Moving.i - Dirty.i ;To signal that drawing need a refresh - + Dirty.i ; To signal that drawing need a refresh + ; MainDrawingThread.i List TilesThreads.TileThread() - - List track.Location() ;to display a GPX track + ; + List track.Location() ; To display a GPX track List Marker.Marker() ; To diplay marker EditMarkerIndex.l EndStructure Global OSM.OSM, Null.i + ;Shows an error msg and terminates the program Procedure Error(msg.s) - Debug msg, 2 + MessageRequester("MapGadget", msg, #PB_MessageRequester_Ok) + End + EndProcedure + + ;Send debug infos to stdout + Procedure MyDebug(msg.s) + If Verbose + PrintN(msg) + EndIf EndProcedure ;- *** CURL specific *** + ; (program has To be compiled in console format for curl debug infos) IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl + ;Curl write callback (needed for win32 dll) ProcedureC ReceiveHTTPWriteToFileFunction(*ptr, Size.i, NMemB.i, FileHandle.i) - - ProcedureReturn WriteData(FileHandle, *ptr, Size * NMemB) - + ProcedureReturn WriteData(FileHandle, *ptr, Size * NMemB) EndProcedure Procedure.i CurlReceiveHTTPToFile(URL$, DestFileName$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="") - Protected *Buffer, curl.i, Timeout.i, res.i Protected FileHandle.i - - ;Debug "ReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + ProxyPort$ + ProxyUser$ - ;Debug " to file : " + DestFileName$ - + MyDebug("ReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + ProxyPort$ + ProxyUser$) + MyDebug(" to file : " + DestFileName$) FileHandle = CreateFile(#PB_Any, DestFileName$) - If FileHandle And Len(URL$) - curl = curl_easy_init() - If curl - Timeout = 120 - curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$)) curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0) curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0) @@ -180,53 +184,43 @@ Module OSM curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout) curl_easy_setopt(curl, #CURLOPT_VERBOSE, 1) ;curl_easy_setopt(curl, #CURLOPT_CONNECTTIMEOUT, 60) - If Len(ProxyURL$) ;curl_easy_setopt(curl, #CURLOPT_HTTPPROXYTUNNEL, #True) If Len(ProxyPort$) ProxyURL$ + ":" + ProxyPort$ EndIf - ; Debug ProxyURL$ + MyDebug( ProxyURL$) curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$)) If Len(ProxyUser$) If Len(ProxyPassword$) ProxyUser$ + ":" + ProxyPassword$ EndIf - ;Debug ProxyUser$ + MyDebug( ProxyUser$) curl_easy_setopt(curl, #CURLOPT_PROXYUSERPWD, str2curl(ProxyUser$)) EndIf EndIf - curl_easy_setopt(curl, #CURLOPT_WRITEDATA, FileHandle) curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToFileFunction()) - res = curl_easy_perform(curl) - If res <> #CURLE_OK - Debug "CURL NOT OK" + MyDebug("CURL problem") EndIf - curl_easy_cleanup(curl) - Else - Debug "Can't Init CURL" + MyDebug("Can't init CURL") EndIf - CloseFile(FileHandle) ProcedureReturn FileSize(DestFileName$) - EndIf - ProcedureReturn #False - EndProcedure - ;- *** Procedure InitOSM() - Protected Result.i - + If Verbose + OpenConsole() + EndIf OSM\HDDCachePath = GetTemporaryDirectory() OSM\ServerURL = "http://tile.openstreetmap.org/" OSM\ZoomMin = 0 @@ -237,12 +231,9 @@ Module OSM OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Semaphore = CreateSemaphore() OSM\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected - OSM\Font=LoadFont(#PB_Any, "Comic Sans MS", 20, #PB_Font_Bold) + OSM\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold) ;- Proxy details - - Global Proxy = #True - - ;Use this to customize your preferences + ;Use this to create and customize your preferences file for the first time ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") ; If Proxy ; PreferenceGroup("PROXY") @@ -253,35 +244,30 @@ Module OSM ; If Result ; ClosePreferences() ; EndIf - Result = OpenPreferences(GetHomeDirectory() + "OSM.prefs") - If Proxy PreferenceGroup("PROXY") Global ProxyURL$ = ReadPreferenceString("ProxyURL", "") ;InputRequester("ProxyServer", "Do you use a Proxy Server? Then enter the full url:", "") Global ProxyPort$ = ReadPreferenceString("ProxyPort", "") ;InputRequester("ProxyPort" , "Do you use a specific port? Then enter it", "") Global ProxyUser$ = ReadPreferenceString("ProxyUser", "") ;InputRequester("ProxyUser" , "Do you use a user name? Then enter it", "") - Global ProxyPassword$ = InputRequester("ProxyPass" , "Do you use a password ? Then enter it", "") + Global ProxyPassword$ = InputRequester("ProxyPass", "Do you use a password ? Then enter it", "") EndIf If Result ClosePreferences() EndIf - curl_global_init(#CURL_GLOBAL_WIN32); - ;- Main drawing thread launching OSM\MainDrawingThread = CreateThread(@DrawingThread(), @OSM\Drawing) If OSM\MainDrawingThread = 0 - Error("MapGadget : Can't create main drawing thread") - End + Error("MapGadget : can't create main drawing thread.") EndIf - EndProcedure Procedure Quit() - ;kill main drawing thread - KillThread(OSM\MainDrawingThread) - + ;kill main drawing thread (nicer than KillThread(OSM\MainDrawingThread)) + LockMutex(OSM\Drawing\Mutex) + OSM\Drawing\End = #True + UnlockMutex(OSM\Drawing\Mutex) ;wait for loading threads to finish nicely ResetList( OSM\TilesThreads()) While NextElement(OSM\TilesThreads()) @@ -291,7 +277,6 @@ Module OSM ResetList( OSM\TilesThreads()) EndIf Wend - curl_global_cleanup() EndProcedure @@ -325,8 +310,8 @@ Module OSM Protected LatRad.d = Radian(*Location\Latitude) *Coords\x = n * ( (*Location\Longitude + 180.0) / 360.0) *Coords\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0 - ; Debug "Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude) - ; Debug "Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y) + MyDebug("Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude)) + MyDebug("Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y)) EndProcedure ;*** Converts tile.decimal to coords @@ -361,24 +346,20 @@ Module OSM Protected mapWidth.l = Pow(2, OSM\Zoom + 8) Protected mapHeight.l = Pow(2, OSM\Zoom + 8) Protected x1.l,y1.l - ; get x value x1 = (*Location\Longitude+180)*(mapWidth/360) ; convert from degrees To radians Protected latRad.d = *Location\Latitude*#PI/180; - Protected mercN.d = Log(Tan((#PI/4)+(latRad/2))); y1 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)) ; - Protected x2.l, y2.l ; get x value x2 = (OSM\TargetLocation\Longitude+180)*(mapWidth/360) ; convert from degrees To radians latRad = OSM\TargetLocation\Latitude*#PI/180; - ; get y value - mercN = Log(Tan((#PI/4)+(latRad/2))) ; - y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)); - + ; get y value + mercN = Log(Tan((#PI/4)+(latRad/2))) + y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)); *Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1) *Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1) EndProcedure @@ -414,19 +395,15 @@ Module OSM EndProcedure Procedure.i GetTileFromMem(Zoom.i, XTile.i, YTile.i) - - Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0") - - ; Debug "Check if we have this image in memory" - + Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0") + MyDebug("Check if we have this image in memory") If FindMapElement(OSM\MemCache\Images(), key) - ; Debug "Key : " + key + " found !" + MyDebug("Key : " + key + " found !") ProcedureReturn OSM\MemCache\Images()\nImage Else - ; Debug "Key : " + key + " not found !" + MyDebug("Key : " + key + " not found !") ProcedureReturn -1 EndIf - EndProcedure Procedure.i GetTileFromHDD(CacheFile.s) @@ -434,59 +411,51 @@ Module OSM If FileSize(CacheFile) > 0 nImage = LoadImage(#PB_Any, CacheFile) If IsImage(nImage) - ;Debug "Loadimage " + CacheFile + " -> Success !" + MyDebug("Loadimage " + CacheFile + " -> Success !") ProcedureReturn nImage EndIf EndIf - ;Debug "Loadimage " + CacheFile + " -> Failed !" + MyDebug("Loadimage " + CacheFile + " -> Failed !") ProcedureReturn -1 EndProcedure Procedure.i GetTileFromWeb(Zoom.i, XTile.i, YTile.i, CacheFile.s) - Protected *Buffer Protected nImage.i = -1 Protected FileHandle.i - Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" - ;Debug "Check if we have this image on Web" - + MyDebug("Check if we have this image on Web") If Proxy FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) If FileHandle nImage = GetTileFromHDD(CacheFile) Else - ;Debug "File " + TileURL + " not correctly received with Curl and proxy" + MyDebug("File " + TileURL + " not correctly received with Curl and proxy") EndIf Else *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous - If *Buffer nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) If IsImage(nImage) - ;Debug "Load from web " + TileURL + " as Tile nb " + nImage + MyDebug("Load from web " + TileURL + " as Tile nb " + nImage) SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG) FreeMemory(*Buffer) Else - ;Debug "Can't catch image " + TileURL + MyDebug("Can't catch image " + TileURL) nImage = -1 ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) EndIf Else - ;Debug "ReceiveHTTPMemory's buffer is empty" + MyDebug("ReceiveHTTPMemory's buffer is empty") EndIf EndIf - ProcedureReturn nImage - EndProcedure Procedure GetImageThread(*Tile.Tile) - Protected nImage.i = -1 Protected key.s = "Z" + RSet(Str(*Tile\OSMZoom), 4, "0") + "X" + RSet(Str(*Tile\OSMTileX), 8, "0") + "Y" + RSet(Str(*Tile\OSMTileY), 8, "0") Protected CacheFile.s = OSM\HDDCachePath + "OSM_" + Str(*Tile\OSMZoom) + "_" + Str(*Tile\OSMTileX) + "_" + Str(*Tile\OSMTileY) + ".png" - ;Adding the image to the cache if possible AddMapElement(OSM\MemCache\Images(), key) nImage = GetTileFromHDD(CacheFile) @@ -495,39 +464,31 @@ Module OSM EndIf If nImage <> -1 OSM\MemCache\Images(key)\nImage = nImage - ; Debug "Image nb " + Str(nImage) + " successfully added to mem cache" - ; Debug "With the following key : " + key + MyDebug("Image nb " + Str(nImage) + " successfully added to mem cache") + MyDebug("With the following key : " + key) Else - ; Debug "Error GetImageThread procedure, image not loaded - " + key + MyDebug("Error GetImageThread procedure, image not loaded - " + key) nImage = -1 EndIf ;Define this tile image nb *Tile\nImage = nImage - EndProcedure Procedure DrawTile(*Tile.Tile) - Protected x = *Tile\Position\x Protected y = *Tile\Position\y - - ; Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) - ; Debug " at coords " + Str(x) + "," + Str(y) - + MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX)) + MyDebug(" at coords " + Str(x) + "," + Str(y)) MovePathCursor(x, y) DrawVectorImage(ImageID(*Tile\nImage)) - EndProcedure Procedure DrawLoading(*Tile.Tile) - Protected x = *Tile\Position\x Protected y = *Tile\Position\y Protected Text$ = "Loading" - - ; Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) - ; Debug " at coords " + Str(x) + "," + Str(y) - + MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX)) + MyDebug(" at coords " + Str(x) + "," + Str(y)) BeginVectorLayer() ;MovePathCursor(x, y) VectorSourceColor(RGBA(255, 255, 255, 128)) @@ -539,70 +500,55 @@ Module OSM MovePathCursor(x + (OSM\TileSize - VectorTextWidth(Text$)) / 2, y + (OSM\TileSize - VectorTextHeight(Text$)) / 2) DrawVectorText(Text$) EndVectorLayer() - EndProcedure Procedure DrawTiles(*Drawing.DrawingParameters) - Protected x.i, y.i - Protected tx = Int(*Drawing\Position\x) ;Don't forget the Int() ! Protected ty = Int(*Drawing\Position\y) - Protected nx = *Drawing\CenterX / OSM\TileSize ;How many tiles around the point Protected ny = *Drawing\CenterY / OSM\TileSize - - ; Debug "Drawing tiles" - + MyDebug("Drawing tiles") For y = - ny - 1 To ny + 1 For x = - nx - 1 To nx + 1 - ;Was quiting the loop if a move occured, giving maybe smoother movement ;If OSM\Moving ; Break 2 ;EndIf - Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile)) If *NewTile With *NewTile - ;Keep a track of tiles (especially to free memory) AddElement(OSM\TilesThreads()) OSM\TilesThreads()\Tile = *NewTile - ;New tile parameters \Position\x = *Drawing\CenterX + x * OSM\TileSize - *Drawing\DeltaX \Position\y = *Drawing\CenterY + y * OSM\TileSize - *Drawing\DeltaY \OSMTileX = tx + x \OSMTileY = ty + y \OSMZoom = OSM\Zoom - ;Check if the image exists \nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY) If \nImage = -1 ;If not, load it in the background \GetImageThread = CreateThread(@GetImageThread(), *NewTile) OSM\TilesThreads()\GetImageThread = \GetImageThread - ; Debug " Creating get image thread nb " + Str(\GetImageThread) + MyDebug(" Creating get image thread nb " + Str(\GetImageThread)) EndIf - If IsImage(\nImage) DrawTile(*NewTile) Else - ;Debug "Image missing" + MyDebug("Image missing") DrawLoading(*NewTile) *Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw EndIf - EndWith - Else - ; Debug" Error, can't create a new tile." + MyDebug(" Error, can't create a new tile") Break 2 EndIf Next Next - ;Free tile memory when the loading thread has finished ;TODO : get out this proc from drawtiles in a special "free ressources" task ForEach OSM\TilesThreads() @@ -611,11 +557,9 @@ Module OSM DeleteElement(OSM\TilesThreads()) EndIf Next - EndProcedure Procedure Pointer(x.i, y.i, color.l = #Red) - color=RGBA(255, 0, 0, 255) VectorSourceColor(color) MovePathCursor(x, y) @@ -627,7 +571,6 @@ Module OSM AddPathCircle(0,-16,5,0,360,#PB_Path_Relative) VectorSourceColor(color) FillPath(#PB_Path_Preserve):VectorSourceColor(RGBA(0, 0, 0, 255)):StrokePath(1) - EndProcedure Procedure TrackPointer(x.i, y.i,dist.l) @@ -705,7 +648,6 @@ Module OSM ; Draw all markers on the screen ! Procedure DrawMarker(*Drawing.DrawingParameters) Protected Pixel.PixelPosition - ForEach OSM\Marker() If OSM\Marker()\Location\Latitude <> 0 And OSM\Marker()\Location\Longitude <> 0 GetPixelCoordFromLocation(OSM\Marker()\Location, @Pixel) @@ -718,27 +660,20 @@ Module OSM EndIf EndIf Next - EndProcedure ;-*** Main drawing thread ; always running, waiting for a semaphore to start refreshing Procedure DrawingThread(*SharedDrawing.DrawingParameters) - Protected Drawing.DrawingParameters Protected Px.d, Py.d - Repeat - WaitSemaphore(*SharedDrawing\Semaphore) - - ; Debug "--------- Main drawing thread ------------" - - ;Creates a copy of the structure to work with + MyDebug("--------- Main drawing thread ------------") + ;Creates a copy of the structure to work with to avoid multiple mutex locks LockMutex(*SharedDrawing\Mutex) CopyStructure(*SharedDrawing, @Drawing, DrawingParameters) UnlockMutex(*SharedDrawing\Mutex) - ;Precalc some values Drawing\CenterX = GadgetWidth(OSM\Gadget) / 2 Drawing\CenterY = GadgetHeight(OSM\Gadget) / 2 @@ -748,41 +683,34 @@ Module OSM Drawing\DeltaY = Py * OSM\TileSize - (Int(Py) * OSM\TileSize) Drawing\TargetLocation\Latitude = OSM\TargetLocation\Latitude Drawing\TargetLocation\Longitude = OSM\TargetLocation\Longitude - Drawing\Dirty = #False - + ;Main drawing stuff StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) DrawTiles(@Drawing) DrawTrack(@Drawing) DrawMarker(@Drawing) Pointer(Drawing\CenterX, Drawing\CenterY, #Red) StopVectorDrawing() - ;Redraw - ;If something was not correctly drawn, redraw after a while - LockMutex(*SharedDrawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore) + ; If something was not correctly drawn, redraw after a while + LockMutex(*SharedDrawing\Mutex) ;Be sure that we're not modifying variables while moving (seems not useful, but it is, especially to clean the semaphore) If Drawing\Dirty - ; Debug "Something was dirty ! We try again to redraw" + MyDebug("Something was dirty ! We try again to redraw") Drawing\PassNb + 1 SignalSemaphore(*SharedDrawing\Semaphore) Else ;Clean the semaphore to avoid multiple unuseful redraws Repeat : Until TrySemaphore(*SharedDrawing\Semaphore) = 0 EndIf - UnlockMutex(*SharedDrawing\Mutex) - - Until Drawing\End - + UnlockMutex(*SharedDrawing\Mutex) + Until Drawing\End EndProcedure Procedure Refresh() - SignalSemaphore(OSM\Drawing\Semaphore) - EndProcedure Procedure SetLocation(latitude.d, longitude.d, zoom = 15, Mode.i = #PB_Absolute) - Select Mode Case #PB_Absolute OSM\TargetLocation\Latitude = latitude @@ -793,10 +721,8 @@ Module OSM OSM\TargetLocation\Longitude + longitude OSM\Zoom + zoom EndSelect - If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf - LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) ;Convert X, Y in tile.decimal into real pixels OSM\Position\x = OSM\Drawing\Position\x * OSM\TileSize @@ -808,7 +734,6 @@ Module OSM If OSM\CallBackLocation > 0 CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) EndIf - EndProcedure Procedure ZoomToArea() @@ -832,14 +757,11 @@ Module OSM Protected DeltaX.d=MaxX-MinX ;assumption ! In original code DeltaX have no source Protected centerX.d=MinX+DeltaX/2 ; assumption ! In original code CenterX have no source Protected paddingFactor.f= 1.2 ;paddingFactor: this can be used to get the "120%" effect ThomM refers to. Value of 1.2 would get you the 120%. - Protected ry1.d = Log((Sin(Radian(MinY)) + 1) / Cos(Radian(MinY))) Protected ry2.d = Log((Sin(Radian(MaxY)) + 1) / Cos(Radian(MaxY))) Protected ryc.d = (ry1 + ry2) / 2 Protected centerY.d = Degree(ATan(SinH(ryc))) - Protected resolutionHorizontal.d = DeltaX / GadgetWidth(OSM\Gadget) - Protected vy0.d = Log(Tan(#PI*(0.25 + centerY/360))); Protected vy1.d = Log(Tan(#PI*(0.25 + MaxY/360))) ; Protected viewHeightHalf.d = GadgetHeight(OSM\Gadget)/2; @@ -848,29 +770,23 @@ Module OSM If resolutionHorizontal<>0 And resolutionVertical<>0 Protected resolution.d = Max(resolutionHorizontal, resolutionVertical)* paddingFactor Protected zoom.d = Log(360 / (resolution * OSM\TileSize))/Log(2) - Protected lon.d = centerX; Protected lat.d = centerY; - SetLocation(lat,lon, Round(zoom,#PB_Round_Down)) Else SetLocation(OSM\TargetLocation\Latitude,OSM\TargetLocation\Longitude, 15) EndIf - EndProcedure Procedure SetZoom(Zoom.i, mode.i = #PB_Relative) - Select mode Case #PB_Relative OSM\Zoom = OSM\Zoom + zoom Case #PB_Absolute OSM\Zoom = zoom EndSelect - If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf - LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) ;Convert X, Y in tile.decimal into real pixels OSM\Position\X = OSM\Drawing\Position\x * OSM\TileSize @@ -883,7 +799,6 @@ Module OSM If OSM\CallBackLocation > 0 CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) EndIf - EndProcedure Procedure SetCallBackLocation(CallBackLocation.i) @@ -915,12 +830,10 @@ Module OSM EndProcedure Procedure Event(Event.l) - Protected Gadget.i Protected MouseX.i, MouseY.i Protected Marker.Position Protected *Drawing.DrawingParameters - If IsGadget(OSM\Gadget) And GadgetType(OSM\Gadget) = #PB_GadgetType_Canvas Select Event Case #PB_Event_Gadget ;{ @@ -988,13 +901,9 @@ Module OSM LockMutex(OSM\Drawing\Mutex) OSM\Drawing\Position\x = OSM\Position\x / OSM\TileSize OSM\Drawing\Position\y = OSM\Position\y / OSM\TileSize - ; Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) + MyDebug("OSM\Drawing\Position\x " + Str(OSM\Drawing\Position\x) + " ; OSM\Drawing\Position\y " + Str(OSM\Drawing\Position\y) ) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) UnlockMutex(OSM\Drawing\Mutex) - ;Draw() - ; Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) - ;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude)) - ;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude)) EndIf EndSelect EndSelect @@ -1073,15 +982,13 @@ CompilerIf #PB_Compiler_IsMainFile ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) OSM::Refresh() EndProcedure - + ;- MAIN TEST If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) - OSM::InitOSM() + LoadFont(0, "Wingdings", 12) LoadFont(1, "Arial", 12, #PB_Font_Bold) - - OSM::MapGadget(#Map, 10, 10, 512, 512) - + TextGadget(#Text_1, 530, 50, 60, 15, "Movements") ButtonGadget(#Gdt_Left, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Gdt_Left, FontID(0)) ButtonGadget(#Gdt_Right, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Gdt_Right, FontID(0)) @@ -1099,13 +1006,16 @@ CompilerIf #PB_Compiler_IsMainFile Define Event.i, Gadget.i, Quit.b = #False Define pfValue.d + + ;Our main gadget + OSM::InitOSM() + OSM::MapGadget(#Map, 10, 10, 512, 512) OSM::SetCallBackLocation(@UpdateLocation()) OSM::SetLocation(49.04599, 2.03347, 17) OSM::AddMarker(49.0446828398, 2.0349812508, -1, @MyPointer()) Repeat Event = WaitWindowEvent() - OSM::Event(Event) Select Event Case #PB_Event_CloseWindow : Quit = 1 @@ -1140,9 +1050,7 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; ExecutableFormat = Console -; CursorPosition = 1115 -; FirstLine = 1083 +; CursorPosition = 458 ; Folding = -------- ; EnableUnicode ; EnableThread From b4754a34ae3e838ec1150fb9df6fea13c06c4c28 Mon Sep 17 00:00:00 2001 From: djes Date: Wed, 3 Aug 2016 14:57:07 +0200 Subject: [PATCH 35/35] Renamed OSM to PBMap --- osm.pb => PBMap.pb | 470 +++++++++++++++++++++++---------------------- 1 file changed, 236 insertions(+), 234 deletions(-) rename osm.pb => PBMap.pb (68%) diff --git a/osm.pb b/PBMap.pb similarity index 68% rename from osm.pb rename to PBMap.pb index b1e3386..0034046 100644 --- a/osm.pb +++ b/PBMap.pb @@ -1,11 +1,13 @@ ;************************************************************** -; Program: OSM (OpenStreetMap Module) +; Program: PBMap +; Description: Permits the use of tiled maps like +; OpenStreetMap in a handy PureBASIC module ; Author: Thyphoon And Djes ; Date: Mai 17, 2016 ; License: Free, unrestricted, credit appreciated ; but not required. ; Note: Please share improvement ! -; Thanks: Progi1984, +; Thanks: Progi1984 ;************************************************************** CompilerIf #PB_Compiler_Thread = #False @@ -19,12 +21,12 @@ InitNetwork() UsePNGImageDecoder() UsePNGImageEncoder() -DeclareModule OSM +DeclareModule PBMap ;-Show debug infos Global Verbose = #True ;-Proxy ON/OFF Global Proxy = #True - Declare InitOSM() + Declare InitPBMap() Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) Declare Event(Event.l) Declare SetLocation(latitude.d, longitude.d, zoom = 15, mode.i = #PB_Absolute) @@ -42,7 +44,7 @@ DeclareModule OSM Declare.i GetZoom() EndDeclareModule -Module OSM +Module PBMap EnableExplicit @@ -64,9 +66,9 @@ Module OSM ;- Tile Structure Structure Tile Position.Position - OSMTileX.i - OSMTileY.i - OSMZoom.i + PBMapTileX.i + PBMapTileY.i + PBMapZoom.i nImage.i GetImageThread.i EndStructure @@ -74,9 +76,9 @@ Module OSM Structure DrawingParameters Position.Position Canvas.i - OSMTileX.i - OSMTileY.i - OSMZoom.i + PBMapTileX.i + PBMapTileY.i + PBMapZoom.i Mutex.i TargetLocation.Location CenterX.i @@ -109,8 +111,8 @@ Module OSM CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib) EndStructure - ;-OSM Structure - Structure OSM + ;-PBMap Structure + Structure PBMap Gadget.i ; Canvas Gadget Id Font.i ; Font to uses when write on the map TargetLocation.Location ; Latitude and Longitude from focus point @@ -141,7 +143,7 @@ Module OSM EditMarkerIndex.l EndStructure - Global OSM.OSM, Null.i + Global PBMap.PBMap, Null.i ;Shows an error msg and terminates the program Procedure Error(msg.s) @@ -216,25 +218,25 @@ Module OSM EndProcedure ;- *** - Procedure InitOSM() + Procedure InitPBMap() Protected Result.i If Verbose OpenConsole() EndIf - OSM\HDDCachePath = GetTemporaryDirectory() - OSM\ServerURL = "http://tile.openstreetmap.org/" - OSM\ZoomMin = 0 - OSM\ZoomMax = 18 - OSM\MoveStartingPoint\x = - 1 - OSM\TileSize = 256 - OSM\Dirty = #False - OSM\Drawing\Mutex = CreateMutex() - OSM\Drawing\Semaphore = CreateSemaphore() - OSM\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected - OSM\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold) + PBMap\HDDCachePath = GetTemporaryDirectory() + PBMap\ServerURL = "http://tile.openstreetmap.org/" + PBMap\ZoomMin = 0 + PBMap\ZoomMax = 18 + PBMap\MoveStartingPoint\x = - 1 + PBMap\TileSize = 256 + PBMap\Dirty = #False + PBMap\Drawing\Mutex = CreateMutex() + PBMap\Drawing\Semaphore = CreateSemaphore() + PBMap\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected + PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold) ;- Proxy details ;Use this to create and customize your preferences file for the first time - ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") + ; Result = CreatePreferences(GetHomeDirectory() + "PBMap.prefs") ; If Proxy ; PreferenceGroup("PROXY") ; WritePreferenceString("ProxyURL", "myproxy.fr") @@ -244,7 +246,7 @@ Module OSM ; If Result ; ClosePreferences() ; EndIf - Result = OpenPreferences(GetHomeDirectory() + "OSM.prefs") + Result = OpenPreferences(GetHomeDirectory() + "PBMap.prefs") If Proxy PreferenceGroup("PROXY") Global ProxyURL$ = ReadPreferenceString("ProxyURL", "") ;InputRequester("ProxyServer", "Do you use a Proxy Server? Then enter the full url:", "") @@ -257,24 +259,24 @@ Module OSM EndIf curl_global_init(#CURL_GLOBAL_WIN32); ;- Main drawing thread launching - OSM\MainDrawingThread = CreateThread(@DrawingThread(), @OSM\Drawing) - If OSM\MainDrawingThread = 0 + PBMap\MainDrawingThread = CreateThread(@DrawingThread(), @PBMap\Drawing) + If PBMap\MainDrawingThread = 0 Error("MapGadget : can't create main drawing thread.") EndIf EndProcedure Procedure Quit() - ;kill main drawing thread (nicer than KillThread(OSM\MainDrawingThread)) - LockMutex(OSM\Drawing\Mutex) - OSM\Drawing\End = #True - UnlockMutex(OSM\Drawing\Mutex) + ;kill main drawing thread (nicer than KillThread(PBMap\MainDrawingThread)) + LockMutex(PBMap\Drawing\Mutex) + PBMap\Drawing\End = #True + UnlockMutex(PBMap\Drawing\Mutex) ;wait for loading threads to finish nicely - ResetList( OSM\TilesThreads()) - While NextElement(OSM\TilesThreads()) - If IsThread(OSM\TilesThreads()\GetImageThread) = 0 - FreeMemory(OSM\TilesThreads()\Tile) - DeleteElement(OSM\TilesThreads()) - ResetList( OSM\TilesThreads()) + ResetList(PBMap\TilesThreads()) + While NextElement(PBMap\TilesThreads()) + If IsThread(PBMap\TilesThreads()\GetImageThread) = 0 + FreeMemory(PBMap\TilesThreads()\Tile) + DeleteElement(PBMap\TilesThreads()) + ResetList( PBMap\TilesThreads()) EndIf Wend curl_global_cleanup() @@ -296,17 +298,17 @@ Module OSM Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i) If Gadget = #PB_Any - OSM\Gadget = CanvasGadget(OSM\Gadget, X, Y, Width, Height) + PBMap\Gadget = CanvasGadget(PBMap\Gadget, X, Y, Width, Height) Else - OSM\Gadget = Gadget - CanvasGadget(OSM\Gadget, X, Y, Width, Height) + PBMap\Gadget = Gadget + CanvasGadget(PBMap\Gadget, X, Y, Width, Height) EndIf EndProcedure ;*** Converts coords to tile.decimal ;Warning, structures used in parameters are not tested Procedure LatLon2XY(*Location.Location, *Coords.Position) - Protected n.d = Pow(2.0, OSM\Zoom) + Protected n.d = Pow(2.0, PBMap\Zoom) Protected LatRad.d = Radian(*Location\Latitude) *Coords\x = n * ( (*Location\Longitude + 180.0) / 360.0) *Coords\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0 @@ -317,7 +319,7 @@ Module OSM ;*** Converts tile.decimal to coords ;Warning, structures used in parameters are not tested Procedure XY2LatLon(*Coords.Position, *Location.Location) - Protected n.d = Pow(2.0, OSM\Zoom) + Protected n.d = Pow(2.0, PBMap\Zoom) Protected LatitudeRad.d *Location\Longitude = *Coords\x / n * 360.0 - 180.0 LatitudeRad = ATan(SinH(#PI * (1.0 - 2.0 * *Coords\y / n))) @@ -343,8 +345,8 @@ Module OSM EndProcedure Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.PixelPosition) ; TODO to Optimize - Protected mapWidth.l = Pow(2, OSM\Zoom + 8) - Protected mapHeight.l = Pow(2, OSM\Zoom + 8) + Protected mapWidth.l = Pow(2, PBMap\Zoom + 8) + Protected mapHeight.l = Pow(2, PBMap\Zoom + 8) Protected x1.l,y1.l ; get x value x1 = (*Location\Longitude+180)*(mapWidth/360) @@ -354,14 +356,14 @@ Module OSM y1 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)) ; Protected x2.l, y2.l ; get x value - x2 = (OSM\TargetLocation\Longitude+180)*(mapWidth/360) + x2 = (PBMap\TargetLocation\Longitude+180)*(mapWidth/360) ; convert from degrees To radians - latRad = OSM\TargetLocation\Latitude*#PI/180; + latRad = PBMap\TargetLocation\Latitude*#PI/180; ; get y value mercN = Log(Tan((#PI/4)+(latRad/2))) y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)); - *Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1) - *Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1) + *Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1) + *Pixel\y=GadgetHeight(PBMap\Gadget)/2 - (y2-y1) EndProcedure Procedure LoadGpxFile(file.s) @@ -376,17 +378,17 @@ Module OSM Protected *MainNode,*subNode,*child,child.l *MainNode=MainXMLNode(0) *MainNode=XMLNodeFromPath(*MainNode,"/gpx/trk/trkseg") - ClearList(OSM\track()) + ClearList(PBMap\track()) For child = 1 To XMLChildCount(*MainNode) *child = ChildXMLNode(*MainNode, child) - AddElement(OSM\track()) + AddElement(PBMap\track()) If ExamineXMLAttributes(*child) While NextXMLAttribute(*child) Select XMLAttributeName(*child) Case "lat" - OSM\track()\Latitude=ValD(XMLAttributeValue(*child)) + PBMap\track()\Latitude=ValD(XMLAttributeValue(*child)) Case "lon" - OSM\track()\Longitude=ValD(XMLAttributeValue(*child)) + PBMap\track()\Longitude=ValD(XMLAttributeValue(*child)) EndSelect Wend EndIf @@ -397,9 +399,9 @@ Module OSM Procedure.i GetTileFromMem(Zoom.i, XTile.i, YTile.i) Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0") MyDebug("Check if we have this image in memory") - If FindMapElement(OSM\MemCache\Images(), key) + If FindMapElement(PBMap\MemCache\Images(), key) MyDebug("Key : " + key + " found !") - ProcedureReturn OSM\MemCache\Images()\nImage + ProcedureReturn PBMap\MemCache\Images()\nImage Else MyDebug("Key : " + key + " not found !") ProcedureReturn -1 @@ -423,7 +425,7 @@ Module OSM Protected *Buffer Protected nImage.i = -1 Protected FileHandle.i - Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" + Protected TileURL.s = PBMap\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" MyDebug("Check if we have this image on Web") If Proxy FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) @@ -454,16 +456,16 @@ Module OSM Procedure GetImageThread(*Tile.Tile) Protected nImage.i = -1 - Protected key.s = "Z" + RSet(Str(*Tile\OSMZoom), 4, "0") + "X" + RSet(Str(*Tile\OSMTileX), 8, "0") + "Y" + RSet(Str(*Tile\OSMTileY), 8, "0") - Protected CacheFile.s = OSM\HDDCachePath + "OSM_" + Str(*Tile\OSMZoom) + "_" + Str(*Tile\OSMTileX) + "_" + Str(*Tile\OSMTileY) + ".png" + Protected key.s = "Z" + RSet(Str(*Tile\PBMapZoom), 4, "0") + "X" + RSet(Str(*Tile\PBMapTileX), 8, "0") + "Y" + RSet(Str(*Tile\PBMapTileY), 8, "0") + Protected CacheFile.s = PBMap\HDDCachePath + "PBMap_" + Str(*Tile\PBMapZoom) + "_" + Str(*Tile\PBMapTileX) + "_" + Str(*Tile\PBMapTileY) + ".png" ;Adding the image to the cache if possible - AddMapElement(OSM\MemCache\Images(), key) + AddMapElement(PBMap\MemCache\Images(), key) nImage = GetTileFromHDD(CacheFile) If nImage = -1 - nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY, CacheFile) + nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, CacheFile) EndIf If nImage <> -1 - OSM\MemCache\Images(key)\nImage = nImage + PBMap\MemCache\Images(key)\nImage = nImage MyDebug("Image nb " + Str(nImage) + " successfully added to mem cache") MyDebug("With the following key : " + key) Else @@ -477,7 +479,7 @@ Module OSM Procedure DrawTile(*Tile.Tile) Protected x = *Tile\Position\x Protected y = *Tile\Position\y - MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX)) + MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\PBMapTileX) + " Y : " + Str(*Tile\PBMapTileX)) MyDebug(" at coords " + Str(x) + "," + Str(y)) MovePathCursor(x, y) DrawVectorImage(ImageID(*Tile\nImage)) @@ -487,17 +489,17 @@ Module OSM Protected x = *Tile\Position\x Protected y = *Tile\Position\y Protected Text$ = "Loading" - MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX)) + MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\PBMapTileX) + " Y : " + Str(*Tile\PBMapTileX)) MyDebug(" at coords " + Str(x) + "," + Str(y)) BeginVectorLayer() ;MovePathCursor(x, y) VectorSourceColor(RGBA(255, 255, 255, 128)) - AddPathBox(x, y, OSM\TileSize, OSM\TileSize) + AddPathBox(x, y, PBMap\TileSize, PBMap\TileSize) FillPath() MovePathCursor(x, y) - VectorFont(FontID(OSM\Font), OSM\TileSize / 20) + VectorFont(FontID(PBMap\Font), PBMap\TileSize / 20) VectorSourceColor(RGBA(150, 150, 150, 255)) - MovePathCursor(x + (OSM\TileSize - VectorTextWidth(Text$)) / 2, y + (OSM\TileSize - VectorTextHeight(Text$)) / 2) + MovePathCursor(x + (PBMap\TileSize - VectorTextWidth(Text$)) / 2, y + (PBMap\TileSize - VectorTextHeight(Text$)) / 2) DrawVectorText(Text$) EndVectorLayer() EndProcedure @@ -506,33 +508,33 @@ Module OSM Protected x.i, y.i Protected tx = Int(*Drawing\Position\x) ;Don't forget the Int() ! Protected ty = Int(*Drawing\Position\y) - Protected nx = *Drawing\CenterX / OSM\TileSize ;How many tiles around the point - Protected ny = *Drawing\CenterY / OSM\TileSize + Protected nx = *Drawing\CenterX / PBMap\TileSize ;How many tiles around the point + Protected ny = *Drawing\CenterY / PBMap\TileSize MyDebug("Drawing tiles") For y = - ny - 1 To ny + 1 For x = - nx - 1 To nx + 1 ;Was quiting the loop if a move occured, giving maybe smoother movement - ;If OSM\Moving + ;If PBMap\Moving ; Break 2 ;EndIf Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile)) If *NewTile With *NewTile ;Keep a track of tiles (especially to free memory) - AddElement(OSM\TilesThreads()) - OSM\TilesThreads()\Tile = *NewTile + AddElement(PBMap\TilesThreads()) + PBMap\TilesThreads()\Tile = *NewTile ;New tile parameters - \Position\x = *Drawing\CenterX + x * OSM\TileSize - *Drawing\DeltaX - \Position\y = *Drawing\CenterY + y * OSM\TileSize - *Drawing\DeltaY - \OSMTileX = tx + x - \OSMTileY = ty + y - \OSMZoom = OSM\Zoom + \Position\x = *Drawing\CenterX + x * PBMap\TileSize - *Drawing\DeltaX + \Position\y = *Drawing\CenterY + y * PBMap\TileSize - *Drawing\DeltaY + \PBMapTileX = tx + x + \PBMapTileY = ty + y + \PBMapZoom = PBMap\Zoom ;Check if the image exists - \nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY) + \nImage = GetTileFromMem(\PBMapZoom, \PBMapTileX, \PBMapTileY) If \nImage = -1 ;If not, load it in the background \GetImageThread = CreateThread(@GetImageThread(), *NewTile) - OSM\TilesThreads()\GetImageThread = \GetImageThread + PBMap\TilesThreads()\GetImageThread = \GetImageThread MyDebug(" Creating get image thread nb " + Str(\GetImageThread)) EndIf If IsImage(\nImage) @@ -551,10 +553,10 @@ Module OSM Next ;Free tile memory when the loading thread has finished ;TODO : get out this proc from drawtiles in a special "free ressources" task - ForEach OSM\TilesThreads() - If IsThread(OSM\TilesThreads()\GetImageThread) = 0 - FreeMemory(OSM\TilesThreads()\Tile) - DeleteElement(OSM\TilesThreads()) + ForEach PBMap\TilesThreads() + If IsThread(PBMap\TilesThreads()\GetImageThread) = 0 + FreeMemory(PBMap\TilesThreads()\Tile) + DeleteElement(PBMap\TilesThreads()) EndIf Next EndProcedure @@ -586,7 +588,7 @@ Module OSM VectorSourceColor(RGBA(255, 255, 255, 255)) AddPathCircle(x,y-20,12) FillPath() - VectorFont(FontID(OSM\Font), 13) + VectorFont(FontID(PBMap\Font), 13) MovePathCursor(x-VectorTextWidth(Str(dist))/2, y-20-VectorTextHeight(Str(dist))/2) VectorSourceColor(RGBA(0, 0, 0, 255)) DrawVectorText(Str(dist)) @@ -596,13 +598,13 @@ Module OSM Protected Pixel.PixelPosition Protected Location.Location Protected km.f, memKm.i - If ListSize(OSM\track())>0 + If ListSize(PBMap\track())>0 ;Trace Track - LockMutex(OSM\Drawing\Mutex) - ForEach OSM\track() + LockMutex(PBMap\Drawing\Mutex) + ForEach PBMap\track() If *Drawing\TargetLocation\Latitude<>0 And *Drawing\TargetLocation\Longitude<>0 - GetPixelCoordFromLocation(@OSM\track(),@Pixel) - If ListIndex(OSM\track())=0 + GetPixelCoordFromLocation(@PBMap\track(),@Pixel) + If ListIndex(PBMap\track())=0 MovePathCursor(Pixel\X, Pixel\Y) Else AddPathLine(Pixel\X, Pixel\Y) @@ -612,50 +614,50 @@ Module OSM VectorSourceColor(RGBA(0, 255, 0, 150)) StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) ;Draw Distance - ForEach OSM\track() + ForEach PBMap\track() ;-Test Distance - If ListIndex(OSM\track())=0 - Location\Latitude=OSM\track()\Latitude - Location\Longitude=OSM\track()\Longitude + If ListIndex(PBMap\track())=0 + Location\Latitude=PBMap\track()\Latitude + Location\Longitude=PBMap\track()\Longitude Else - km=km+HaversineInKM(@Location,@OSM\track()) ;<- display Distance - Location\Latitude=OSM\track()\Latitude - Location\Longitude=OSM\track()\Longitude + km=km+HaversineInKM(@Location,@PBMap\track()) ;<- display Distance + Location\Latitude=PBMap\track()\Latitude + Location\Longitude=PBMap\track()\Longitude EndIf - GetPixelCoordFromLocation(@OSM\track(),@Pixel) + GetPixelCoordFromLocation(@PBMap\track(),@Pixel) If Int(km)<>memKm memKm=Int(km) - If OSM\Zoom>10 + If PBMap\Zoom>10 BeginVectorLayer() TrackPointer(Pixel\X , Pixel\Y,Int(km)) EndVectorLayer() EndIf EndIf Next - UnlockMutex(OSM\Drawing\Mutex) + UnlockMutex(PBMap\Drawing\Mutex) EndIf EndProcedure ; Add a Marker To the Map Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1) - AddElement(OSM\Marker()) - OSM\Marker()\Location\Latitude=Latitude - OSM\Marker()\Location\Longitude=Longitude - OSM\Marker()\color=color - OSM\Marker()\CallBackPointer = CallBackPointer + AddElement(PBMap\Marker()) + PBMap\Marker()\Location\Latitude=Latitude + PBMap\Marker()\Location\Longitude=Longitude + PBMap\Marker()\color=color + PBMap\Marker()\CallBackPointer = CallBackPointer EndProcedure ; Draw all markers on the screen ! Procedure DrawMarker(*Drawing.DrawingParameters) Protected Pixel.PixelPosition - ForEach OSM\Marker() - If OSM\Marker()\Location\Latitude <> 0 And OSM\Marker()\Location\Longitude <> 0 - GetPixelCoordFromLocation(OSM\Marker()\Location, @Pixel) - If Pixel\X >= 0 And Pixel\Y >= 0 And Pixel\X < GadgetWidth(OSM\Gadget) And Pixel\Y < GadgetHeight(OSM\Gadget) ; Only if visible ^_^ - If OSM\Marker()\CallBackPointer > 0 - CallFunctionFast(OSM\Marker()\CallBackPointer, Pixel\X, Pixel\Y) + ForEach PBMap\Marker() + If PBMap\Marker()\Location\Latitude <> 0 And PBMap\Marker()\Location\Longitude <> 0 + GetPixelCoordFromLocation(PBMap\Marker()\Location, @Pixel) + If Pixel\X >= 0 And Pixel\Y >= 0 And Pixel\X < GadgetWidth(PBMap\Gadget) And Pixel\Y < GadgetHeight(PBMap\Gadget) ; Only if visible ^_^ + If PBMap\Marker()\CallBackPointer > 0 + CallFunctionFast(PBMap\Marker()\CallBackPointer, Pixel\X, Pixel\Y) Else - Pointer(Pixel\X, Pixel\Y, OSM\Marker()\color) + Pointer(Pixel\X, Pixel\Y, PBMap\Marker()\color) EndIf EndIf EndIf @@ -675,17 +677,17 @@ Module OSM CopyStructure(*SharedDrawing, @Drawing, DrawingParameters) UnlockMutex(*SharedDrawing\Mutex) ;Precalc some values - Drawing\CenterX = GadgetWidth(OSM\Gadget) / 2 - Drawing\CenterY = GadgetHeight(OSM\Gadget) / 2 + Drawing\CenterX = GadgetWidth(PBMap\Gadget) / 2 + Drawing\CenterY = GadgetHeight(PBMap\Gadget) / 2 ;Pixel shift, aka position in the tile Px = Drawing\Position\x : Py = Drawing\Position\y - Drawing\DeltaX = Px * OSM\TileSize - (Int(Px) * OSM\TileSize) ;Don't forget the Int() ! - Drawing\DeltaY = Py * OSM\TileSize - (Int(Py) * OSM\TileSize) - Drawing\TargetLocation\Latitude = OSM\TargetLocation\Latitude - Drawing\TargetLocation\Longitude = OSM\TargetLocation\Longitude + Drawing\DeltaX = Px * PBMap\TileSize - (Int(Px) * PBMap\TileSize) ;Don't forget the Int() ! + Drawing\DeltaY = Py * PBMap\TileSize - (Int(Py) * PBMap\TileSize) + Drawing\TargetLocation\Latitude = PBMap\TargetLocation\Latitude + Drawing\TargetLocation\Longitude = PBMap\TargetLocation\Longitude Drawing\Dirty = #False ;Main drawing stuff - StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) + StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget)) DrawTiles(@Drawing) DrawTrack(@Drawing) DrawMarker(@Drawing) @@ -707,32 +709,32 @@ Module OSM EndProcedure Procedure Refresh() - SignalSemaphore(OSM\Drawing\Semaphore) + SignalSemaphore(PBMap\Drawing\Semaphore) EndProcedure Procedure SetLocation(latitude.d, longitude.d, zoom = 15, Mode.i = #PB_Absolute) Select Mode Case #PB_Absolute - OSM\TargetLocation\Latitude = latitude - OSM\TargetLocation\Longitude = longitude - OSM\Zoom = zoom + PBMap\TargetLocation\Latitude = latitude + PBMap\TargetLocation\Longitude = longitude + PBMap\Zoom = zoom Case #PB_Relative - OSM\TargetLocation\Latitude + latitude - OSM\TargetLocation\Longitude + longitude - OSM\Zoom + zoom + PBMap\TargetLocation\Latitude + latitude + PBMap\TargetLocation\Longitude + longitude + PBMap\Zoom + zoom EndSelect - If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf - If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf - LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) + If PBMap\Zoom > PBMap\ZoomMax : PBMap\Zoom = PBMap\ZoomMax : EndIf + If PBMap\Zoom < PBMap\ZoomMin : PBMap\Zoom = PBMap\ZoomMin : EndIf + LatLon2XY(@PBMap\TargetLocation, @PBMap\Drawing) ;Convert X, Y in tile.decimal into real pixels - OSM\Position\x = OSM\Drawing\Position\x * OSM\TileSize - OSM\Position\y = OSM\Drawing\Position\y * OSM\TileSize - OSM\Drawing\PassNb = 1 + PBMap\Position\x = PBMap\Drawing\Position\x * PBMap\TileSize + PBMap\Position\y = PBMap\Drawing\Position\y * PBMap\TileSize + PBMap\Drawing\PassNb = 1 ;Start drawing - SignalSemaphore(OSM\Drawing\Semaphore) + SignalSemaphore(PBMap\Drawing\Semaphore) ;*** - If OSM\CallBackLocation > 0 - CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) + If PBMap\CallBackLocation > 0 + CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation) EndIf EndProcedure @@ -740,18 +742,18 @@ Module OSM ;Source => http://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map ;bounding box in long/lat coords (x=long, y=lat) Protected MinY.d,MaxY.d,MinX.d,MaxX.d - ForEach OSM\track() - If ListIndex(OSM\track())=0 Or OSM\track()\LongitudeMaxX - MaxX=OSM\track()\Longitude + If ListIndex(PBMap\track())=0 Or PBMap\track()\Longitude>MaxX + MaxX=PBMap\track()\Longitude EndIf - If ListIndex(OSM\track())=0 Or OSM\track()\LatitudeMaxY - MaxY=OSM\track()\Latitude + If ListIndex(PBMap\track())=0 Or PBMap\track()\Latitude>MaxY + MaxY=PBMap\track()\Latitude EndIf Next Protected DeltaX.d=MaxX-MinX ;assumption ! In original code DeltaX have no source @@ -761,71 +763,71 @@ Module OSM Protected ry2.d = Log((Sin(Radian(MaxY)) + 1) / Cos(Radian(MaxY))) Protected ryc.d = (ry1 + ry2) / 2 Protected centerY.d = Degree(ATan(SinH(ryc))) - Protected resolutionHorizontal.d = DeltaX / GadgetWidth(OSM\Gadget) + Protected resolutionHorizontal.d = DeltaX / GadgetWidth(PBMap\Gadget) Protected vy0.d = Log(Tan(#PI*(0.25 + centerY/360))); Protected vy1.d = Log(Tan(#PI*(0.25 + MaxY/360))) ; - Protected viewHeightHalf.d = GadgetHeight(OSM\Gadget)/2; + Protected viewHeightHalf.d = GadgetHeight(PBMap\Gadget)/2; Protected zoomFactorPowered.d = viewHeightHalf / (40.7436654315252*(vy1 - vy0)) - Protected resolutionVertical.d = 360.0 / (zoomFactorPowered * OSM\TileSize) + Protected resolutionVertical.d = 360.0 / (zoomFactorPowered * PBMap\TileSize) If resolutionHorizontal<>0 And resolutionVertical<>0 Protected resolution.d = Max(resolutionHorizontal, resolutionVertical)* paddingFactor - Protected zoom.d = Log(360 / (resolution * OSM\TileSize))/Log(2) + Protected zoom.d = Log(360 / (resolution * PBMap\TileSize))/Log(2) Protected lon.d = centerX; Protected lat.d = centerY; SetLocation(lat,lon, Round(zoom,#PB_Round_Down)) Else - SetLocation(OSM\TargetLocation\Latitude,OSM\TargetLocation\Longitude, 15) + SetLocation(PBMap\TargetLocation\Latitude,PBMap\TargetLocation\Longitude, 15) EndIf EndProcedure Procedure SetZoom(Zoom.i, mode.i = #PB_Relative) Select mode Case #PB_Relative - OSM\Zoom = OSM\Zoom + zoom + PBMap\Zoom = PBMap\Zoom + zoom Case #PB_Absolute - OSM\Zoom = zoom + PBMap\Zoom = zoom EndSelect - If OSM\Zoom > OSM\ZoomMax : OSM\Zoom = OSM\ZoomMax : EndIf - If OSM\Zoom < OSM\ZoomMin : OSM\Zoom = OSM\ZoomMin : EndIf - LatLon2XY(@OSM\TargetLocation, @OSM\Drawing) + If PBMap\Zoom > PBMap\ZoomMax : PBMap\Zoom = PBMap\ZoomMax : EndIf + If PBMap\Zoom < PBMap\ZoomMin : PBMap\Zoom = PBMap\ZoomMin : EndIf + LatLon2XY(@PBMap\TargetLocation, @PBMap\Drawing) ;Convert X, Y in tile.decimal into real pixels - OSM\Position\X = OSM\Drawing\Position\x * OSM\TileSize - OSM\Position\Y = OSM\Drawing\Position\y * OSM\TileSize + PBMap\Position\X = PBMap\Drawing\Position\x * PBMap\TileSize + PBMap\Position\Y = PBMap\Drawing\Position\y * PBMap\TileSize ;*** Creates a drawing thread and fill parameters - OSM\Drawing\PassNb = 1 + PBMap\Drawing\PassNb = 1 ;Start drawing - SignalSemaphore(OSM\Drawing\Semaphore) + SignalSemaphore(PBMap\Drawing\Semaphore) ;*** - If OSM\CallBackLocation > 0 - CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) + If PBMap\CallBackLocation > 0 + CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation) EndIf EndProcedure Procedure SetCallBackLocation(CallBackLocation.i) - OSM\CallBackLocation = CallBackLocation + PBMap\CallBackLocation = CallBackLocation EndProcedure Procedure.d GetLatitude() Protected Value.d - LockMutex(OSM\Drawing\Mutex) - Value = OSM\TargetLocation\Latitude - UnlockMutex(OSM\Drawing\Mutex) + LockMutex(PBMap\Drawing\Mutex) + Value = PBMap\TargetLocation\Latitude + UnlockMutex(PBMap\Drawing\Mutex) ProcedureReturn Value EndProcedure Procedure.d GetLongitude() Protected Value.d - LockMutex(OSM\Drawing\Mutex) - Value = OSM\TargetLocation\Longitude - UnlockMutex(OSM\Drawing\Mutex) + LockMutex(PBMap\Drawing\Mutex) + Value = PBMap\TargetLocation\Longitude + UnlockMutex(PBMap\Drawing\Mutex) ProcedureReturn Value EndProcedure Procedure.i GetZoom() Protected Value.d - LockMutex(OSM\Drawing\Mutex) - Value = OSM\Zoom - UnlockMutex(OSM\Drawing\Mutex) + LockMutex(PBMap\Drawing\Mutex) + Value = PBMap\Zoom + UnlockMutex(PBMap\Drawing\Mutex) ProcedureReturn Value EndProcedure @@ -834,82 +836,82 @@ Module OSM Protected MouseX.i, MouseY.i Protected Marker.Position Protected *Drawing.DrawingParameters - If IsGadget(OSM\Gadget) And GadgetType(OSM\Gadget) = #PB_GadgetType_Canvas + If IsGadget(PBMap\Gadget) And GadgetType(PBMap\Gadget) = #PB_GadgetType_Canvas Select Event Case #PB_Event_Gadget ;{ Gadget = EventGadget() Select Gadget - Case OSM\Gadget + Case PBMap\Gadget Select EventType() Case #PB_EventType_LeftButtonDown ;Check if we select a marker - MouseX = OSM\Position\x - GadgetWidth(OSM\Gadget) / 2 + GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - MouseY = OSM\Position\y - GadgetHeight(OSM\Gadget) / 2 + GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - ForEach OSM\Marker() - LatLon2XY(@OSM\Marker()\Location, @Marker) - Marker\x * OSM\TileSize - Marker\y * OSM\TileSize + MouseX = PBMap\Position\x - GadgetWidth(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) + MouseY = PBMap\Position\y - GadgetHeight(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) + ForEach PBMap\Marker() + LatLon2XY(@PBMap\Marker()\Location, @Marker) + Marker\x * PBMap\TileSize + Marker\y * PBMap\TileSize If Distance(Marker\x, Marker\y, MouseX, MouseY) < 8 - OSM\EditMarkerIndex = ListIndex(OSM\Marker()) + PBMap\EditMarkerIndex = ListIndex(PBMap\Marker()) Break EndIf Next ;Mem cursor Coord - OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) + PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) + PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) Case #PB_EventType_MouseMove - If OSM\MoveStartingPoint\x <> - 1 - MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x - MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y - OSM\Moving = #True + If PBMap\MoveStartingPoint\x <> - 1 + MouseX = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) - PBMap\MoveStartingPoint\x + MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\MoveStartingPoint\y + PBMap\Moving = #True ;move Marker - If OSM\EditMarkerIndex > -1 - SelectElement(OSM\Marker(), OSM\EditMarkerIndex) - LatLon2XY(@OSM\Marker()\Location, @Marker) - Marker\x + MouseX / OSM\TileSize - Marker\y + MouseY / OSM\TileSize - XY2LatLon(@Marker, @OSM\Marker()\Location) + If PBMap\EditMarkerIndex > -1 + SelectElement(PBMap\Marker(), PBMap\EditMarkerIndex) + LatLon2XY(@PBMap\Marker()\Location, @Marker) + Marker\x + MouseX / PBMap\TileSize + Marker\y + MouseY / PBMap\TileSize + XY2LatLon(@Marker, @PBMap\Marker()\Location) Else ;New move values - OSM\Position\x - MouseX - OSM\Position\y - MouseY + PBMap\Position\x - MouseX + PBMap\Position\y - MouseY ;-*** Fill parameters and signal the drawing thread - LockMutex(OSM\Drawing\Mutex) - ;OSM tile position in tile.decimal - OSM\Drawing\Position\x = OSM\Position\x / OSM\TileSize - OSM\Drawing\Position\y = OSM\Position\y / OSM\TileSize - OSM\Drawing\PassNb = 1 - XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) + LockMutex(PBMap\Drawing\Mutex) + ;PBMap tile position in tile.decimal + PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize + PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize + PBMap\Drawing\PassNb = 1 + XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation) ;If CallBackLocation send Location to function - If OSM\CallBackLocation > 0 - CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation) + If PBMap\CallBackLocation > 0 + CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation) EndIf - UnlockMutex(OSM\Drawing\Mutex) + UnlockMutex(PBMap\Drawing\Mutex) EndIf ;Start drawing - SignalSemaphore(OSM\Drawing\Semaphore) + SignalSemaphore(PBMap\Drawing\Semaphore) ;- *** - OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) + PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) + PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) EndIf Case #PB_EventType_LeftButtonUp - OSM\Moving = #False - OSM\MoveStartingPoint\x = - 1 - If OSM\EditMarkerIndex > -1 - OSM\EditMarkerIndex = -1 + PBMap\Moving = #False + PBMap\MoveStartingPoint\x = - 1 + If PBMap\EditMarkerIndex > -1 + PBMap\EditMarkerIndex = -1 Else ;Move Map - LockMutex(OSM\Drawing\Mutex) - OSM\Drawing\Position\x = OSM\Position\x / OSM\TileSize - OSM\Drawing\Position\y = OSM\Position\y / OSM\TileSize - MyDebug("OSM\Drawing\Position\x " + Str(OSM\Drawing\Position\x) + " ; OSM\Drawing\Position\y " + Str(OSM\Drawing\Position\y) ) - XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) - UnlockMutex(OSM\Drawing\Mutex) + LockMutex(PBMap\Drawing\Mutex) + PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize + PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize + MyDebug("PBMap\Drawing\Position\x " + Str(PBMap\Drawing\Position\x) + " ; PBMap\Drawing\Position\y " + Str(PBMap\Drawing\Position\y) ) + XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation) + UnlockMutex(PBMap\Drawing\Mutex) EndIf EndSelect EndSelect EndSelect Else - MessageRequester("Module OSM", "You must use OSMGadget before", #PB_MessageRequester_Ok ) + MessageRequester("Module PBMap", "You must use PBMapGadget before", #PB_MessageRequester_Ok ) End EndIf @@ -980,7 +982,7 @@ CompilerIf #PB_Compiler_IsMainFile ResizeGadget(#Text_4,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_AddMarker,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) - OSM::Refresh() + PBMap::Refresh() EndProcedure ;- MAIN TEST @@ -1008,49 +1010,49 @@ CompilerIf #PB_Compiler_IsMainFile Define pfValue.d ;Our main gadget - OSM::InitOSM() - OSM::MapGadget(#Map, 10, 10, 512, 512) - OSM::SetCallBackLocation(@UpdateLocation()) - OSM::SetLocation(49.04599, 2.03347, 17) - OSM::AddMarker(49.0446828398, 2.0349812508, -1, @MyPointer()) + PBMap::InitPBMap() + PBMap::MapGadget(#Map, 10, 10, 512, 512) + PBMap::SetCallBackLocation(@UpdateLocation()) + PBMap::SetLocation(49.04599, 2.03347, 17) + PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyPointer()) Repeat Event = WaitWindowEvent() - OSM::Event(Event) + PBMap::Event(Event) Select Event Case #PB_Event_CloseWindow : Quit = 1 Case #PB_Event_Gadget ;{ Gadget = EventGadget() Select Gadget Case #Gdt_Up - OSM::SetLocation(10* 360 / Pow(2, OSM::GetZoom() + 8), 0, 0, #PB_Relative) + PBMap::SetLocation(10* 360 / Pow(2, PBMap::GetZoom() + 8), 0, 0, #PB_Relative) Case #Gdt_Down - OSM::SetLocation(10* -360 / Pow(2, OSM::GetZoom() + 8), 0, 0, #PB_Relative) + PBMap::SetLocation(10* -360 / Pow(2, PBMap::GetZoom() + 8), 0, 0, #PB_Relative) Case #Gdt_Left - OSM::SetLocation(0, 10* -360 / Pow(2, OSM::GetZoom() + 8), 0, #PB_Relative) + PBMap::SetLocation(0, 10* -360 / Pow(2, PBMap::GetZoom() + 8), 0, #PB_Relative) Case #Gdt_Right - OSM::SetLocation(0, 10* 360 / Pow(2, OSM::GetZoom() + 8), 0, #PB_Relative) + PBMap::SetLocation(0, 10* 360 / Pow(2, PBMap::GetZoom() + 8), 0, #PB_Relative) Case #Button_4 - OSM::SetZoom(1) + PBMap::SetZoom(1) Case #Button_5 - OSM::SetZoom( - 1) + PBMap::SetZoom( - 1) Case #Gdt_LoadGpx - OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) - OSM::ZoomToArea() ; <-To center the view, and to viex all the track + PBMap::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) + PBMap::ZoomToArea() ; <-To center the view, and to viex all the track Case #Gdt_AddMarker - OSM:: AddMarker(ValD(GetGadgetText(#String_0)),ValD(GetGadgetText(#String_1)),RGBA(Random(255),Random(255),Random(255),255)) + PBMap:: AddMarker(ValD(GetGadgetText(#String_0)),ValD(GetGadgetText(#String_1)),RGBA(Random(255),Random(255),Random(255),255)) EndSelect Case #PB_Event_SizeWindow ResizeAll() EndSelect Until Quit = #True - OSM::Quit() + PBMap::Quit() EndIf CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 458 +; CursorPosition = 8 ; Folding = -------- ; EnableUnicode ; EnableThread