From 024b6610367a95946b734ecd590c59def2846da1 Mon Sep 17 00:00:00 2001 From: jmike <> Date: Fri, 21 Apr 2017 13:47:08 +0000 Subject: [PATCH] 98_TRAFFIC: v1.3.1 attribute changed, buttons to store map settings git-svn-id: https://svn.fhem.de/fhem/trunk@14059 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/98_TRAFFIC.pm | 65 ++++++++++++++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 9204bbecd..6d61cacfd 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 98_TRAFFIC: v1.3.1, attribute change, map setting save buttons - feature: 98_TRAFFIC: v1.3, map customizable, enhancements, fix JSON error - change: 76_SMAInverter: changed SMA_logon, enhanced inverter Types - feature: 98_DLNARenderer: support $readingFnAttributes diff --git a/fhem/FHEM/98_TRAFFIC.pm b/fhem/FHEM/98_TRAFFIC.pm index c77f2819f..17f919cb4 100644 --- a/fhem/FHEM/98_TRAFFIC.pm +++ b/fhem/FHEM/98_TRAFFIC.pm @@ -40,10 +40,18 @@ # 2016-12-15 adding reverseWaypoints attribute, adding weblink with auto create route via gmaps on verbose 5 # 2017-04-21 reduced log entries if verbose is not set, fixed JSON error, Map available through FHEM-Web-toggle, and direct link # Map https, with APIKey, Traffic & customizable, new attributes GoogleMapsStyle,GoogleMapsSize,GoogleMapsLocation,GoogleMapsStroke,GoogleMapsDisableUI +# 2017-04-21 added buttons to save current map settings, renamed attribute GoogleMapsLocation to GoogleMapsCenter # ############################################################################## +#next: +# +# typo on update your map +# optional map zoom +# +# + package main; use strict; @@ -68,7 +76,7 @@ sub TRAFFIC_GetUpdate($); my %TRcmds = ( 'update' => 'noArg', ); -my $TRVersion = '1.3'; +my $TRVersion = '1.3.1'; sub TRAFFIC_Initialize($){ @@ -80,7 +88,7 @@ sub TRAFFIC_Initialize($){ $hash->{AttrFn} = "TRAFFIC_Attr"; $hash->{AttrList} = - "disable:0,1 start_address end_address raw_data:0,1 language waypoints returnWaypoints stateReading outputReadings travelMode:driving,walking,bicycling,transit includeReturn:0,1 updateSchedule GoogleMapsStyle:default,silver,dark,night GoogleMapsSize GoogleMapsLocation GoogleMapsStroke GoogleMapsTrafficLayer:0,1 GoogleMapsDisableUI:0,1 " . + "disable:0,1 start_address end_address raw_data:0,1 language waypoints returnWaypoints stateReading outputReadings travelMode:driving,walking,bicycling,transit includeReturn:0,1 updateSchedule GoogleMapsStyle:default,silver,dark,night GoogleMapsSize GoogleMapsZoom GoogleMapsCenter GoogleMapsStroke GoogleMapsTrafficLayer:0,1 GoogleMapsDisableUI:0,1 " . $readingFnAttributes; $data{FWEXT}{"/TRAFFIC"}{FUNC} = "TRAFFIC"; @@ -165,6 +173,26 @@ sub TRAFFIC_fhemwebFn($$$$) { if (ReadingsVal($device,".map","off") eq "on") { $web .= TRAFFIC_GetMap($device); $web .= TRAFFIC_weblink($device); + + $web .= "
"; + $web .= FW_hidden("fwcsrf", $defs{$FW_wname}{CSRFTOKEN}) if($FW_CSRF); + $web .= FW_hidden("detail", $device); + $web .= FW_hidden("dev.attr$device", $device); + $web .= ""; + $web .= ""; + $web .= ""; + $web .= ""; + $web .= "
"; + + $web .= "
"; + $web .= FW_hidden("fwcsrf", $defs{$FW_wname}{CSRFTOKEN}) if($FW_CSRF); + $web .= FW_hidden("detail", $device); + $web .= FW_hidden("dev.attr$device", $device); + $web .= ""; + $web .= ""; + $web .= ""; + $web .= ""; + $web .= "
"; } return $web; } @@ -176,10 +204,10 @@ sub TRAFFIC_GetMap($@){ my $debugPoly = $hash->{helper}{'Poly'}; my $returnDebugPoly = $hash->{helper}{'return_Poly'}; - my $GoogleMapsLocation = AttrVal($name, "GoogleMapsLocation", $hash->{helper}{'GoogleMapsLocation'}); + my $GoogleMapsCenter = AttrVal($name, "GoogleMapsCenter", $hash->{helper}{'GoogleMapsCenter'}); - if(!$debugPoly || !$GoogleMapsLocation){ - return "
please update your map first
"; + if(!$debugPoly || !$GoogleMapsCenter){ + return "
please update your device first
"; } my%GoogleMapsStyles=( @@ -190,10 +218,11 @@ sub TRAFFIC_GetMap($@){ ); my $selectedGoogleMapsStyle = $GoogleMapsStyles{ AttrVal($name, "GoogleMapsStyle", 'default' )}; - my ( $GoogleMapsWidth ) = AttrVal($name, "GoogleMapsSize", '800,600') =~ m/(\d+),\d+/; - my ( $GoogleMapsHeight ) = AttrVal($name, "GoogleMapsSize", '800,600') =~ m/\d+,(\d+)/; - my ( $GoogleMapsStroke1 ) = AttrVal($name, "GoogleMapsStroke", '#4cde44,#FF0000') =~ m/(#[a-zA-z0-9]+),#[a-zA-z0-9]+/; - my ( $GoogleMapsStroke2 ) = AttrVal($name, "GoogleMapsStroke", '#4cde44,#FF0000') =~ m/#[a-zA-z0-9]+,(#[a-zA-z0-9]+)/; + # load map scale and zoom from attr, override if empty/na + my ( $GoogleMapsWidth, $GoogleMapsHeight ) = AttrVal($name, "GoogleMapsSize", '800,600') =~ m/(\d+),(\d+)/; + my ( $GoogleMapsZoom ) = AttrVal($name, "GoogleMapsZoom", '10'); + + my ( $GoogleMapsStroke1, $GoogleMapsStroke2 ) = AttrVal($name, "GoogleMapsStroke", '#4cde44,#FF0000') =~ m/(#[a-zA-z0-9]+),(#[a-zA-z0-9]+)/; my $GoogleMapsDisableUI; $GoogleMapsDisableUI = "disableDefaultUI: true," if AttrVal($name, "GoogleMapsDisableUI", 0) eq 1; @@ -210,10 +239,11 @@ sub TRAFFIC_GetMap($@){ #map {width:'.$GoogleMapsWidth.'px;height:'.$GoogleMapsHeight.'px;}