#include <Array.au3>
; #FUNCTION# ;===============================================================================
;
; Name...........: _googlemaplink
; Description ...: Create googlemap-imagelink
; AutoIt Version : V3.3.8.0
; Syntax.........: _googlemaplink($place[,  $zoom = "12"[, $x = "512"[, $y = "512"[, $type = "roadmap"[, $format = "jpg"]]]]])
; Parameters ....: $place - Mapplace (Cityname/Road/Housenumber or coordinates)
;				   $zoom - Optional: (Default = "12") : Zoomlevel
;				   $x - Optional: (Default = "512") : Mapwidth
;				   $y - Optional: (Default = "512") : Mapheight
;				   $type - Optional: (Default = "roadmap") : Maptype (roadmap, satellite, terrain, hybrid)
;				   $format - Optional: (Default = "png") : Mapformat (png, png32, gif, jpg, jpg-baseline)
; Return values .: Success - Returns : googlemap-imagelink
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - No place set
;                  |2 - Wrong maptype
;			       |3 - Wrong format
; Author ........: chip
;
; ;==========================================================================================
Func _googlemaplink($place, $zoom = "12", $x = "512", $y = "512", $type = "roadmap", $format = "jpg")
	If $place = "" Then
		Return SetError(1, 0, 0)
	ElseIf $type = "roadmap" Or $type = "satellite" Or $type = "terrain" Or $type = "hybrid" Then
		If $format = "png" Or $format = "png32" Or $format = "gif" Or $format = "jpg" Or $format = "jpg-baseline" Then
			Return "http://maps.google.com/maps/api/staticmap?center=" & _URIEncode($place) & "&zoom=" & $zoom & "&size=" & $x & "x" & $y & "&maptype=" & $type & "&format=" & $format & "&sensor=false"
		Else
			Return SetError(3, 0, 0)
		EndIf
	Else
		Return SetError(2, 0, 0)
	EndIf
EndFunc   ;==>_googlemaplink


; #FUNCTION# ;===============================================================================
;
; Name...........: _googlemapzoom
; Description ...: Change zoomlevel
; AutoIt Version : V3.3.8.0
; Syntax.........: _googlemapzoom($link[,  $zoom = "1"])
; Parameters ....: $link - googlemaplink
;				   $zoom - Optional: (Default = "1") : Zoomlevel
; Return values .: Success - Returns : googlemap-imagelink
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - No link set
; Author ........: chip
;
; ;==========================================================================================
Func _googlemapzoom($link, $zoom = "1")
	If $link = "" Then
		Return SetError(1, 0, 0)
	Else
		$split = StringSplit($link, "&", 2)
		$split2 = StringSplit($split[1], "=", 2)
		$split[1] = "zoom=" & $split2[1] + $zoom

		Return _ArrayToString($split, "&")
	EndIf
EndFunc   ;==>_googlemapzoom


; #FUNCTION# ;===============================================================================
;
; Name...........: _googlemapwidth
; Description ...: Change width
; AutoIt Version : V3.3.8.0
; Syntax.........: _googlemapwidth($link[,  $x = "512"])
; Parameters ....: $link - googlemaplink
;				   $x - Optional: (Default = "512") : Mapwidth
; Return values .: Success - Returns : googlemap-imagelink
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - No link set
; Author ........: chip
;
; ;==========================================================================================
Func _googlemapwidth($link, $x = "512")
	If $link = "" Then
		Return SetError(1, 0, 0)
	Else
		$split = StringSplit($link, "&", 2)
		$split2 = StringSplit($split[2], "=", 2)
		$split3 = StringSplit($split2[1], "x", 2)
		$split[2] = "size=" & $x & "x" & $split3[1]

		Return _ArrayToString($split, "&")
	EndIf
EndFunc   ;==>_googlemapwidth


; #FUNCTION# ;===============================================================================
;
; Name...........: _googlemapheigth
; Description ...: Change heigth
; AutoIt Version : V3.3.8.0
; Syntax.........: _googlemapheigth($link[,  $y = "512"])
; Parameters ....: $link - googlemaplink
;				   $y - Optional: (Default = "512") : Mapheigth
; Return values .: Success - Returns : googlemap-imagelink
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - No link set
; Author ........: chip
;
; ;==========================================================================================
Func _googlemapheigth($link, $y = "512")
	If $link = "" Then
		Return SetError(1, 0, 0)
	Else
		$split = StringSplit($link, "&", 2)
		$split2 = StringSplit($split[2], "=", 2)
		$split3 = StringSplit($split2[1], "x", 2)
		$split[2] = "size=" & $split3[0] & "x" & $y

		Return _ArrayToString($split, "&")
	EndIf
EndFunc   ;==>_googlemapheigth


