ReFran Posted April 15, 2011 Share Posted April 15, 2011 (edited) Hi, for the map moving/scrolling I've used up to now Accel-Keys (ctl+right/l/u/p for 5px step and ctl+pgUp/dn tabs for page scroll). Now I put scrollbars on the GUI (based on helpfile example) and used the same function mapScroll to scroll the map. It works basicly, but no min max and also I've the feeling that the wrong GUI is scrolled. I work with 3 GUI's. On the mainGUI I placed a mapGUI(sized fixed based on mainGUI) and on that I placed mapTileGUI (size based on tilesize) which works as container for the maptiles png files. The HScrollbar I placed as own "$scrollhor" GUI on the mainGuI (based on Martins stringgrid expl.), the VScollbar I placed on the mapGUI. Perhaps someone who nows how scrollbars real works - I don't - can have a look at it. best regards, Reinhard expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #Include <WinAPI.au3> #Include <Math.au3> #Include <GUIComboBox.au3> #include <Misc.au3> #include <ScrollBarConstants.au3> #include <GUIScrollBars.au3> ;; author: ReFran - autoIt-Forum ;; thread: http://www.autoitscript.com/forum/topic/126194-internet-maps-tiles-viewer-project-study/ #region toDo ; mapAddress update after move (keep start, forward/backwards button) ; mapgeo language set, dann Münster und nicht Muenster ; mapgeo ini ; mapmove by pixel (keys/mouse) ; scrollbars ; resizing ; batch download of maps (different zoos #endregion toDo ;; app related (mt = map tiles, arrays mostly 1 based DIM $mtSize = 256 ;tile size in pixel DIM $mtiRows = 5, $mtiCols = 5 DIM $mtFileNo = $mtiRows*$mtiCols+1, $mtFile[$mtFileNo], $mtImg[$mtFileNo] DIM $tileNoActiv, $zoom = 13, $quad DIM $mapScale_arr[17] $mapScale_arr[0] = 591659008 mapScaleCalc() DIM $mSSPx = 5 DIM $ttqvSaveDir = @scriptdir&"\maps\" ,$TtqvSaveFn="" DIM $ttqvSaveFx = "jpg" ; can be pgn (=>no convert) jpg, bmp DIM $pawSaveDir = @scriptdir&"\maps\", $pawSaveFn="", $Inp_pawSaveDir DIM $cachePath = @scriptdir&"\cache\" DIM $cacheState = 2 ; 0=not installed 1= don't cache maptiles; 2=use cache (should be standard) DIM $geoBase = "Deutschland" ;take this if address is blank DIM $geoURL = "http://maps.google.com/maps/geo?q={A}&output=csv" ;; {A} = placeholder for Address (real post/geo-addr. or GeoPoint(Lat,Lon) for reverse geocoding ;"MapPvId||MapPvName||MapPvUrl" &@lf _ ;|| because at least one URL contains "|" DIM $mapPv_str= "OC||Osm Cycle map||http://andy.sandbox.cloudmade.com/tiles/cycle/{Z}/{X}/{Y}.png" &@lf _ & "OM||Osm Mapnik map||http://tile.openstreetmap.org/{Z}/{X}/{Y}.png" &@lf _ & "OO||Osm Osmarender||http://tah.openstreetmap.org/Tiles/tile/{Z}/{X}/{Y}.png" &@lf _ & "OV||Osm VPN B&B map (NotAll)||http://tile.xn--pnvkarte-m4a.de/tilegen/{Z}/{X}/{Y}.png" &@lf _ & "--||--------------||http://tah.openstreetmap.org/Tiles/tile/{Z}/{X}/{Y}.png" &@lf _ & "GR||Google Roadmap||http://mt3.google.com/vt/x={X}&y={Y}&z={Z}" &@lf _ & "GT||Google Terrain||http://khm.google.com/vt/lbw/lyrs=p&x={X}&y={Y}&z={Z}" &@lf _ & "GH||Google Hybrid||http://mt1.google.com/vt/lyrs=y&x={X}&y={Y}&z={Z}" &@lf _ & "GS||Google Satelite||http://khm1.google.com/kh/v=49&x={X}&y={Y}&z={Z}" &@lf _ & "GN||Google Night||http://mt1.google.com/vt/lyrs=h@130&hl=de&src=api&x={X}&y={Y}&z={Z}" &@lf _ & "--||--------------||http://tah.openstreetmap.org/Tiles/tile/{Z}/{X}/{Y}.png" &@lf _ & "BM||Bing Roadmap||http://ecn.t0.tiles.virtualearth.net/tiles/r{Q}.png?g=441&mkt=de-de&n=z";&@lf _ ;& "YR||Yahoo Roadmap||http://maps1.yimg.com/hx/tl?v=4.2&x={X}&y={Y}&z={Z}" ;; placeholders: {Z} zoom based on GMAP-zoom, {X} tileNoX calc'ed from Lon; {Y} tileNoY calc'ed from Lat; {Q} Bing Quad ;; defined as string for later use with ini DIM $mapPv_arr= stringSplit($mapPv_str,@lf) DIM $mapPvIdDefault = "OM" ;set preferred maptype DIM $mapPvId, $mapPvName, $mapPvURL DIM $autoRedraw = 1 ;used to switch out autoredraw DIM $timeOutMapDnl = 5 ;in sec DIM $pi = 3.14159265358979 ;; GUI related Dim $mainGUI, $MainGuiTitle = @scriptname, $mapGui,$mTileGui, $mtileCanvas, $Inp_Addr, $dino Dim $mgw = 1200, $mgh = 800, $mgt , $mgtDelta DIM $lab_cache,$chb_cache,$inp_mtMoveStep,$cmb_mapType #region MainMenuLoop mainGui() Func MainGui() $mainGUI = GUICreate($MainGuiTitle, $mgw, $mgh, 20, -1, _ $WS_OVERLAPPEDWINDOW +$WS_CLIPCHILDREN + $WS_CLIPSIBLINGS) GUISetStyle(BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SIZEBOX, $WS_SYSMENU)) $scrollhor = GUICreate("scrollhor",$mgw-200,17,$mgw-($mgw-200)-2,$mgh-160+1, $WS_CHILD,-1, $mainGui) ;GUISetBkColor(0x808080) ;GUISetState() _GUIScrollBars_Init($scrollhor) _GUIScrollBars_SetScrollInfoMax($scrollhor, $SB_HORZ, $mtiCols*$mtsize);this can be the grid width _GUIScrollBars_SetScrollInfoPage($scrollhor, $SB_HORZ, $mtiCols*$mtsize / 2.6);this can be the cellsparent width rounded to integral column width GUICtrlCreateButton("Test",$mgw-200,0,17,17) GUISetState() Guiswitch($mainGui) ;; definition of tabs $mainTab = GUICtrlCreateTab(2, $mgh-155,$mgw-2,$mgh-645) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER) $mainTab1 = GUICtrlCreateTabItem("View") $Inp_Addr = GuiCtrlCreateCombo("Wesel,de",5,$mgh-150+30,220,18) GuiCtrlsetdata(-1,"Bocholt,de|Venlo,nl|Taverne on the Green, New York, US|Hofbraeuhaus, Muenchen, DE|Zum Frosch, Prag, cz") GUICtrlSetTip(-1, "Real Address (google maps format) or lat,lon"&@lf&"e.g.=street,town,country; "&@lf&"e.g.: 51.1,6.2)") $cmb_Zoom = GUICtrlCreateCombo("",230, $mgh-150+30,40,18) GuiCtrlsetdata(-1,"16|15|14|13|12|11|10","13") GUICtrlSetTip(-1, "Zoom (google based)"&@lf&"13= 1:72,2 KM; "&@lf&"14=1:36,1 Km)") $inp_zoom = GUICtrlCreateInput(0,272,$mgh-150+30,19,22) $udn_zoom = GUICtrlCreateUpdown($inp_zoom) $dino = GUICtrlCreateIcon(@WindowsDir & "\cursors\dinosaur.ani",-1, 305, $mgh-150+25,28, 28) $cmb_mapType = GuiCtrlCreateCombo("",5,$mgh-150+30+30,220,18) ;GuiCtrlsetdata(-1,"[OM] Osm Mapnik|[OC] Osm Cycle map|[OO] Osm Osmarender","[OM] Osm Mapnik") $cmb_mapTiles = GuiCtrlCreateCombo("",230,$mgh-150+30+30,62,18) GuiCtrlsetdata(-1,"3x5|5x5|7x7|9x9|","3x5") GUICtrlSetTip(-1, "Tiles Matrix rows x cols; 1 tile = 256 pixel") $btn_go =GUICtrlCreateButton("GO",305,$mgh-150+30+30,30,20) $btn_dnl = "";GUICtrlCreateButton("dnl",230,$mgh-150+30+30,30,30) $btn_mUp =GUICtrlCreateButton("Up",$mgw-100,$mgh-150+30,20,20) $btn_mDown =GUICtrlCreateButton("Dn",$mgw-100,$mgh-150+30+30,20,20) $btn_mleft =GUICtrlCreateButton("<-",$mgw-125,$mgh-150+30+15,20,20) $btn_mRight =GUICtrlCreateButton("->",$mgw-75,$mgh-150+30+15,20,20) $inp_mtMoveStep = GUICtrlCreateInput("1",$mgw-170,$mgh-150+30+15, 35, 20) $udn_mtMoveStep = GUICtrlCreateUpdown($inp_mtMoveStep) $lab_cache = GUICtrlCreateLabel("Cache",5,$mgh-30,220,18,$SS_SUNKEN) $chb_cache = GUICtrlCreateCheckbox("",230, $mgh-30,40,18) GUICtrlSetState ( -1, $GUI_CHECKED ) GUICtrlSetTip(-1, "Switch cache on/off") $btn_printMap = GUICtrlCreateButton("Print",$mgw-170,$mgh-30,50,20) $btn_saveMap = GUICtrlCreateButton("Save",$mgw-120,$mgh-30,50,20) $btn_dummy = GUICtrlCreateDummy() $mainTab2 = GUICtrlCreateTabItem("Files") $Lab_Ttqvlab = GuiCtrlCreateLabel("TTQV",5,$mgh-150+30,40,18) $Inp_TtqvSaveDir = GuiCtrlCreateInput($ttqvSaveDir,5+45,$mgh-150+30,220,18) $Inp_TtqvSaveFn = GuiCtrlCreateInput($mapPvIdDefault&"_xxxx_"&$zoom&"."&$ttqvSaveFx,230+45,$mgh-150+30,220,18) $Lab_pawlab = GuiCtrlCreateLabel("paw",5,$mgh-150+30+30,40,18) $Inp_pawSaveDir = GuiCtrlCreateInput($pawSaveDir,5+45,$mgh-150+30+30,220,18) ;$Inp_pawSaveFn = GuiCtrlCreateInput($mapPvIdDefault&"_xxxx_"&$zoom&".jpg",230+45,$mgh-150+30+30,220,18) GUICtrlCreateTabItem("") ; Set accelerators test $key_mRight = GUICtrlCreateDummy() $key_mLeft = GUICtrlCreateDummy() $key_mDown = GUICtrlCreateDummy() $key_mUp = GUICtrlCreateDummy() $key_mPgDn = GUICtrlCreateDummy() $key_mPgUp = GUICtrlCreateDummy() $key_mPgRight = GUICtrlCreateDummy() $key_mPgLeft = GUICtrlCreateDummy() Dim $AccelKeys[8][2]=[["^{left}", $Key_mleft], ["^{right}", $key_mRight], ["^{down}", $key_mDown], ["^{up}", $key_mUp], _ ["^{PgDn}", $key_mPgDn], ["^{PgUp}", $key_mPgUp],["^{Tab}", $key_mPgRight], ["^+{Tab}", $key_mPgLeft]] GUISetAccelerators($AccelKeys) $mapGui = GUICreate("", $mgw-4, $mgh-160-2, 2, 2,BitOR($WS_CHILD, $WS_TABSTOP), -1, $mainGUI) GUISetBkColor(0x004080) GUICtrlSetResizing(-1, $GUI_DOCKTOP) _GUIScrollBars_Init($mapGui) _GUIScrollBars_SetScrollInfoMax($mapGui, $SB_VERT, $mtiCols*$mtsize);this can be the grid width _GUIScrollBars_SetScrollInfoPage($mapGui, $SB_VERT, $mtiRows*$mtsize / 2.6);this can be the cellsparent width rounded to integral column width GUISetState() $mtileGUI = GUICreate("", $mtiCols*$mtSize, $mtiRows*$mtSize, 0, 0,BitOR($WS_CHILD, $WS_TABSTOP), -1, $mapGui) ;$mtileGUI = GUICreate("", $mgw-4-20, $mgh-160-2-20, 0, 0,BitOR($WS_CHILD, $WS_TABSTOP), -1, $mapGui) GUISetBkColor(0x0080C0) GUISetState() _GDIPlus_Startup() $mtileCanvas = _GDIPlus_GraphicsCreateFromHWND($mtileGUI) GUISetState() cacheCheck() MapPvSet($mapPvIdDefault) GuiSetState(@sw_show,$mainGui) GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT") GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") ;GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") $a = 50 While 1 $Msg = GUIGetMsg() ;; dino run ;$a += +0.1 ;if $a > 700 then $a=50 ;GUICtrlSetPos($dino, $a,$mgh-160) ;; msg loop Switch $Msg Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() Exit ;case $GUI_EVENT_RESTORE ; mapDraw() case $udn_zoom $x=guictrlread($cmb_zoom) $i=guictrlread($inp_zoom) $s = $x+$i if $s < 1 then $s = 1 if $s > 16 Then $s = 16 guictrlsetData($inp_zoom,0) guictrlsetData($cmb_zoom,$s) $zoom = $s ;; my be better using func tileNotoLatLon if stringlen($tileNoActiv) > 1 and $x<>$s then $a = stringsplit($tileNoActiv,"|") if $s > $x then ;zoom-in $mtx = round($a[1]*2) $mty = round($a[2]*2) Else $mtx = round($a[1]/2) $mty = round($a[2]/2) endif $tileNoActiv = $mtx&"|"&$mty consolewrite(@lf&"Mapdownload from UpDn-Zoom") MapDownload($mapPvId,$tileNoActiv,$s) endif case $btn_go ;; check if cache is available $x = GUICtrlRead($chb_cache) if $x = 1 Then if $cacheState = 0 then dirCreate($cachePath) $cacheState = 2 else $cacheState = 1 if not Fileexists($cachePath) then $cachState=0 EndIf $Zoom = GuiCtrlRead($Cmb_Zoom) ;; get wanted tiles count (prefer odd numberes for easy center address $xt = GuiCtrlRead($cmb_mapTiles) if stringInstr($xt,"x") then $xta = stringSplit($xt,"x") $mtiRows = $xta[1] $mtiCols = $xta[2] endif ;; get map provider and map type $xs = GuiCtrlRead($cmb_mapType) $xid = stringmid($xs,2,2) mapPvSet($xid) ;; read adress, get Lat/Lon from Google service and start $inp = GuiCtrlRead($Inp_Addr) if $inp = "" then $inp = $geoBase $xa = stringreplace($geoUrl,"{A}",$inp) consolewrite("geoURL:"&$xa&@lf) $xa = InetGet($xa,@tempdir&"Temp.tmp") $geoGet = Fileread(@tempdir&"Temp.tmp") consolewrite("geoCSV:"&$geoGet&@lf) if not stringInstr($geoGet,'"') Then $geoGet_arr = stringsplit($geoGet,",") $tileNoActiv = LatLonToTileNumber($geoGet_arr[3],$geoGet_arr[4], $Zoom) ;msgbox(0,"",$rc) MapDownload($mapPvId,$tileNoActiv,$Zoom) endif ;; for later use of mapid and zoom in TTQV filename $TtqvSaveFn = guictrlread($Inp_TtqvSaveFn) $x1 = $mapPvID&stringTrimleft($TtqvSaveFn,2) $x2 = stringleft($x1,stringInstr($x1,"_",0,-1))&$zoom&stringright($x1,4) GUICtrlSetData($Inp_TtqvSaveFn,$x2) ;; move by tile-steps case $btn_mUp MapTilesMove("u") case $btn_mDown MapTilesMove("d") case $btn_mleft MapTilesMove("l") case $btn_mRight MapTilesMove("r") ;; key scroll = überarbeiten case $key_mRight consolewrite("Key_mRight"&@lf) mapScroll("r") case $key_mLeft consolewrite("Key_mLeft"&@lf) mapScroll("l") case $key_mDown consolewrite("Key_mDownt"&@lf) mapScroll("d") case $key_mUp consolewrite("Key_mDownt"&@lf) mapScroll("u") case $key_mPgDn consolewrite("Key_mPgDn"&@lf) mapScroll("pd") case $key_mPgUp consolewrite("Key_mPgUp"&@lf) mapScroll("pu") case $key_mPgRight consolewrite("Key_mPgRight"&@lf) mapScroll("pr") case $key_mPgLeft consolewrite("Key_mPgLeft"&@lf) mapScroll("pl") case $udn_mtMoveStep , $inp_mtMoveStep $x = guictrlread($inp_mtMoveStep) if $x < 1 then guictrlsetdata($inp_mtMoveStep,1) case $btn_printMap if not FileExists(@scriptdir&"\montage.exe") Then msgbox(0,"", "You need montage.exe to use this function") elseif $mtfile[1] = "" Then msgbox(0,"", "No active file") else printMap() endif case $btn_saveMap if not FileExists(@scriptdir&"\montage.exe") Then msgbox(0,"", "You need montage.exe to use this function") elseif $mtfile[1] = "" Then msgbox(0,"", "No active file") else saveMap() endif case $lab_ttqvlab if not FileExists(@scriptdir&"\montage.exe") Then msgbox(0,"", "You need montage.exe to use this function") elseif $mtfile[1] = "" Then msgbox(0,"", "No active file") elseif not FileExists(@scriptdir&"\maps\TTQV_ext.cal") Then msgbox(0,"", "Can not find TTQV calibration mask file") else $TtqvSaveDir = guictrlread($Inp_TtqvSaveDir) $TtqvSaveFn = guictrlread($Inp_TtqvSaveFn) saveMapAs($TtqvSaveDir,$TtqvSaveFn) endif case $lab_pawlab if not FileExists(@scriptdir&"\montage.exe") Then msgbox(0,"", "You need montage.exe to use this function") elseif $mtfile[1] = "" Then msgbox(0,"", "No active file") elseif not FileExists(@scriptdir&"\PWMapConvert.exe") Then msgbox(0,"", "PW Mapconvert misssing") else $pawSaveDir = guictrlread($Inp_pawSaveDir) $pawSaveFn = guictrlread($Inp_TtqvSaveFn) saveMapAs($pawSaveDir,$pawSaveFn) endif case $mainTab2 msgbox(0,"","Test") $TtqvSaveFn = guictrlread($Inp_TtqvSaveFn) $x1 = $mapPvID&stringTrimleft($TtqvSaveFn,2) GUICtrlSetData($Inp_TtqvSaveFn,$x1) EndSwitch WEnd EndFunc ;==>MainGui Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $cmb_mapType Select Case $event = $CBN_SELCHANGE consolewrite("Notify - $CBN_SELCHANGE") $xs = GuiCtrlRead($cmb_mapType) $xid = stringmid($xs,2,2) mapPvSet($xid) MapDownload($mapPvId,$TileNoActiv,$zoom) EndSelect EndSelect Return $GUI_RUNDEFMSG EndFunc ;=> WM-Notify Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam) ;_WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_UPDATENOW) if $autoRedraw = 1 then ;mapDraw() mapDraw() GuiSetState(@sw_show,$mainGui) ;GuiSetState(@sw_show,$mapGui) ;GuiSetState(@sw_show,$mTileGui) endif ;_WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_VALIDATE) Return $GUI_RUNDEFMSG EndFunc #endregion MainMenuLoop Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $index = -1, $xChar, $xPos Local $Min, $Max, $Page, $Pos, $TrackPos For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xChar = $aSB_WindowInfo[$index][2] ExitLoop EndIf Next If $index = -1 Then Return 0 ;~ ; Get all the horizontal scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $xPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $xPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") #forceref $Min, $Max Switch $nScrollCode Case $SB_LINELEFT ; user clicked left arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) MapScroll("l") Case $SB_LINERIGHT ; user clicked right arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) MapScroll("r") Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) MapScroll("pl") Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) MapScroll("pr") Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO, "nPos", $TrackPos) EndSwitch ;~ // Set the position and then retrieve it. Due to adjustments ;~ // by Windows it may not be the same as the value set. DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) ;// If the position has changed, scroll the window and update it $Pos = DllStructGetData($tSCROLLINFO, "nPos") If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0) Return $GUI_RUNDEFMSG EndFunc ;==>WM_HSCROLL Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $index = -1, $yChar, $yPos Local $Min, $Max, $Page, $Pos, $TrackPos For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $yChar = $aSB_WindowInfo[$index][3] ExitLoop EndIf Next If $index = -1 Then Return 0 ; Get all the vertial scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $yPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $yPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") Switch $nScrollCode Case $SB_TOP ; user clicked the HOME keyboard key DllStructSetData($tSCROLLINFO, "nPos", $Min) Case $SB_BOTTOM ; user clicked the END keyboard key DllStructSetData($tSCROLLINFO, "nPos", $Max) Case $SB_LINEUP ; user clicked the top arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) mapScroll("u") Case $SB_LINEDOWN ; user clicked the bottom arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) mapScroll("d") Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) mapScroll("pu") Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) mapScroll("pd") Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO, "nPos", $TrackPos) EndSwitch ;~ // Set the position and then retrieve it. Due to adjustments ;~ // by Windows it may not be the same as the value set. DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ;// If the position has changed, scroll the window and update it $Pos = DllStructGetData($tSCROLLINFO, "nPos") If ($Pos <> $yPos) Then _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos)) $yPos = $Pos EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_VSCROLL #Region Calc func LatLonToTileNumber($lat,$lon,$zoom) $tileX= int(($lon+180)/360 *2^$zoom) $lat_rad = $lat*($pi/180) $tileY = int((1 - log(tan($lat_rad) + (1 / cos($lat_rad))) / $pi) / 2*2^$zoom) ;ytile = int((1.0 - log(tan(lat_rad) + (1 / cos(lat_rad))) / pi) / 2 * n) $tileNoActiv = $tileX&"|"&$tileY ;consolewrite("tileNO: "&$tileNumber&@crlf) return $tileNoActiv endfunc func tileXyToQuad($tilex,$tileY,$tileZ) local $quad = "" for $i = $tileZ to 1 step -1 $digit = 0 $mask = bitshift(1,-($i-1)) if bitand($tileX,$mask) <> 0 then $digit +=+1 if bitand($tileY,$mask) <> 0 then $digit +=+2 $quad &= $digit Next consolewrite(@lf &$quad &@lf) return $quad EndFunc func mapScaleCalc() ;detailed at: http://msdn.microsoft.com/en-us/library/bb259689.aspx ;following per 96 dpi for $i = 1 to ubound ($mapScale_arr)-1 $mapScale_arr[$i] = round($mapScale_arr[0]/(2^$i),0) next endfunc func TileNumberToLonLat($tileX,$tileY,$zoom) $lon = $tileX / 2^$zoom * 360.0 - 180.0 $lat_rad = atan(_sinh($pi * (1 - 2 * $tileY / 2^$zoom))) $lat = _degree($lat_rad) $LatLonNW = round($lat,7) &"," &round($lon,7) return $LatLonNW endfunc Func _Sinh(Const $nX) ;; written by trancexx - autoIt-Forum If Not IsNumber($nX) Then Return SetError(1, 0, 0) EndIf Local $aResult Local $h_DLL = DllOpen("msvcrt.dll") If $h_DLL <> -1 Then $aResult = DllCall($h_DLL, "double:cdecl", "sinh", "double", $nX) If @error Then DllClose($h_DLL) Return SetError(2, 0, 0) EndIf DllClose($h_DLL) Return SetError(0, 0, $aResult[0]) EndFunc ;==>_Sinh #endRegion Calc func cacheCheck() if Fileexists($cachePath) Then $ax = dirGetSize($cachePath,1) If IsArray($ax) Then GUICtrlsetdata($lab_cache,"Cache; "&int($ax[0]/1024)&" KB / "&$ax[1] &" Fls") endif Else dirCreate($cachePath) GUICtrlsetdata($lab_cache,"No Cache") GUICtrlSetState ($chb_cache, $GUI_UNCHECKED ) $catcheState=0 endif endfunc func MapPvSet($xmId = "OC") local $sname = "" for $i =1 to ubound($mapPv_arr)-1 $x = stringsplit(stringreplace($mapPv_arr[$i],"||",@lf),@lf) if stringleft($mapPv_arr[$i],2) = $xmId Then $mapPvId = $x[1] $mapPvName = $x[2] $mapPvURL = $x[3] $mapPvIdDefault = "[" &$x[1] &"] " &$x[2] endif $sName &= "["&$x[1]&"] "&$x[2]&"|" next $x = GuiCtrlRead($cmb_mapType) if $x = "" then GuiCtrlsetdata($cmb_mapType,$sName,$mapPvIdDefault) endfunc ;GuiCtrlsetdata(-1,"[OM] Osm Mapnik|[OC] Osm Cycle map|[OO] Osm Osmarender","[OM] Osm Mapnik") #region MapTilesAction func MapScroll($where) consolewrite("MapScroll->"&$where&@lf) $tgPos = ControlGetPos($mainGui,"",$mTileGui) consolewrite("x:"&$tgPos[0]&"y:"&$tgPos[1]&"w:"&$tgPos[2]&"h:"&$tgPos[3] &@lf) if $where = "l" then ControlMove($mainGui, "",$mTileGui,($tgPos[0]-2)+$mSSPx,$tgPos[1]-2,$tgPos[2],$tgPos[3]) if $where = "r" then ControlMove($mainGui, "",$mTileGui,($tgPos[0]-2)-$mSSPx,$tgPos[1]-2,$tgPos[2],$tgPos[3]) if $where = "d" then ControlMove($mainGui, "",$mTileGui,($tgPos[0]-2),($tgPos[1]-2)-$mSSPx,$tgPos[2],$tgPos[3]) if $where = "u" then ControlMove($mainGui, "",$mTileGui,($tgPos[0]-2),($tgPos[1]-2)+$mSSPx,$tgPos[2],$tgPos[3]) if $where = "pl" then ControlMove ($mainGui, "",$mTileGui,($tgPos[0]-2)+($mgw-4),$tgPos[1]-2,$tgPos[2],$tgPos[3]) if $where = "pr" then ControlMove ($mainGui, "",$mTileGui,($tgPos[0]-2)-($mgw-4),$tgPos[1]-2,$tgPos[2],$tgPos[3]) if $where = "pd" then ControlMove ($mainGui, "",$mTileGui,($tgPos[0]-2),($tgPos[1]-2)-($mgh-160-2),$tgPos[2],$tgPos[3]) if $where = "pu" then ControlMove ($mainGui, "",$mTileGui,($tgPos[0]-2),($tgPos[1]-2)+($mgh-160-2),$tgPos[2],$tgPos[3]) GuiSetState(@sw_show,$mTileGui) ;$tgPos = ControlGetPos($mainGui,"",$mTileGui) ;consolewrite("x:"&$tgPos[0]&"y:"&$tgPos[1]&"w:"&$tgPos[2]&"h:"&$tgPos[3] &@lf) endfunc func MapTilesMove($where) consolewrite(@lf&"MapTilesMove > tileNo: "&$tileNoActiv &" to:"&$where &@lf) $mtmoveStep = guictrlread($inp_mtMoveStep) if _ispressed(12) then $mtmoveStep = $mticols - 1 ; auf rows prüfen if stringinstr($tileNoActiv,"|") > 0 Then $tileNo_arr = stringsplit($tileNoActiv,"|") if $where = "l" then $tileNo_arr[1] = $tileNo_arr[1]-$mtMoveStep if $where = "r" then $tileNo_arr[1] = $tileNo_arr[1]+$mtMoveStep if $where = "u" then $tileNo_arr[2] = $tileNo_arr[2]-$mtMoveStep if $where = "d" then $tileNo_arr[2] = $tileNo_arr[2]+$mtMoveStep $tileNoActiv = $tileNo_arr[1]&"|"&$tileNo_arr[2] consolewrite("movezoom: "&$zoom) MapDownload($mapPvId,$TileNoActiv,$zoom) EndIf endfunc func MapDownload($mapID,$TileNo,$zoom) $autoRedraw = 0 ;set to 0 because especially GuiCtrlsetdat init a redraw GUICtrlSetImage($dino,@WindowsDir& "\cursors\dinosau2.ani") consoleWrite(@lf&"MapDownLoad -> M:"&$mapID&" T:"&$TileNo&" Z:"&$zoom&@lf) ;; get tilenumbers consolewrite("tileNO: "&$tileNo&@crlf) GuiCtrlsetdata($lab_cache,"tileNO: "&$tileNo) if stringinstr($tileNo,"|") > 0 Then $tileNo_arr = stringsplit($tileNo,"|") EndIf ;; peprare url $ActiveUrl = $mapPvURL $mtiCenter = round($mtiRows/2,0) ;2te Kachel wird zentriert bei 3x3Kachel local $iLeft=0, $iTop=0, $iget = "", $DlCt = 0 for $i = 1 to $mtFileNo-1 ;consolewrite("tileArr: "&$tileNo_arr[0]&@crlf) $x = $tileNo_arr[1] + $ileft - $mtiCenter+1 $y = $tileNo_arr[2] + $iTop - $mtiCenter+1 if stringleft($mapId,1) = "B" then $q = tileXyToQuad($x,$y,$zoom) consolewrite($i&": "&$x&" / " &$y&@lf) GuiCtrlsetdata($lab_cache,"Get tile "&$i&": "&$x&" / " &$y&" / " &$zoom) $xfn = $cachePath&$mapID&"_"&$x&"_"&$y&"_"&$zoom&".png" ;; download from Internet if not FileExists($xfn) or $cacheState < 2 then if stringleft($mapId,1) = "B" then $xurl = stringReplace($activeUrl,"{Q}",$q) else $xurl = stringReplace(stringReplace(stringReplace($activeUrl,"{X}",$x),"{Y}",$y),"{Z}",$zoom) endif consolewrite($xurl&@lf) $iget = inetget($xurl,$xfn,1,1) $DlCt = 0 do Sleep(250) $DlCt += +250 if $dlCt/1000 >= $timeOutMapDnl then inetClose($iget) GUICtrlSetData($lab_cache,"!! DOWNLOAD TIMEOUT REACHED !!") return 0 endif Until InetGetInfo($iget, 2) endif ;; end download $mtFile[$i] = $xfn $ileft +=+1 if $ileft = $mticols Then $ileft = 0 $itop +=+1 endif next if IsHWnd($iget) then inetClose($iget) consolewrite("Mapdownload END -> call mapdraw"&@lf) MapImageDispose() mapDraw() consolewrite("MapDraw End"&@lf) GUICtrlSetImage($dino,@WindowsDir& "\cursors\dinosaur.ani") cacheCheck() $autoRedraw = 1 endfunc func MapDraw() ;; draw the maps on tilecanavas _WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_UPDATENOW) local $ileft=0,$iTop=0 for $i = 1 to $mtFileNo-1 if $mtFile[$i] <> "" then $mtimg[$i] = _GDIPlus_ImageLoadFromFile($mtFile[$i]) _GDIPlus_GraphicsDrawImageRect($mtileCanvas, $mtimg[$i], $ileft*$mtSize,$iTop*$mtSize,$mtSize,$mtSize ) endif $ileft +=+1 if $ileft = $mticols Then $ileft = 0 $itop +=+1 endif next ;_WinAPI_InvalidateRect($mtileGui) _WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_VALIDATE) endfunc func MapImageDispose() for $i = 1 to $mtFileNo-1 _GDIPlus_ImageDispose($mtFile[$i]) next endfunc #endregion MapTilesAction func printMap() ;; same as save, without getting calibration ;; optimize for page size (DINA4, port. landscape $montage = @scriptdir&"\montage.exe " for $i = 1 to $mtFileNo-1 $tf = $mtFile[$i] if $tf <> "" Then $montage &= $tf&" " EndIf Next $montage &= "-tile "&$mtirows&"x"&$mtiCols&" -geometry "&$mtSize&"x"&$mtSize&"+0+0 "&$cachePath&"new.png" runwait($montage) shellexecute($cachePath&"new.png") endfunc func saveMap() ;; for testing. Must be orghanized $montage = @scriptdir&"\montage.exe " for $i = 1 to $mtFileNo-1 $tf = $mtFile[$i] if $tf <> "" Then $montage &= $tf&" " EndIf Next $montage &= "-tile "&$mtirows&"x"&$mtiCols&" -geometry "&$mtSize&"x"&$mtSize&"+0+0 "&$cachePath&"new.png" runwait($montage) ;;get calibration endfunc func saveMapAs($filePath,$filename) ;; for testing. Must be orghanized $montage = @scriptdir&"\montage.exe " for $i = 1 to $mtFileNo-1 $tf = $mtFile[$i] if $tf <> "" Then $montage &= $tf&" " EndIf Next ;; put tiles together $montage &= "-tile "&$mtirows&"x"&$mtiCols&" -geometry "&$mtSize&"x"&$mtSize&"+0+0 "&$filePath&$filename runwait($montage) ;;get calibration $x = stringsplit($mtFile[1],"_") $top = TileNumberToLonLat($x[2],$x[3],$x[4]) $x = stringsplit($mtFile[$mtFileNo-1],"_") $bot = TileNumberToLonLat($x[2]+1,$x[3]+1,$x[4]) ;get topleft of next tile consolewrite(@lf &"TopLeft: NW"& $top &"SE: " &$bot &@lf) $topa = stringsplit($top,",") $tN = $topa[1] $tW = $topa[2] $bota = stringsplit($bot,",") $tS = $bota[1] $tE = $bota[2] ttqvCal($tN,$tW,$tS,$tE,$mtSize*$mtiCols,$mtSize*$mtiRows) pawCal($tN,$tW,$tS,$tE,$mtSize*$mtiCols,$mtSize*$mtiRows) endfunc func TTQvCal($tN,$tW,$tS,$tE,$pW,$pH) $in = stringtrimright($ttqvSaveFn,4) $fr = fileopen(@scriptdir&"\maps\TTQV_ext.cal") $t = fileread($fr) Fileclose($fr) ;MsgBox(0,"",$t) $t = stringreplace($t,"#NorthLat#",$tN) $t = stringreplace($t,"#SouthLat#",$tS) $t = stringreplace($t,"#WestLon#",$tW) $t = stringreplace($t,"#EastLon#",$tE) $t = stringreplace($t,"#MapWidth#",$pW) $t = stringreplace($t,"#MapHigh#",$pH) ;$t = stringreplace($t,"#MapScale#",$Gzoom[$zoom]) $t = stringreplace($t,"#MapScale#",$mapScale_arr[$zoom]) $t = stringreplace($t,"#MapName#",$in) $t = stringreplace($t,"#MapFileName#",$in&".png") $fw = fileopen(@scriptdir&"\maps\"&$in&"_"&stringright($TtqvSaveFn,3)&".cal",2) filewrite($fw,$t) fileclose($fw) endfunc func pawCal($tN,$tW,$tS,$tE,$pW,$pH) $pawConverter = @scriptdir&"\PwMapConvert.exe" $pawSaveDir = guiCtrlRead($Inp_pawSaveDir) $pawSaveFn = $TtqvSaveFn msgbox(0,"",$pawSaveDir&$pawSaveFn ) if fileexists($pawConverter) Then $convert = $pawConverter&" "&$pawSaveDir&$pawSaveFn&",8,,,,,,,,"&$tN&","&$tW&","&$tS&","&$tE&",1,1,1" consolewrite($convert&@lf) runwait($convert) endif endfunc Edited April 15, 2011 by ReFran Link to comment Share on other sites More sharing options...
UEZ Posted April 15, 2011 Share Posted April 15, 2011 Well, it is not perfect but you can improve it: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #Include <WinAPI.au3> #Include <Math.au3> #Include <GUIComboBox.au3> #include <Misc.au3> #include <ScrollBarConstants.au3> #include <GUIScrollBars.au3> ;; author: ReFran - autoIt-Forum ;; thread: http://www.autoitscript.com/forum/topic/...nternet-maps-tiles-viewer-proj #region toDo ; mapAddress update after move (keep start, forward/backwards button) ; mapgeo language set, dann Münster und nicht Muenster ; mapgeo ini ; mapmove by pixel (keys/mouse) ; scrollbars ; resizing ; batch download of maps (different zoos #endregion toDo Global $xPos = 0, $yPos = 0, $memory = 0 ;; app related (mt = map tiles, arrays mostly 1 based DIM $mtSize = 256 ;tile size in pixel DIM $mtiRows = 5, $mtiCols = 5 DIM $mtFileNo = $mtiRows*$mtiCols+1, $mtFile[$mtFileNo], $mtImg[$mtFileNo] DIM $tileNoActiv, $zoom = 13, $quad DIM $mapScale_arr[17] $mapScale_arr[0] = 591659008 mapScaleCalc() DIM $mSSPx = 5 DIM $ttqvSaveDir = @scriptdir&"\maps\" ,$TtqvSaveFn="" DIM $ttqvSaveFx = "jpg" ; can be pgn (=>no convert) jpg, bmp DIM $pawSaveDir = @scriptdir&"\maps\", $pawSaveFn="", $Inp_pawSaveDir DIM $cachePath = @scriptdir&"\cache\" DIM $cacheState = 2 ; 0=not installed 1= don't cache maptiles; 2=use cache (should be standard) DIM $geoBase = "Deutschland" ;take this if address is blank DIM $geoURL = "http://maps.google.com/maps/geo?q={A}&output=csv" ;; {A} = placeholder for Address (real post/geo-addr. or GeoPoint(Lat,Lon) for reverse geocoding ;"MapPvId||MapPvName||MapPvUrl" &@lf _ ;|| because at least one URL contains "|" DIM $mapPv_str= "OC||Osm Cycle map||http://andy.sandbox.cloudmade.com/tiles/cycle/{Z}/{X}/{Y}.png" &@lf _ & "OM||Osm Mapnik map||http://tile.openstreetmap.org/{Z}/{X}/{Y}.png" &@lf _ & "OO||Osm Osmarender||http://tah.openstreetmap.org/Tiles/tile/{Z}/{X}/{Y}.png" &@lf _ & "OV||Osm VPN B&B map (NotAll)||http://tile.xn--pnvkarte-m4a.de/tilegen/{Z}/{X}/{Y}.png" &@lf _ & "--||--------------||http://tah.openstreetmap.org/Tiles/tile/{Z}/{X}/{Y}.png" &@lf _ & "GR||Google Roadmap||http://mt3.google.com/vt/x={X}&y={Y}&z={Z}" &@lf _ & "GT||Google Terrain||http://khm.google.com/vt/lbw/lyrs=p&x={X}&y={Y}&z={Z}" &@lf _ & "GH||Google Hybrid||http://mt1.google.com/vt/lyrs=y&x={X}&y={Y}&z={Z}" &@lf _ & "GS||Google Satelite||http://khm1.google.com/kh/v=49&x={X}&y={Y}&z={Z}" &@lf _ & "GN||Google Night||http://mt1.google.com/vt/lyrs=h@130&hl=de&src=api&x={X}&y={Y}&z={Z}" &@lf _ & "--||--------------||http://tah.openstreetmap.org/Tiles/tile/{Z}/{X}/{Y}.png" &@lf _ & "BM||Bing Roadmap||http://ecn.t0.tiles.virtualearth.net/tiles/r{Q}.png?g=441&mkt=de-de&n=z";&@lf _ ;& "YR||Yahoo Roadmap||http://maps1.yimg.com/hx/tl?v=4.2&x={X}&y={Y}&z={Z}" ;; placeholders: {Z} zoom based on GMAP-zoom, {X} tileNoX calc'ed from Lon; {Y} tileNoY calc'ed from Lat; {Q} Bing Quad ;; defined as string for later use with ini DIM $mapPv_arr= stringSplit($mapPv_str,@lf) DIM $mapPvIdDefault = "OM" ;set preferred maptype DIM $mapPvId, $mapPvName, $mapPvURL DIM $autoRedraw = 1 ;used to switch out autoredraw DIM $timeOutMapDnl = 5 ;in sec DIM $pi = 3.14159265358979 ;; GUI related Dim $mainGUI, $MainGuiTitle = @scriptname, $mapGui,$mTileGui, $mtileCanvas, $Inp_Addr, $dino Dim $mgw = 1200, $mgh = 800, $mgt , $mgtDelta DIM $lab_cache,$chb_cache,$inp_mtMoveStep,$cmb_mapType #region MainMenuLoop mainGui() Func MainGui() $mainGUI = GUICreate($MainGuiTitle, $mgw, $mgh, 20, -1, _ $WS_OVERLAPPEDWINDOW +$WS_CLIPCHILDREN + $WS_CLIPSIBLINGS) GUISetStyle(BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SIZEBOX, $WS_SYSMENU)) $scrollhor = GUICreate("scrollhor",$mgw-200,17,$mgw-($mgw-200)-2,$mgh-160+1, $WS_CHILD,-1, $mainGui) ;GUISetBkColor(0x808080) ;GUISetState() _GUIScrollBars_Init($scrollhor) _GUIScrollBars_SetScrollInfoMax($scrollhor, $SB_HORZ, $mtiCols*$mtsize);this can be the grid width _GUIScrollBars_SetScrollInfoPage($scrollhor, $SB_HORZ, $mtiCols*$mtsize / 2.6);this can be the cellsparent width rounded to integral column width GUICtrlCreateButton("Test",$mgw-200,0,17,17) GUISetState() Guiswitch($mainGui) ;; definition of tabs $mainTab = GUICtrlCreateTab(2, $mgh-155,$mgw-2,$mgh-645) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER) $mainTab1 = GUICtrlCreateTabItem("View") $Inp_Addr = GuiCtrlCreateCombo("Wesel,de",5,$mgh-150+30,220,18) GuiCtrlsetdata(-1,"Bocholt,de|Venlo,nl|Taverne on the Green, New York, US|Hofbraeuhaus, Muenchen, DE|Zum Frosch, Prag, cz") GUICtrlSetTip(-1, "Real Address (google maps format) or lat,lon"&@lf&"e.g.=street,town,country; "&@lf&"e.g.: 51.1,6.2)") $cmb_Zoom = GUICtrlCreateCombo("",230, $mgh-150+30,40,18) GuiCtrlsetdata(-1,"16|15|14|13|12|11|10","13") GUICtrlSetTip(-1, "Zoom (google based)"&@lf&"13= 1:72,2 KM; "&@lf&"14=1:36,1 Km)") $inp_zoom = GUICtrlCreateInput(0,272,$mgh-150+30,19,22) $udn_zoom = GUICtrlCreateUpdown($inp_zoom) $dino = GUICtrlCreateIcon(@WindowsDir & "\cursors\dinosaur.ani",-1, 305, $mgh-150+25,28, 28) $cmb_mapType = GuiCtrlCreateCombo("",5,$mgh-150+30+30,220,18) ;GuiCtrlsetdata(-1,"[OM] Osm Mapnik|[OC] Osm Cycle map|[OO] Osm Osmarender","[OM] Osm Mapnik") $cmb_mapTiles = GuiCtrlCreateCombo("",230,$mgh-150+30+30,62,18) GuiCtrlsetdata(-1,"3x5|5x5|7x7|9x9|","3x5") GUICtrlSetTip(-1, "Tiles Matrix rows x cols; 1 tile = 256 pixel") $btn_go =GUICtrlCreateButton("GO",305,$mgh-150+30+30,30,20) $btn_dnl = "";GUICtrlCreateButton("dnl",230,$mgh-150+30+30,30,30) $btn_mUp =GUICtrlCreateButton("Up",$mgw-100,$mgh-150+30,20,20) $btn_mDown =GUICtrlCreateButton("Dn",$mgw-100,$mgh-150+30+30,20,20) $btn_mleft =GUICtrlCreateButton("<-",$mgw-125,$mgh-150+30+15,20,20) $btn_mRight =GUICtrlCreateButton("->",$mgw-75,$mgh-150+30+15,20,20) $inp_mtMoveStep = GUICtrlCreateInput("1",$mgw-170,$mgh-150+30+15, 35, 20) $udn_mtMoveStep = GUICtrlCreateUpdown($inp_mtMoveStep) $lab_cache = GUICtrlCreateLabel("Cache",5,$mgh-30,220,18,$SS_SUNKEN) $chb_cache = GUICtrlCreateCheckbox("",230, $mgh-30,40,18) GUICtrlSetState ( -1, $GUI_CHECKED ) GUICtrlSetTip(-1, "Switch cache on/off") $btn_printMap = GUICtrlCreateButton("Print",$mgw-170,$mgh-30,50,20) $btn_saveMap = GUICtrlCreateButton("Save",$mgw-120,$mgh-30,50,20) $btn_dummy = GUICtrlCreateDummy() $mainTab2 = GUICtrlCreateTabItem("Files") $Lab_Ttqvlab = GuiCtrlCreateLabel("TTQV",5,$mgh-150+30,40,18) $Inp_TtqvSaveDir = GuiCtrlCreateInput($ttqvSaveDir,5+45,$mgh-150+30,220,18) $Inp_TtqvSaveFn = GuiCtrlCreateInput($mapPvIdDefault&"_xxxx_"&$zoom&"."&$ttqvSaveFx,230+45,$mgh-150+30,220,18) $Lab_pawlab = GuiCtrlCreateLabel("paw",5,$mgh-150+30+30,40,18) $Inp_pawSaveDir = GuiCtrlCreateInput($pawSaveDir,5+45,$mgh-150+30+30,220,18) ;$Inp_pawSaveFn = GuiCtrlCreateInput($mapPvIdDefault&"_xxxx_"&$zoom&".jpg",230+45,$mgh-150+30+30,220,18) GUICtrlCreateTabItem("") ; Set accelerators test $key_mRight = GUICtrlCreateDummy() $key_mLeft = GUICtrlCreateDummy() $key_mDown = GUICtrlCreateDummy() $key_mUp = GUICtrlCreateDummy() $key_mPgDn = GUICtrlCreateDummy() $key_mPgUp = GUICtrlCreateDummy() $key_mPgRight = GUICtrlCreateDummy() $key_mPgLeft = GUICtrlCreateDummy() Dim $AccelKeys[8][2]=[["^{left}", $Key_mleft], ["^{right}", $key_mRight], ["^{down}", $key_mDown], ["^{up}", $key_mUp], _ ["^{PgDn}", $key_mPgDn], ["^{PgUp}", $key_mPgUp],["^{Tab}", $key_mPgRight], ["^+{Tab}", $key_mPgLeft]] GUISetAccelerators($AccelKeys) $mapGui = GUICreate("", $mgw-4, $mgh-160-2, 2, 2,BitOR($WS_CHILD, $WS_TABSTOP), -1, $mainGUI) GUISetBkColor(0x004080) GUICtrlSetResizing(-1, $GUI_DOCKTOP) _GUIScrollBars_Init($mapGui) _GUIScrollBars_SetScrollRange($mapGui, $SB_VERT, 0, $mtiCols*$mtsize) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $mtsize = ' & $mtsize & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console ;~ _GUIScrollBars_SetScrollInfoMax($mapGui, $SB_VERT, $mtiCols*$mtsize);this can be the grid width ;~ _GUIScrollBars_SetScrollInfoPage($mapGui, $SB_VERT, $mtiRows*$mtsize / 2.6);this can be the cellsparent width rounded to integral column width GUISetState() $mtileGUI = GUICreate("", $mtiCols*$mtSize, $mtiRows*$mtSize, 0, 0,BitOR($WS_CHILD, $WS_TABSTOP), -1, $mapGui) ;$mtileGUI = GUICreate("", $mgw-4-20, $mgh-160-2-20, 0, 0,BitOR($WS_CHILD, $WS_TABSTOP), -1, $mapGui) GUISetBkColor(0x0080C0) GUISetState() _GDIPlus_Startup() $mtileCanvas = _GDIPlus_GraphicsCreateFromHWND($mtileGUI) GUISetState() cacheCheck() MapPvSet($mapPvIdDefault) GuiSetState(@sw_show,$mainGui) GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT") GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") ;~ GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") ;~ GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") $a = 50 While 1 $Msg = GUIGetMsg() ;; dino run ;$a += +0.1 ;if $a > 700 then $a=50 ;GUICtrlSetPos($dino, $a,$mgh-160) ;; msg loop Switch $Msg Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() Exit ;case $GUI_EVENT_RESTORE ; mapDraw() case $udn_zoom $x=guictrlread($cmb_zoom) $i=guictrlread($inp_zoom) $s = $x+$i if $s < 1 then $s = 1 if $s > 16 Then $s = 16 guictrlsetData($inp_zoom,0) guictrlsetData($cmb_zoom,$s) $zoom = $s ;; my be better using func tileNotoLatLon if stringlen($tileNoActiv) > 1 and $x<>$s then $a = stringsplit($tileNoActiv,"|") if $s > $x then ;zoom-in $mtx = round($a[1]*2) $mty = round($a[2]*2) Else $mtx = round($a[1]/2) $mty = round($a[2]/2) endif $tileNoActiv = $mtx&"|"&$mty consolewrite(@lf&"Mapdownload from UpDn-Zoom") MapDownload($mapPvId,$tileNoActiv,$s) endif case $btn_go ;; check if cache is available $x = GUICtrlRead($chb_cache) if $x = 1 Then if $cacheState = 0 then dirCreate($cachePath) $cacheState = 2 else $cacheState = 1 if not Fileexists($cachePath) then $cachState=0 EndIf $Zoom = GuiCtrlRead($Cmb_Zoom) ;; get wanted tiles count (prefer odd numberes for easy center address $xt = GuiCtrlRead($cmb_mapTiles) if stringInstr($xt,"x") then $xta = stringSplit($xt,"x") $mtiRows = $xta[1] $mtiCols = $xta[2] endif ;; get map provider and map type $xs = GuiCtrlRead($cmb_mapType) $xid = stringmid($xs,2,2) mapPvSet($xid) ;; read adress, get Lat/Lon from Google service and start $inp = GuiCtrlRead($Inp_Addr) if $inp = "" then $inp = $geoBase $xa = stringreplace($geoUrl,"{A}",$inp) consolewrite("geoURL:"&$xa&@lf) $xa = InetGet($xa,@tempdir&"Temp.tmp") $geoGet = Fileread(@tempdir&"Temp.tmp") consolewrite("geoCSV:"&$geoGet&@lf) if not stringInstr($geoGet,'"') Then $geoGet_arr = stringsplit($geoGet,",") $tileNoActiv = LatLonToTileNumber($geoGet_arr[3],$geoGet_arr[4], $Zoom) ;msgbox(0,"",$rc) MapDownload($mapPvId,$tileNoActiv,$Zoom) endif ;; for later use of mapid and zoom in TTQV filename $TtqvSaveFn = guictrlread($Inp_TtqvSaveFn) $x1 = $mapPvID&stringTrimleft($TtqvSaveFn,2) $x2 = stringleft($x1,stringInstr($x1,"_",0,-1))&$zoom&stringright($x1,4) GUICtrlSetData($Inp_TtqvSaveFn,$x2) ;; move by tile-steps case $btn_mUp MapTilesMove("u") case $btn_mDown MapTilesMove("d") case $btn_mleft MapTilesMove("l") case $btn_mRight MapTilesMove("r") ;; key scroll = überarbeiten case $key_mRight consolewrite("Key_mRight"&@lf) mapScroll("r") case $key_mLeft consolewrite("Key_mLeft"&@lf) mapScroll("l") case $key_mDown consolewrite("Key_mDownt"&@lf) mapScroll("d") case $key_mUp consolewrite("Key_mDownt"&@lf) mapScroll("u") case $key_mPgDn consolewrite("Key_mPgDn"&@lf) mapScroll("pd") case $key_mPgUp consolewrite("Key_mPgUp"&@lf) mapScroll("pu") case $key_mPgRight consolewrite("Key_mPgRight"&@lf) mapScroll("pr") case $key_mPgLeft consolewrite("Key_mPgLeft"&@lf) mapScroll("pl") case $udn_mtMoveStep , $inp_mtMoveStep $x = guictrlread($inp_mtMoveStep) if $x < 1 then guictrlsetdata($inp_mtMoveStep,1) case $btn_printMap if not FileExists(@scriptdir&"\montage.exe") Then msgbox(0,"", "You need montage.exe to use this function") elseif $mtfile[1] = "" Then msgbox(0,"", "No active file") else printMap() endif case $btn_saveMap if not FileExists(@scriptdir&"\montage.exe") Then msgbox(0,"", "You need montage.exe to use this function") elseif $mtfile[1] = "" Then msgbox(0,"", "No active file") else saveMap() endif case $lab_ttqvlab if not FileExists(@scriptdir&"\montage.exe") Then msgbox(0,"", "You need montage.exe to use this function") elseif $mtfile[1] = "" Then msgbox(0,"", "No active file") elseif not FileExists(@scriptdir&"\maps\TTQV_ext.cal") Then msgbox(0,"", "Can not find TTQV calibration mask file") else $TtqvSaveDir = guictrlread($Inp_TtqvSaveDir) $TtqvSaveFn = guictrlread($Inp_TtqvSaveFn) saveMapAs($TtqvSaveDir,$TtqvSaveFn) endif case $lab_pawlab if not FileExists(@scriptdir&"\montage.exe") Then msgbox(0,"", "You need montage.exe to use this function") elseif $mtfile[1] = "" Then msgbox(0,"", "No active file") elseif not FileExists(@scriptdir&"\PWMapConvert.exe") Then msgbox(0,"", "PW Mapconvert misssing") else $pawSaveDir = guictrlread($Inp_pawSaveDir) $pawSaveFn = guictrlread($Inp_TtqvSaveFn) saveMapAs($pawSaveDir,$pawSaveFn) endif case $mainTab2 msgbox(0,"","Test") $TtqvSaveFn = guictrlread($Inp_TtqvSaveFn) $x1 = $mapPvID&stringTrimleft($TtqvSaveFn,2) GUICtrlSetData($Inp_TtqvSaveFn,$x1) EndSwitch WEnd EndFunc ;==>MainGui Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $cmb_mapType Select Case $event = $CBN_SELCHANGE consolewrite("Notify - $CBN_SELCHANGE") $xs = GuiCtrlRead($cmb_mapType) $xid = stringmid($xs,2,2) mapPvSet($xid) MapDownload($mapPvId,$TileNoActiv,$zoom) EndSelect EndSelect Return $GUI_RUNDEFMSG EndFunc ;=> WM-Notify Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam) ;_WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_UPDATENOW) if $autoRedraw = 1 then ;mapDraw() mapDraw() GuiSetState(@sw_show,$mainGui) ;GuiSetState(@sw_show,$mapGui) ;GuiSetState(@sw_show,$mTileGui) endif ;_WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_VALIDATE) Return $GUI_RUNDEFMSG EndFunc #endregion MainMenuLoop ;~ Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam) ;~ #forceref $Msg, $lParam ;~ Local $nScrollCode = BitAND($wParam, 0x0000FFFF) ;~ Local $index = -1, $xChar, $xPos ;~ Local $Min, $Max, $Page, $Pos, $TrackPos ;~ For $x = 0 To UBound($aSB_WindowInfo) - 1 ;~ If $aSB_WindowInfo[$x][0] = $hWnd Then ;~ $index = $x ;~ $xChar = $aSB_WindowInfo[$index][2] ;~ ExitLoop ;~ EndIf ;~ Next ;~ If $index = -1 Then Return 0 ; Get all the horizontal scroll bar information ;~ Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ) ;~ $Min = DllStructGetData($tSCROLLINFO, "nMin") ;~ $Max = DllStructGetData($tSCROLLINFO, "nMax") ;~ $Page = DllStructGetData($tSCROLLINFO, "nPage") ;~ ; Save the position for comparison later on ;~ $xPos = DllStructGetData($tSCROLLINFO, "nPos") ;~ $Pos = $xPos ;~ $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") ;~ #forceref $Min, $Max ;~ Switch $nScrollCode ;~ Case $SB_LINELEFT ; user clicked left arrow ;~ DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) ;~ MapScroll("l") ;~ Case $SB_LINERIGHT ; user clicked right arrow ;~ DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) ;~ MapScroll("r") ;~ Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box ;~ DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) ;~ MapScroll("pl") ;~ Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box ;~ DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) ;~ MapScroll("pr") ;~ Case $SB_THUMBTRACK ; user dragged the scroll box ;~ DllStructSetData($tSCROLLINFO, "nPos", $TrackPos) ;~ EndSwitch ;// Set the position and then retrieve it. Due to adjustments ;// by Windows it may not be the same as the value set. ;~ DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) ;~ _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) ;~ _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) ;~ ;// If the position has changed, scroll the window and update it ;~ $Pos = DllStructGetData($tSCROLLINFO, "nPos") ;~ If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0) ;~ Return $GUI_RUNDEFMSG ;~ EndFunc ;==>WM_HSCROLL ;~ Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam) ;~ #forceref $Msg, $wParam, $lParam ;~ Local $nScrollCode = BitAND($wParam, 0x0000FFFF) ;~ Local $index = -1, $yChar, $yPos ;~ Local $Min, $Max, $Page, $Pos, $TrackPos ;~ For $x = 0 To UBound($aSB_WindowInfo) - 1 ;~ If $aSB_WindowInfo[$x][0] = $hWnd Then ;~ $index = $x ;~ $yChar = $aSB_WindowInfo[$index][3] ;~ ExitLoop ;~ EndIf ;~ Next ;~ If $index = -1 Then Return 0 ;~ ; Get all the vertial scroll bar information ;~ Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) ;~ $Min = DllStructGetData($tSCROLLINFO, "nMin") ;~ $Max = DllStructGetData($tSCROLLINFO, "nMax") ;~ $Page = DllStructGetData($tSCROLLINFO, "nPage") ;~ ; Save the position for comparison later on ;~ $yPos = DllStructGetData($tSCROLLINFO, "nPos") ;~ $Pos = $yPos ;~ $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") ;~ Switch $nScrollCode ;~ Case $SB_TOP ; user clicked the HOME keyboard key ;~ DllStructSetData($tSCROLLINFO, "nPos", $Min) ;~ Case $SB_BOTTOM ; user clicked the END keyboard key ;~ DllStructSetData($tSCROLLINFO, "nPos", $Max) ;~ Case $SB_LINEUP ; user clicked the top arrow ;~ DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) ;~ mapScroll("u") ;~ Case $SB_LINEDOWN ; user clicked the bottom arrow ;~ DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) ;~ mapScroll("d") ;~ Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box ;~ DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) ;~ mapScroll("pu") ;~ Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box ;~ DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) ;~ mapScroll("pd") ;~ Case $SB_THUMBTRACK ; user dragged the scroll box ;~ DllStructSetData($tSCROLLINFO, "nPos", $TrackPos) ;~ EndSwitch ;~ ; // Set the position and then retrieve it. Due to adjustments ;~ ;// by Windows it may not be the same as the value set. ;~ DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) ;~ _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ;~ _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ;~ ;// If the position has changed, scroll the window and update it ;~ $Pos = DllStructGetData($tSCROLLINFO, "nPos") ;~ If ($Pos <> $yPos) Then ;~ _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos)) ;~ $yPos = $Pos ;~ EndIf ;~ Return $GUI_RUNDEFMSG ;~ EndFunc ;==>WM_VSCROLL ; Vertikales Scrollen Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $index = -1, $yChar, $ii Local $Min, $Max, $Page, $Pos, $TrackPos ;~ For $x = 0 To UBound($aSB_WindowInfo) - 1 ;~ If $aSB_WindowInfo[$x][0] = $hWnd Then ;~ $index = $x ;~ $yChar = $aSB_WindowInfo[$index][3] ;~ ExitLoop ;~ EndIf ;~ Next ;~ If $index = -1 Then Return 0 ; Ermittelt alle Informationen der vertikalen Scrollbar Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") $yPos = DllStructGetData($tSCROLLINFO, "nPos") $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") ; Speichert die y-Position für einen späteren Vergleich $Pos = $yPos ; Auswertung der vom System gemeldeten Scroll-Nachricht Switch $nScrollCode Case $SB_LINEUP ; Der Anwender klickte auf den oberen Pfeil DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) mapScroll("u") Case $SB_LINEDOWN ; Der Anwender klickte auf den unteren Pfeil DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) mapScroll("d") Case $SB_PAGEUP ; Der Anwender klickte oberhalb des Scrollbalkens DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) mapScroll("pu") Case $SB_PAGEDOWN ; Der Anwender klickte unterhalb des Scrollbalkens DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) mapScroll("pd") Case $SB_THUMBTRACK ; Der Anwender zog den Scrollbalken DllStructSetData($tSCROLLINFO, "nPos", $TrackPos) If $memory > $TrackPos Then For $ii = 1 To 5 mapScroll("u") Next $memory = $TrackPos Else For $ii = 1 To 5 mapScroll("d") Next $memory = $TrackPos EndIf EndSwitch ;~ // Setzt die neue Position und ermittelt sie danach erneut. ;~ // Abhängig von den Windows-Einstellungen kann es sein, dass die gelesenen Werte nicht die gleichen sind, wie die vorher gesetzten. DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ; // Falls sich die y-Position der Scrollbar geändert hat, den Fensterbereich verschieben und aktualisieren $Pos = DllStructGetData($tSCROLLINFO, "nPos") If ($Pos <> $yPos) Then _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos)) $yPos = $Pos EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_VSCROLL #Region Calc func LatLonToTileNumber($lat,$lon,$zoom) $tileX= int(($lon+180)/360 *2^$zoom) $lat_rad = $lat*($pi/180) $tileY = int((1 - log(tan($lat_rad) + (1 / cos($lat_rad))) / $pi) / 2*2^$zoom) ;ytile = int((1.0 - log(tan(lat_rad) + (1 / cos(lat_rad))) / pi) / 2 * n) $tileNoActiv = $tileX&"|"&$tileY ;consolewrite("tileNO: "&$tileNumber&@crlf) return $tileNoActiv endfunc func tileXyToQuad($tilex,$tileY,$tileZ) local $quad = "" for $i = $tileZ to 1 step -1 $digit = 0 $mask = bitshift(1,-($i-1)) if bitand($tileX,$mask) <> 0 then $digit +=+1 if bitand($tileY,$mask) <> 0 then $digit +=+2 $quad &= $digit Next consolewrite(@lf &$quad &@lf) return $quad EndFunc func mapScaleCalc() ;detailed at: http://msdn.microsoft.com/en-us/library/bb259689.aspx ;following per 96 dpi for $i = 1 to ubound ($mapScale_arr)-1 $mapScale_arr[$i] = round($mapScale_arr[0]/(2^$i),0) next endfunc func TileNumberToLonLat($tileX,$tileY,$zoom) $lon = $tileX / 2^$zoom * 360.0 - 180.0 $lat_rad = atan(_sinh($pi * (1 - 2 * $tileY / 2^$zoom))) $lat = _degree($lat_rad) $LatLonNW = round($lat,7) &"," &round($lon,7) return $LatLonNW endfunc Func _Sinh(Const $nX) ;; written by trancexx - autoIt-Forum If Not IsNumber($nX) Then Return SetError(1, 0, 0) EndIf Local $aResult Local $h_DLL = DllOpen("msvcrt.dll") If $h_DLL <> -1 Then $aResult = DllCall($h_DLL, "double:cdecl", "sinh", "double", $nX) If @error Then DllClose($h_DLL) Return SetError(2, 0, 0) EndIf DllClose($h_DLL) Return SetError(0, 0, $aResult[0]) EndFunc ;==>_Sinh #endRegion Calc func cacheCheck() if Fileexists($cachePath) Then $ax = dirGetSize($cachePath,1) If IsArray($ax) Then GUICtrlsetdata($lab_cache,"Cache; "&int($ax[0]/1024)&" KB / "&$ax[1] &" Fls") endif Else dirCreate($cachePath) GUICtrlsetdata($lab_cache,"No Cache") GUICtrlSetState ($chb_cache, $GUI_UNCHECKED ) $catcheState=0 endif endfunc func MapPvSet($xmId = "OC") local $sname = "" for $i =1 to ubound($mapPv_arr)-1 $x = stringsplit(stringreplace($mapPv_arr[$i],"||",@lf),@lf) if stringleft($mapPv_arr[$i],2) = $xmId Then $mapPvId = $x[1] $mapPvName = $x[2] $mapPvURL = $x[3] $mapPvIdDefault = "[" &$x[1] &"] " &$x[2] endif $sName &= "["&$x[1]&"] "&$x[2]&"|" next $x = GuiCtrlRead($cmb_mapType) if $x = "" then GuiCtrlsetdata($cmb_mapType,$sName,$mapPvIdDefault) endfunc ;GuiCtrlsetdata(-1,"[OM] Osm Mapnik|[OC] Osm Cycle map|[OO] Osm Osmarender","[OM] Osm Mapnik") #region MapTilesAction func MapScroll($where) consolewrite("MapScroll->"&$where&@lf) $tgPos = ControlGetPos($mainGui,"",$mTileGui) consolewrite("x:"&$tgPos[0]&"y:"&$tgPos[1]&"w:"&$tgPos[2]&"h:"&$tgPos[3] &@lf) if $where = "l" then ControlMove($mainGui, "",$mTileGui,($tgPos[0]-2)+$mSSPx,$tgPos[1]-2,$tgPos[2],$tgPos[3]) if $where = "r" then ControlMove($mainGui, "",$mTileGui,($tgPos[0]-2)-$mSSPx,$tgPos[1]-2,$tgPos[2],$tgPos[3]) if $where = "d" then ControlMove($mainGui, "",$mTileGui,($tgPos[0]-2),($tgPos[1]-2)-$mSSPx,$tgPos[2],$tgPos[3]) if $where = "u" then ControlMove($mainGui, "",$mTileGui,($tgPos[0]-2),($tgPos[1]-2)+$mSSPx,$tgPos[2],$tgPos[3]) if $where = "pl" then ControlMove ($mainGui, "",$mTileGui,($tgPos[0]-2)+($mgw-4),$tgPos[1]-2,$tgPos[2],$tgPos[3]) if $where = "pr" then ControlMove ($mainGui, "",$mTileGui,($tgPos[0]-2)-($mgw-4),$tgPos[1]-2,$tgPos[2],$tgPos[3]) if $where = "pd" then ControlMove ($mainGui, "",$mTileGui,($tgPos[0]-2),($tgPos[1]-2)-($mgh-160-2),$tgPos[2],$tgPos[3]) if $where = "pu" then ControlMove ($mainGui, "",$mTileGui,($tgPos[0]-2),($tgPos[1]-2)+($mgh-160-2),$tgPos[2],$tgPos[3]) GuiSetState(@sw_show,$mTileGui) ;$tgPos = ControlGetPos($mainGui,"",$mTileGui) ;consolewrite("x:"&$tgPos[0]&"y:"&$tgPos[1]&"w:"&$tgPos[2]&"h:"&$tgPos[3] &@lf) endfunc func MapTilesMove($where) consolewrite(@lf&"MapTilesMove > tileNo: "&$tileNoActiv &" to:"&$where &@lf) $mtmoveStep = guictrlread($inp_mtMoveStep) if _ispressed(12) then $mtmoveStep = $mticols - 1 ; auf rows prüfen if stringinstr($tileNoActiv,"|") > 0 Then $tileNo_arr = stringsplit($tileNoActiv,"|") if $where = "l" then $tileNo_arr[1] = $tileNo_arr[1]-$mtMoveStep if $where = "r" then $tileNo_arr[1] = $tileNo_arr[1]+$mtMoveStep if $where = "u" then $tileNo_arr[2] = $tileNo_arr[2]-$mtMoveStep if $where = "d" then $tileNo_arr[2] = $tileNo_arr[2]+$mtMoveStep $tileNoActiv = $tileNo_arr[1]&"|"&$tileNo_arr[2] consolewrite("movezoom: "&$zoom) MapDownload($mapPvId,$TileNoActiv,$zoom) EndIf endfunc func MapDownload($mapID,$TileNo,$zoom) $autoRedraw = 0 ;set to 0 because especially GuiCtrlsetdat init a redraw GUICtrlSetImage($dino,@WindowsDir& "\cursors\dinosau2.ani") consoleWrite(@lf&"MapDownLoad -> M:"&$mapID&" T:"&$TileNo&" Z:"&$zoom&@lf) ;; get tilenumbers consolewrite("tileNO: "&$tileNo&@crlf) GuiCtrlsetdata($lab_cache,"tileNO: "&$tileNo) if stringinstr($tileNo,"|") > 0 Then $tileNo_arr = stringsplit($tileNo,"|") EndIf ;; peprare url $ActiveUrl = $mapPvURL $mtiCenter = round($mtiRows/2,0) ;2te Kachel wird zentriert bei 3x3Kachel local $iLeft=0, $iTop=0, $iget = "", $DlCt = 0 for $i = 1 to $mtFileNo-1 ;consolewrite("tileArr: "&$tileNo_arr[0]&@crlf) $x = $tileNo_arr[1] + $ileft - $mtiCenter+1 $y = $tileNo_arr[2] + $iTop - $mtiCenter+1 if stringleft($mapId,1) = "B" then $q = tileXyToQuad($x,$y,$zoom) consolewrite($i&": "&$x&" / " &$y&@lf) GuiCtrlsetdata($lab_cache,"Get tile "&$i&": "&$x&" / " &$y&" / " &$zoom) $xfn = $cachePath&$mapID&"_"&$x&"_"&$y&"_"&$zoom&".png" ;; download from Internet if not FileExists($xfn) or $cacheState < 2 then if stringleft($mapId,1) = "B" then $xurl = stringReplace($activeUrl,"{Q}",$q) else $xurl = stringReplace(stringReplace(stringReplace($activeUrl,"{X}",$x),"{Y}",$y),"{Z}",$zoom) endif consolewrite($xurl&@lf) $iget = inetget($xurl,$xfn,1,1) $DlCt = 0 do Sleep(250) $DlCt += +250 if $dlCt/1000 >= $timeOutMapDnl then inetClose($iget) GUICtrlSetData($lab_cache,"!! DOWNLOAD TIMEOUT REACHED !!") return 0 endif Until InetGetInfo($iget, 2) endif ;; end download $mtFile[$i] = $xfn $ileft +=+1 if $ileft = $mticols Then $ileft = 0 $itop +=+1 endif next if IsHWnd($iget) then inetClose($iget) consolewrite("Mapdownload END -> call mapdraw"&@lf) MapImageDispose() mapDraw() consolewrite("MapDraw End"&@lf) GUICtrlSetImage($dino,@WindowsDir& "\cursors\dinosaur.ani") cacheCheck() $autoRedraw = 1 endfunc func MapDraw() ;; draw the maps on tilecanavas _WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_UPDATENOW) local $ileft=0,$iTop=0 for $i = 1 to $mtFileNo-1 if $mtFile[$i] <> "" then $mtimg[$i] = _GDIPlus_ImageLoadFromFile($mtFile[$i]) _GDIPlus_GraphicsDrawImageRect($mtileCanvas, $mtimg[$i], $ileft*$mtSize,$iTop*$mtSize,$mtSize,$mtSize ) endif $ileft +=+1 if $ileft = $mticols Then $ileft = 0 $itop +=+1 endif next ;_WinAPI_InvalidateRect($mtileGui) _WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_VALIDATE) endfunc func MapImageDispose() for $i = 1 to $mtFileNo-1 _GDIPlus_ImageDispose($mtFile[$i]) next endfunc #endregion MapTilesAction func printMap() ;; same as save, without getting calibration ;; optimize for page size (DINA4, port. landscape $montage = @scriptdir&"\montage.exe " for $i = 1 to $mtFileNo-1 $tf = $mtFile[$i] if $tf <> "" Then $montage &= $tf&" " EndIf Next $montage &= "-tile "&$mtirows&"x"&$mtiCols&" -geometry "&$mtSize&"x"&$mtSize&"+0+0 "&$cachePath&"new.png" runwait($montage) shellexecute($cachePath&"new.png") endfunc func saveMap() ;; for testing. Must be orghanized $montage = @scriptdir&"\montage.exe " for $i = 1 to $mtFileNo-1 $tf = $mtFile[$i] if $tf <> "" Then $montage &= $tf&" " EndIf Next $montage &= "-tile "&$mtirows&"x"&$mtiCols&" -geometry "&$mtSize&"x"&$mtSize&"+0+0 "&$cachePath&"new.png" runwait($montage) ;;get calibration endfunc func saveMapAs($filePath,$filename) ;; for testing. Must be orghanized $montage = @scriptdir&"\montage.exe " for $i = 1 to $mtFileNo-1 $tf = $mtFile[$i] if $tf <> "" Then $montage &= $tf&" " EndIf Next ;; put tiles together $montage &= "-tile "&$mtirows&"x"&$mtiCols&" -geometry "&$mtSize&"x"&$mtSize&"+0+0 "&$filePath&$filename runwait($montage) ;;get calibration $x = stringsplit($mtFile[1],"_") $top = TileNumberToLonLat($x[2],$x[3],$x[4]) $x = stringsplit($mtFile[$mtFileNo-1],"_") $bot = TileNumberToLonLat($x[2]+1,$x[3]+1,$x[4]) ;get topleft of next tile consolewrite(@lf &"TopLeft: NW"& $top &"SE: " &$bot &@lf) $topa = stringsplit($top,",") $tN = $topa[1] $tW = $topa[2] $bota = stringsplit($bot,",") $tS = $bota[1] $tE = $bota[2] ttqvCal($tN,$tW,$tS,$tE,$mtSize*$mtiCols,$mtSize*$mtiRows) pawCal($tN,$tW,$tS,$tE,$mtSize*$mtiCols,$mtSize*$mtiRows) endfunc func TTQvCal($tN,$tW,$tS,$tE,$pW,$pH) $in = stringtrimright($ttqvSaveFn,4) $fr = fileopen(@scriptdir&"\maps\TTQV_ext.cal") $t = fileread($fr) Fileclose($fr) ;MsgBox(0,"",$t) $t = stringreplace($t,"#NorthLat#",$tN) $t = stringreplace($t,"#SouthLat#",$tS) $t = stringreplace($t,"#WestLon#",$tW) $t = stringreplace($t,"#EastLon#",$tE) $t = stringreplace($t,"#MapWidth#",$pW) $t = stringreplace($t,"#MapHigh#",$pH) ;$t = stringreplace($t,"#MapScale#",$Gzoom[$zoom]) $t = stringreplace($t,"#MapScale#",$mapScale_arr[$zoom]) $t = stringreplace($t,"#MapName#",$in) $t = stringreplace($t,"#MapFileName#",$in&".png") $fw = fileopen(@scriptdir&"\maps\"&$in&"_"&stringright($TtqvSaveFn,3)&".cal",2) filewrite($fw,$t) fileclose($fw) endfunc func pawCal($tN,$tW,$tS,$tE,$pW,$pH) $pawConverter = @scriptdir&"\PwMapConvert.exe" $pawSaveDir = guiCtrlRead($Inp_pawSaveDir) $pawSaveFn = $TtqvSaveFn msgbox(0,"",$pawSaveDir&$pawSaveFn ) if fileexists($pawConverter) Then $convert = $pawConverter&" "&$pawSaveDir&$pawSaveFn&",8,,,,,,,,"&$tN&","&$tW&","&$tS&","&$tE&",1,1,1" consolewrite($convert&@lf) runwait($convert) endif endfunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
ReFran Posted April 15, 2011 Author Share Posted April 15, 2011 Mmmh, perhaps I miss something on the first view, but I don't see any improvement. Only HScroll is commented out. br, Reinhard Link to comment Share on other sites More sharing options...
UEZ Posted April 15, 2011 Share Posted April 15, 2011 You are right. Sorry, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now