ReFran Posted March 23, 2011 Share Posted March 23, 2011 Hi, I've buttons to move the map left, right, up, down. Now i wanted in a first run to spent accelkeys to that task. Thought would be easy, maybe I'm blocked are whatever. I donn't get it to work. Perhabs someone can look over that. Is the part over the main while loop. Thanks in advance, Reinhard expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #Include <WinAPI.au3> #Include <Math.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 ; resing #endregion toDo ;; app related (mt = map tiles, arrays mostly 1 based DIM $mtSize = 256 ;tile size in pixel DIM $mtiRows = 5, $mtiCols = 5 ;other values not correctly support at time DIM $mtFileNo = $mtiRows*$mtiCols+1, $mtFile[$mtFileNo], $mtImg[$mtFileNo] DIM $tileNoActiv, $zoom = 13, $quad 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,$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)) ;GUISetIcon("shell32.dll", 44) ;225) ;TraySetIcon("shell32.dll", 44) ; 225) GuiCtrlCreateLabel("", 49, $mgh-160+2,$mgw-48, 28) GUISetBkColor(0x808080) $dino = GUICtrlCreateIcon(@WindowsDir & "\cursors\dinosaur.ani",-1, 50, $mgh-160,28, 28) GUICtrlSetBkColor(-1,0x808080) ;; 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") $cmb_Zoom = GUICtrlCreateCombo("",230, $mgh-150+30,40,18) GuiCtrlsetdata(-1,"16|15|14|13|12|11|10","13") $inp_zoom = GUICtrlCreateInput(0,272,$mgh-150+30,19,22) $udn_zoom = GUICtrlCreateUpdown($inp_zoom) $btn_go =GUICtrlCreateButton("go",305,$mgh-150+30,30,20) $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") $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() GUICtrlCreateTabItem("") GUISetState() $mtileGUI = GUICreate("", $mgw-4, $mgh-160-2, 2, 2, $WS_CHILD, -1, $mainGUI) GUISetBkColor(0x808080) GUICtrlSetResizing(-1, $GUI_DOCKTOP) GUISetState() _GDIPlus_Startup() $mtileCanvas = _GDIPlus_GraphicsCreateFromHWND($mtileGUI) cacheCheck() MapPvSet($mapPvIdDefault) GUISetState() GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT") ; Set accelerators test Dim $AccelKeys[2][2]=[["{down}", $btn_mDown], ["{right}", $btn_mRight]] GUISetAccelerators($AccelKeys) $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 $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) $inp = GuiCtrlRead($Inp_Addr) if $inp = "" then $inp = $geoBase $xs = GuiCtrlRead($cmb_mapType) $xid = stringmid($xs,2,2) mapPvSet($xid) $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 ;; move by tile-steps case $btn_mUp MapTilesMove("u") case $btn_mDown MapTilesMove("d") case $btn_mleft MapTilesMove("l") case $btn_mRight MapTilesMove("r") 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") else printMap() endif case $btn_saveMap if not FileExists(@scriptdir&"\montage.exe") Then msgbox(0,"", "You need montage.exe to use this function") else saveMap() endif EndSwitch WEnd EndFunc ;==>MainGui Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam) ;_WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_UPDATENOW) if $autoRedraw = 1 then mapDraw() ;_WinAPI_RedrawWindow($mtileGUI, 0, 0, $RDW_VALIDATE) Return $GUI_RUNDEFMSG EndFunc #endregion MainMenuLoop #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 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 MapTilesMove($where) consolewrite(@lf&"MapTilesMove > tileNo: "&$tileNoActiv &" to:"&$where &@lf) $mtmoveStep = guictrlread($inp_mtMoveStep) 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 = 3 ;5te Kachel wird zentriert bei 9Kachel 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") 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_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 eas 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 $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) endfunc func TTQvCal($tN,$tW,$tS,$tE,$pW,$pH) $in = InputBox("","Mapname (ex. filextention)") $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#",$zoom) $t = stringreplace($t,"#MapName#",$in) $t = stringreplace($t,"#MapFileName#",$in&".png") $fw = fileopen(@scriptdir&"\"&$in&"_png.cal",2) filewrite($fw,$t) fileclose($fw) endfunc Link to comment Share on other sites More sharing options...
UEZ Posted March 23, 2011 Share Posted March 23, 2011 Put the lines Dim $AccelKeys[2][2]=[["{down}", $btn_mDown], ["{right}", $btn_mRight]] GUISetAccelerators($AccelKeys) after line 111 ( $btn_dummy = GUICtrlCreateDummy()) and it should work. 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 March 23, 2011 Author Share Posted March 23, 2011 Wouh, so easy. Put it under "GUICtrlCreateTabItem("")", in front of "GUISetState()". Perhabs I've to check the GUISetState() statements at all. The "$btn_dummy = GUICtrlCreateDummy()" I put already only in because on resizing the last created btn on the tab ("Save") didn't resize. I just wondered about that, but checking resizing I will do later. Thanks for the quick responds and help, Reinhard 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