; #FUNCTION# ;===============================================================================
;
; Name...........: _googlemaptype
; Description ...: Change type
; AutoIt Version : V3.3.8.0
; Syntax.........: _googlemaptype($link[,  $type = "roadmap"])
; Parameters ....: $link - googlemaplink
;				   $type - Optional: (Default = "roadmap") : Maptype (roadmap, satellite, terrain, hybrid)
; Return values .: Success - Returns : googlemap-imagelink
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - No link set
;                  |2 - Wrong maptype
; Author ........: chip
;
; ;==========================================================================================
Func _googlemaptype($link, $type = "roadmap")
	If $link = "" Then
		Return SetError(1, 0, 0)
	ElseIf $type = "roadmap" Or $type = "satellite" Or $type = "terrain" Or $type = "hybrid" Then
		$split = StringSplit($link, "&", 2)
		$split2 = StringSplit($split[3], "=", 2)
		$split[3] = "maptype=" & $type
		Return _ArrayToString($split, "&")
	Else
		Return SetError(2, 0, 0)
	EndIf
EndFunc   ;==>_googlemaptype


; #FUNCTION# ;===============================================================================
;
; Name...........: _googlemapformat
; Description ...: Change format
; AutoIt Version : V3.3.8.0
; Syntax.........: _googlemapformat($link[,  $format = "jpg"])
; Parameters ....: $link - googlemaplink
;				   $format - Optional: (Default = "jpg") : Mapformat (png, png32, gif, jpg, jpg-baseline)
; Return values .: Success - Returns : googlemap-imagelink
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - No link set
;                  |2 - Wrong mapformat
; Author ........: chip
;
; ;==========================================================================================
Func _googlemapformat($link, $format = "jpg")
	If $link = "" Then
		Return SetError(1, 0, 0)
	ElseIf $format = "png" Or $format = "png32" Or $format = "gif" Or $format = "jpg" Or $format = "jpg-baseline" Then
		$split = StringSplit($link, "&", 2)
		$split2 = StringSplit($split[4], "=", 2)
		$split[4] = "format=" & $format
		_ArrayDisplay($split)
	Else
		Return SetError(2, 0, 0)
	EndIf

EndFunc   ;==>_googlemapformat


