mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
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
This commit is contained in:
parent
6ce83a796e
commit
024b661036
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# 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.
|
# 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
|
- feature: 98_TRAFFIC: v1.3, map customizable, enhancements, fix JSON error
|
||||||
- change: 76_SMAInverter: changed SMA_logon, enhanced inverter Types
|
- change: 76_SMAInverter: changed SMA_logon, enhanced inverter Types
|
||||||
- feature: 98_DLNARenderer: support $readingFnAttributes
|
- feature: 98_DLNARenderer: support $readingFnAttributes
|
||||||
|
@ -40,10 +40,18 @@
|
|||||||
# 2016-12-15 adding reverseWaypoints attribute, adding weblink with auto create route via gmaps on verbose 5
|
# 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
|
# 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
|
# 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;
|
package main;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
@ -68,7 +76,7 @@ sub TRAFFIC_GetUpdate($);
|
|||||||
my %TRcmds = (
|
my %TRcmds = (
|
||||||
'update' => 'noArg',
|
'update' => 'noArg',
|
||||||
);
|
);
|
||||||
my $TRVersion = '1.3';
|
my $TRVersion = '1.3.1';
|
||||||
|
|
||||||
sub TRAFFIC_Initialize($){
|
sub TRAFFIC_Initialize($){
|
||||||
|
|
||||||
@ -80,7 +88,7 @@ sub TRAFFIC_Initialize($){
|
|||||||
|
|
||||||
$hash->{AttrFn} = "TRAFFIC_Attr";
|
$hash->{AttrFn} = "TRAFFIC_Attr";
|
||||||
$hash->{AttrList} =
|
$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;
|
$readingFnAttributes;
|
||||||
|
|
||||||
$data{FWEXT}{"/TRAFFIC"}{FUNC} = "TRAFFIC";
|
$data{FWEXT}{"/TRAFFIC"}{FUNC} = "TRAFFIC";
|
||||||
@ -165,6 +173,26 @@ sub TRAFFIC_fhemwebFn($$$$) {
|
|||||||
if (ReadingsVal($device,".map","off") eq "on") {
|
if (ReadingsVal($device,".map","off") eq "on") {
|
||||||
$web .= TRAFFIC_GetMap($device);
|
$web .= TRAFFIC_GetMap($device);
|
||||||
$web .= TRAFFIC_weblink($device);
|
$web .= TRAFFIC_weblink($device);
|
||||||
|
|
||||||
|
$web .= "<form method=\"$FW_formmethod\" action=\"$FW_ME$FW_subdir\" >";
|
||||||
|
$web .= FW_hidden("fwcsrf", $defs{$FW_wname}{CSRFTOKEN}) if($FW_CSRF);
|
||||||
|
$web .= FW_hidden("detail", $device);
|
||||||
|
$web .= FW_hidden("dev.attr$device", $device);
|
||||||
|
$web .= "<input style='display:none' type='submit' value='save Zoom' class='attr' id='currentMapZoomSubmit'>";
|
||||||
|
$web .= "<input type='hidden' name='val.attr$device' value='' id='currentMapZoom'>";
|
||||||
|
$web .= "<input type='hidden' name='cmd.attr$device' value='attr'>";
|
||||||
|
$web .= "<input type='hidden' name='arg.attr$device' value='GoogleMapsZoom'>";
|
||||||
|
$web .= "</form>";
|
||||||
|
|
||||||
|
$web .= "<form method=\"$FW_formmethod\" action=\"$FW_ME$FW_subdir\" >";
|
||||||
|
$web .= FW_hidden("fwcsrf", $defs{$FW_wname}{CSRFTOKEN}) if($FW_CSRF);
|
||||||
|
$web .= FW_hidden("detail", $device);
|
||||||
|
$web .= FW_hidden("dev.attr$device", $device);
|
||||||
|
$web .= "<input style='display:none' type='submit' value='save Center' class='attr' id='currentMapCenterSubmit'>";
|
||||||
|
$web .= "<input type='hidden' name='val.attr$device' value='' id='currentMapCenter'>";
|
||||||
|
$web .= "<input type='hidden' name='cmd.attr$device' value='attr'>";
|
||||||
|
$web .= "<input type='hidden' name='arg.attr$device' value='GoogleMapsCenter'>";
|
||||||
|
$web .= "</form>";
|
||||||
}
|
}
|
||||||
return $web;
|
return $web;
|
||||||
}
|
}
|
||||||
@ -176,10 +204,10 @@ sub TRAFFIC_GetMap($@){
|
|||||||
|
|
||||||
my $debugPoly = $hash->{helper}{'Poly'};
|
my $debugPoly = $hash->{helper}{'Poly'};
|
||||||
my $returnDebugPoly = $hash->{helper}{'return_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){
|
if(!$debugPoly || !$GoogleMapsCenter){
|
||||||
return "<div>please update your map first</div>";
|
return "<div>please update your device first</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
my%GoogleMapsStyles=(
|
my%GoogleMapsStyles=(
|
||||||
@ -190,10 +218,11 @@ sub TRAFFIC_GetMap($@){
|
|||||||
);
|
);
|
||||||
my $selectedGoogleMapsStyle = $GoogleMapsStyles{ AttrVal($name, "GoogleMapsStyle", 'default' )};
|
my $selectedGoogleMapsStyle = $GoogleMapsStyles{ AttrVal($name, "GoogleMapsStyle", 'default' )};
|
||||||
|
|
||||||
my ( $GoogleMapsWidth ) = AttrVal($name, "GoogleMapsSize", '800,600') =~ m/(\d+),\d+/;
|
# load map scale and zoom from attr, override if empty/na
|
||||||
my ( $GoogleMapsHeight ) = AttrVal($name, "GoogleMapsSize", '800,600') =~ m/\d+,(\d+)/;
|
my ( $GoogleMapsWidth, $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 ( $GoogleMapsZoom ) = AttrVal($name, "GoogleMapsZoom", '10');
|
||||||
my ( $GoogleMapsStroke2 ) = AttrVal($name, "GoogleMapsStroke", '#4cde44,#FF0000') =~ m/#[a-zA-z0-9]+,(#[a-zA-z0-9]+)/;
|
|
||||||
|
my ( $GoogleMapsStroke1, $GoogleMapsStroke2 ) = AttrVal($name, "GoogleMapsStroke", '#4cde44,#FF0000') =~ m/(#[a-zA-z0-9]+),(#[a-zA-z0-9]+)/;
|
||||||
|
|
||||||
my $GoogleMapsDisableUI;
|
my $GoogleMapsDisableUI;
|
||||||
$GoogleMapsDisableUI = "disableDefaultUI: true," if AttrVal($name, "GoogleMapsDisableUI", 0) eq 1;
|
$GoogleMapsDisableUI = "disableDefaultUI: true," if AttrVal($name, "GoogleMapsDisableUI", 0) eq 1;
|
||||||
@ -210,10 +239,11 @@ sub TRAFFIC_GetMap($@){
|
|||||||
#map {width:'.$GoogleMapsWidth.'px;height:'.$GoogleMapsHeight.'px;}
|
#map {width:'.$GoogleMapsWidth.'px;height:'.$GoogleMapsHeight.'px;}
|
||||||
</style>
|
</style>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
var myLatlng = new google.maps.LatLng('.$GoogleMapsLocation.');
|
var myLatlng = new google.maps.LatLng('.$GoogleMapsCenter.');
|
||||||
var myOptions = {
|
var myOptions = {
|
||||||
zoom: 10,
|
zoom: '.$GoogleMapsZoom.',
|
||||||
center: myLatlng,
|
center: myLatlng,
|
||||||
'.$GoogleMapsDisableUI.'
|
'.$GoogleMapsDisableUI.'
|
||||||
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
||||||
@ -246,7 +276,16 @@ sub TRAFFIC_GetMap($@){
|
|||||||
trafficLayer.setMap(map);' if AttrVal($name, "GoogleMapsTrafficLayer", 0) eq 1;
|
trafficLayer.setMap(map);' if AttrVal($name, "GoogleMapsTrafficLayer", 0) eq 1;
|
||||||
|
|
||||||
$map .='
|
$map .='
|
||||||
|
map.addListener("zoom_changed", function() {
|
||||||
|
document.getElementById("currentMapZoom").value = map.getZoom();
|
||||||
|
document.getElementById("currentMapZoomSubmit").style.display = "block";
|
||||||
|
});
|
||||||
|
map.addListener("dragend", function() {
|
||||||
|
document.getElementById("currentMapCenter").value = map.getCenter().lat() + "," + map.getCenter().lng();
|
||||||
|
document.getElementById("currentMapCenterSubmit").style.display = "block";
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodeLevels(encodedLevelsString) {
|
function decodeLevels(encodedLevelsString) {
|
||||||
var decodedLevels = [];
|
var decodedLevels = [];
|
||||||
for (var i = 0; i < encodedLevelsString.length; ++i) {
|
for (var i = 0; i < encodedLevelsString.length; ++i) {
|
||||||
@ -504,7 +543,7 @@ sub TRAFFIC_DoUpdate(){
|
|||||||
$returnJSON->{'READINGS'}->{'eta'} = FmtTime( gettimeofday() + $duration_in_traffic_sec ) if defined($duration_in_traffic_sec);
|
$returnJSON->{'READINGS'}->{'eta'} = FmtTime( gettimeofday() + $duration_in_traffic_sec ) if defined($duration_in_traffic_sec);
|
||||||
|
|
||||||
$returnJSON->{'HELPER'}->{'Poly'} = encode_base64 ($json->{'routes'}[0]->{overview_polyline}->{points});
|
$returnJSON->{'HELPER'}->{'Poly'} = encode_base64 ($json->{'routes'}[0]->{overview_polyline}->{points});
|
||||||
$returnJSON->{'HELPER'}->{'GoogleMapsLocation'} = $json->{'routes'}[0]->{'legs'}[0]->{start_location}->{lat}.','.$json->{'routes'}[0]->{'legs'}[0]->{start_location}->{lng};
|
$returnJSON->{'HELPER'}->{'GoogleMapsCenter'} = $json->{'routes'}[0]->{'legs'}[0]->{start_location}->{lat}.','.$json->{'routes'}[0]->{'legs'}[0]->{start_location}->{lng};
|
||||||
|
|
||||||
if($duration_in_traffic_sec && $duration_sec){
|
if($duration_in_traffic_sec && $duration_sec){
|
||||||
$returnJSON->{'READINGS'}->{'delay'} = prettySeconds($duration_in_traffic_sec - $duration_sec) if AttrVal($name, "outputReadings", "" ) =~ m/text/;
|
$returnJSON->{'READINGS'}->{'delay'} = prettySeconds($duration_in_traffic_sec - $duration_sec) if AttrVal($name, "outputReadings", "" ) =~ m/text/;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user