; #FUNCTION# ;===============================================================================
;
; Name...........: _googlemapaddstyle
; Description ...: Add style
; AutoIt Version : V3.3.8.0
; Syntax.........: _googlemapaddstyle($link[, $feature = "all"[, $element = "all"[, $hue = ""[, $lightness = ""[, $saturation = ""[, $gamma = ""[, $inverse = ""[, $visibility = ""]]]]]]]])
; Parameters ....: $link - googlemaplink
; 				   $feature - Optional: (Default = "all") : feature (http://code.google.com/intl/de-DE/apis/maps/documentation/javascript/reference.html#MapTypeStyleFeatureType)
;                  $element - Optional: (Default = "all") : element (all, geometry, lables)
;                  $hue - Optional: (Default = "") : color (RGB-HEX: 0xRRGGBB)
;                  $lightness - Optional: (Default = "") : lightness (-100 to 100)
;                  $saturation - Optional: (Default = "") :  saturation (-100 to 100)
;                  $gamma - Optional: (Default = "") : gamma (0.01 to 10.0)
;                  $inverse - Optional: (Default = "") : lightness-inverse (1)
;                  $visibility - Optional: (Default = "") : element visibility (on, off, simplified)
; Return values .: Success - Returns : googlemap-imagelink
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - No link set
;                  |2 - Wrong hue value.
;                  |3 - Wrong lightness value.
;                  |4 - Wrong saturation value.
;                  |5 - Wrong gamma value.
;                  |6 - Wrong inverse value.
;                  |7 - Wrong visibility value.
; Author ........: chip
;
; ;==========================================================================================
Func _googlemapaddstyle($link, $feature = "all", $element = "all", $hue = "", $lightness = "", $saturation = "", $gamma = "", $inverse = "", $visibility = "")
	If $link = "" Then
		Return SetError(1, 0, 0)
	Else

		$link = $link & "&style=feature:" & $feature & "|element:" & $element

		If Not $hue = "" Then
			If StringLen($hue) = 8 And StringTrimRight($hue, 6) = "0x" Then
				$link = $link & "|hue:" & $hue
			Else
				Return SetError(2, 0, 0)
			EndIf
		EndIf

		If Not $lightness = "" Then
			If $lightness > -101 And $lightness < 101 Then
				$link = $link & "|lightness:" & $lightness
			Else
				Return SetError(3, 0, 0)
			EndIf
		EndIf

		If Not $saturation = "" Then
			If $saturation > -101 And $saturation < 101 Then
				$link = $link & "|saturation:" & $saturation
			Else
				Return SetError(4, 0, 0)
			EndIf
		EndIf

		If Not $gamma = "" Then
			If $gamma > 0 And $gamma < 10 Then
				$link = $link & "|gamma:" & $gamma
			Else
				Return SetError(5, 0, 0)
			EndIf
		EndIf

		If Not $inverse = "" Then
			If $inverse = 1 Then
				$link = $link & "|inverse_lightness:true"
			Else
				Return SetError(6, 0, 0)
			EndIf
		EndIf

		If Not $visibility = "" Then
			If $visibility = "on" Or $visibility = "off" Or $visibility = "simplified" Then
				$link = $link & "|visibility:" & $visibility
			Else
				Return SetError(7, 0, 0)
			EndIf
		EndIf

		Return $link
	EndIf
EndFunc   ;==>_googlemapaddstyle


; #FUNCTION# ;===============================================================================
;
; Name...........: _googlemapaddmarker
; Description ...: Add marker
; AutoIt Version : V3.3.8.0
; Syntax.........: _googlemapaddmarker($link, $place[, $size = "mid"[, $color = ""[, $label = ""]]])
; Parameters ....: $link - googlemaplink
;				   $place - Markerplace (Cityname/Road/Housenumber or coordinates, more markers with the same size/color/label separated with "|" example "Saarbrücker Straße,Berlin|Auguststraße,Berlin")
;				   $size - Optional: (Default = "mid") : Markersize (tiny, mid, small)
;				   $color - Optional: (Default = "") : Markercolor (black, brown, green, purple, yellow, blue, gray, orange, red, white or 24-Bit example: 0xFFFFCC)
;				   $label - Optional: (Default = "") : Markerlabel (a single uppercase alpha-numeric characters, only available by Markersize mid)
; Return values .: Success - Returns : googlemap-imagelink
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - No link set
;                  |2 - No place set
;                  |3 - Wrong size
; Author ........: chip
;
; ;==========================================================================================
Func _googlemapaddmarker($link, $place, $size = "mid", $color = "", $label = "")
	If $link = "" Then
		Return SetError(1, 0, 0)
	ElseIf $place = "" Then
		Return SetError(2, 0, 0)
	Else
		If $size = "tiny" Or $size = "mid" Or $size = "small" Then
			$link = $link & "&markers=size:" & $size

			If Not $color = "" Then
				$link = $link & "|color:" & $color
			EndIf

			If Not $label = "" Then
				$link = $link & "|label:" & $label
			EndIf

			$link = $link & "|" & _URIEncode($place)
		Else
			Return SetError(3, 0, 0)
		EndIf

		Return $link
	EndIf
EndFunc   ;==>_googlemapaddmarker


; #FUNCTION# ;===============================================================================
;
; Name...........: _googlemapaddpath
; Description ...: Add path
; AutoIt Version : V3.3.8.0
; Syntax.........: _googlemapaddpath($link, $place[, $color = "0xff0000FF"[, $weight = ""[, $fillcolor = ""]]])
; Parameters ....: $link - googlemaplink
;				   $place - List of a least to places ((Cityname/Road/Housenumber or coordinates, separated with "|" example "Auguststraße,Berlin|Almstadtstraße,Berlin|Saarbrücker Straße,Berlin"))
;				   $color - Optional: (Default = "0xff0000FF") : Pathcolor (black, brown, green, purple, yellow, blue, gray, orange, red, white or 24-Bit example: 0xFFFFCC)
;				   $weight - Optional: (Default = "") : path thickness
;				   $fillcolor - Optional: (Default = "") : Fill color of the Path
; Return values .: Success - Returns : googlemap-imagelink
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - No link set
;                  |2 - No place set
;                  |3 - Wrong size
; Author ........: chip
;
; ;==========================================================================================
Func _googlemapaddpath($link, $place, $color = "0xff0000FF", $weight = "", $fillcolor = "")
	If $link = "" Then
		Return SetError(1, 0, 0)
	ElseIf $place = "" Then
		Return SetError(2, 0, 0)
	Else
		$link = $link & "&path=color:" & $color

		If Not $weight = "" Then
			$link = $link & "|weight:" & $weight
		EndIf

		If Not $fillcolor = "" Then
			$link = $link & "|fillcolor:" & $fillcolor
		EndIf

		$link = $link & "|" & _URIEncode($place)
	EndIf

	Return $link
EndFunc   ;==>_googlemapaddpath



Func _URIEncode($sData)
	; Prog@ndy
	Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "")
	Local $nChar
	$sData = ""
	For $i = 1 To $aData[0]
		ConsoleWrite($aData[$i] & @CRLF)
		$nChar = Asc($aData[$i])
		Switch $nChar
			Case 45, 46, 48 - 57, 65 To 90, 95, 97 To 122, 126
				$sData &= $aData[$i]
			Case 32
				$sData &= "+"
			Case Else
				$sData &= "%" & Hex($nChar, 2)
		EndSwitch
	Next
	Return $sData
EndFunc   ;==>_URIEncode