migrate to OSM

This commit is contained in:
ragu 2022-05-27 17:11:35 +02:00
parent cc4dfcd70f
commit 46f86f6c05
13 changed files with 476 additions and 59 deletions

View file

@ -1985,6 +1985,7 @@ sub stations_available(){
my $op_return = {};
foreach my $id (sort { $record->{$a}->{barcode} <=> $record->{$b}->{barcode} } keys (%$record)){
$return->{$id}->{authed} = "$authed";
$return->{$id}->{capacity} = $record->{$id}->{int05} || 1;
$return->{$id}->{station} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$record->{$id}->{int04}";
$return->{$id}->{uri_operator} = "$varenv->{wwwhost}";

View file

@ -250,7 +250,7 @@ elsif($q->param('request') eq "booking_request"){
($ct_bike,$ct_tariff) = $apif->fetch_bike_tariff(\%varenv,$authraw,$bike,$aowner);
my $sig_book = {
bikeId => "$ct_bike->{txt22}",
bikeId => "$ct_bike->{txt22}",
rentalId => "",
reservationId => ""
};
@ -259,6 +259,7 @@ elsif($q->param('request') eq "booking_request"){
#sig reservation. not mandatory
if($ct_bike->{int11} == 3){
$sig_book = $si->sig_booking(\%varenv,$authraw,$ct_bike,"","reserve");
$sig_book->{bikeId} = "$ct_bike->{txt22}";
}
$response_book = $apif->booking_request($q,\%varenv,$authraw,$bike,$ct_bike,$ct_tariff,$aowner,$gps,$sig_book);
}elsif(!$ct_tariff->{barcode}){
@ -360,7 +361,7 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki
$sig_book = $si->sig_booking(\%varenv,$authraw,"",$ctpos,"reserve_end");
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book);
}else{
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book);
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,"");
}
$response = {%$response, %$booking_values};

View file

@ -7,7 +7,7 @@ package APIsigclient;
#
#380116b5-0522-43da-ab66-477744a731a3
#
use lib qw(/var/www/copri-bike/shareeapp-sx/src);
#use lib qw(/var/www/copri-bike/shareeapp-sx/src);
use warnings;
use strict;
use POSIX;
@ -27,6 +27,7 @@ use Lib::Config;
use Mod::DBtank;
use Mod::Basework;
use Mod::APIfunc;
use Mod::Shareework;
use Data::Dumper;
my $q = new CGI;
@ -34,6 +35,7 @@ my $json = JSON->new->allow_nonref;
my $cf = new Config;
my $dbt = new DBtank;
my $apif = new APIfunc;
my $tk = new Shareework;
my $bw = new Basework;
sub new {
@ -69,7 +71,7 @@ sub sig_available {
my $authed = 0;
my $tariff_content = {};
$authed = 1 if(ref($ctadr) eq "HASH" && $ctadr->{c_id} && $ctadr->{c_id} > 0);
(my $bike_group,my $user_group,$tariff_content,my $user_tour) = $apif->fetch_tariff($varenv->{dbname},$ctadr,$q->param('ctadrcookie'));
(my $bike_group,my $user_group,$tariff_content,my $user_tour) = $apif->fetch_tariff($varenv->{dbname},$ctadr,$q->param('authcookie'));
my $hotline_hash = {
table => "contentuser",
@ -103,7 +105,7 @@ sub sig_available {
#station (mainly using sigojson site object)
my $station = "SX$resp->{site}->{id}";
if($station && looks_like_number($resp->{site}->{id}) && $resp->{site}->{status} eq "ACTIVE" && $resp->{site}->{lat} && $resp->{site}->{lon}){
if($station && looks_like_number($resp->{site}->{id})){
print FILE "Station: $station\n";
$response_out->{$station}->{station} = "$station";
$response_out->{$station}->{authed} = "$authed";
@ -113,14 +115,15 @@ sub sig_available {
$response_out->{$station}->{gps}->{latitude} = "$resp->{site}->{lat}" || "";
$response_out->{$station}->{gps}->{longitude} = "$resp->{site}->{lon}" || "";
$response_out->{$station}->{gps_radius} = "75";
#Other than Active status, should not be used to display information to a customer
$response_out->{$station}->{state} = "defect";
if($resp->{site}->{status} eq "ACTIVE"){#?
if(uc($resp->{site}->{status}) eq "ACTIVE"){
$response_out->{$station}->{state} = "available";
}elsif($resp->{site}->{status} eq "MAINTANANCE"){
}elsif(uc($resp->{site}->{status}) eq "MAINTANANCE"){
$response_out->{$station}->{state} = "maintanance";
}elsif($resp->{site}->{status} eq "OFFLINE"){
$response_out->{$station}->{state} = "defect";
}
$response_out->{$station}->{operator_data} = {
"operator_name" => "",
"operator_hours" => "",
@ -149,6 +152,7 @@ sub sig_available {
}
}
delete $response_out->{$station} if(uc($resp->{site}->{status}) ne "ACTIVE" || !$resp->{site}->{lat} || !$resp->{site}->{lon});
}
}#end stations_available
@ -172,18 +176,19 @@ sub sig_available {
$response_out->{$bike}->{gps}->{longitude} = "$resp->{state}->{lon}" || "";
$response_out->{$bike}->{bike_charge} = "$resp->{energy_level}" || "0";
$response_out->{$bike}->{state} = "defect";
if($resp->{reservation_state} eq "RESERVED"){
if(uc($resp->{reservation_state}) eq "RESERVED"){
$response_out->{$bike}->{state} = "requested";
}elsif($resp->{reservation_state} eq "ACTIVE-RENTAL"){
}elsif(uc($resp->{reservation_state}) eq "ACTIVE-RENTAL"){
$response_out->{$bike}->{state} = "occupied";
}elsif(!$resp->{reservation_state}){
$response_out->{$bike}->{state} = "available";
}
#$response_out->{$bike}->{lock_state} = "undefined";#?
#$response_out->{$bike}->{lock_state} = "locked";# I think default should be unlocked
#1. change can take up to 2 mins to reflect
#2. When a customer will start a reservation, it will always be unlock,
#Sigo software automatically handle this condition
$response_out->{$bike}->{lock_state} = "unlocked";
if($resp->{state}->{locked}){
if($resp->{lock}->{status} eq "locked"){
$response_out->{$bike}->{lock_state} = "locked";
}
$response_out->{$bike}->{system} = "sigo";
@ -249,7 +254,8 @@ sub sig_available {
$return2copri->{$bike}->{int20} = $key;
}
}
delete $response_out->{$bike} if($resp->{status} ne "ACTIVE");#don't view not active bikes
#delete if $resp->{status} ne "ACTIVE" || reservation_state ne Reserved|Active-Rental
delete $response_out->{$bike} if(uc($resp->{status}) ne "ACTIVE" || $resp->{reservation_state});#don't view not active bikes
}
}#end bikes_available
@ -296,6 +302,7 @@ sub sig_booking {
);
}
#reservation end, this sig request is still not defined. maybe end by rentalId
#int10 state will be set on booking_request
elsif($todo eq "reserve_end"){
$endpoint .= "reserve/end";
%json = (
@ -304,6 +311,7 @@ sub sig_booking {
);
}
#rental start
#int10 state will be set on main booking_update
elsif($todo eq "rental"){
$endpoint .= "rental";
my $sig_bikeId = $ctpos->{txt22} || $ct_bike->{txt22};
@ -357,12 +365,27 @@ sub sig_booking {
if($ctpos->{c_id}){
my $rows = 0;
my $update_pos = {
table => "contenttranspos",
mtime => "now()",
owner => "169",
};
my $rows = 0;
#TODO try it with user_bikes_available
#on sig api states maybe not just in time available
#check and save sig bike states
#$q->param(-name=>'request',-value=>"bikes_available");
#(my $response->{bikes},my $return2copri) = $self->sig_available($q,$varenv,$ctadr);
#my $ctrows = 0;
#$ctrows = $tk->sigbike_cupdate($return2copri);
#print FILE "<--- ctrows:$ctrows, update content state with:" . Dumper($return2copri) . "\n";
#foreach my $sid (keys (%{$return2copri})){
# $update_pos->{int10} = "$return2copri->{$sid}->{int10}" if($return2copri->{$sid}->{int10});
# $update_pos->{int20} = "$return2copri->{$sid}->{int20}" if($return2copri->{$sid}->{int20});
#}
$update_pos->{txt10} = "$sig_book->{reservationId}" if($sig_book->{reservationId});
$update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalid});
$rows = $dbt->update_record($dbh,$update_pos,$ctpos);

208
copri4/main/src/Mod/GBFSout.pm Executable file
View file

@ -0,0 +1,208 @@
package Mod::GBFSout;
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
#without login only public Stations have to be viewable:
#https://shareeapp-primary.copri-bike.de/GBFSout
#
#with login and valid autcookie:
#https://shareeapp-primary.copri-bike.de/GBFSout?sessionid=a49aba2b5440be72816db2_rafo87znqx
#
#
use warnings;
use strict;
use POSIX;
use Exporter;
our @ISA = qw (Exporter);
use CGI::Cookie ();
use CGI ':standard';
use Apache2::Const -compile => qw(OK );
use Scalar::Util qw(looks_like_number);
use JSON;
use LWP::UserAgent;
use Lib::Config;
use Mod::DBtank;
use Mod::APIfunc;
use Mod::Basework;
use Data::Dumper;
my $bw = new Basework;
sub handler {
my $r = shift;
my $q = new CGI;
$q->import_names('R');
my $dbt = new DBtank;
my $apif = new APIfunc;
my $cf = new Config;
my %varenv = $cf->envonline();
my $coo = $q->cookie('domcookie') || $R::sessionid || "";
my $users_sharee = { c_id => 0 };
my $api_return = { authcookie => '' };
($api_return,$users_sharee) = $apif->auth_verify($q,$coo,"");
if($dbt->{website}->{$varenv{syshost}}->{merchant_id}){
$api_return->{authcookie} = $dbt->{website}->{$varenv{syshost}}->{merchant_id} if(!$api_return->{authcookie});
}elsif($dbt->{operator}->{$varenv{dbname}}->{merchant_id}){
$api_return->{authcookie} = $dbt->{operator}->{$varenv{dbname}}->{merchant_id} if(!$api_return->{authcookie});
}elsif($dbt->{primary}->{$varenv{dbname}}->{merchant_id}){
$api_return->{authcookie} = $dbt->{primary}->{$varenv{dbname}}->{merchant_id} if(!$api_return->{authcookie});
}
$users_sharee->{c_id} = "0" if(!$users_sharee->{c_id});
$bw->log("GBFSout handler with api_return: ",$api_return,"");
print $q->header(-type => "application/json", -charset => "utf-8", -'Access-Control-Allow-Origin' => "*");
#main
my $project = "all";
$project = $dbt->{website}->{$varenv{syshost}}->{project} if($dbt->{website}->{$varenv{syshost}}->{project});
$project = $dbt->{operator}->{$varenv{dbname}}->{project} if($dbt->{operator}->{$varenv{dbname}}->{project});
#request primary will jsonclient loop_sharees
my $uri_request = $dbt->{primary}->{sharee_primary}->{primaryApp};
#detect DMS, because this will do it directly without loop_sharees
$uri_request = $dbt->{operator}->{$varenv{dbname}}->{operatorApp} if($varenv{dbname} ne "sharee_primary" && $varenv{syshost} =~ /shareedms-/);
if($R::request eq "stations_available"){
station_information($api_return,\%varenv,$users_sharee,$uri_request,$project);
}
if($R::request eq "bikes_available"){
vehicle_status($api_return,\%varenv,$users_sharee,$uri_request,$project);
}
return Apache2::Const::OK;
}
sub station_information {
my $authcookie = shift || { authcookie => '' };
my $varenv = shift;
my $users_sharee = shift || { c_id => 0 };
my $uri_request = shift || "";
my $project = shift || "all";
my $json = JSON->new->allow_nonref;
my $rest_stations = "request=stations_available&project=$project&authcookie=$authcookie->{authcookie}";
my $gbfs_resp = {};
my $stations_json = fetch_primary_json("",$uri_request,$rest_stations);
#decode json to hash
my $response_stations = decode_json($stations_json);
my @gbfs_stations = ();
foreach my $station (keys (%{ $response_stations->{shareejson}->{stations} })) {
#print Dumper($response_stations->{shareejson}->{stations}->{$station});
my %gbfs_station = ();
$gbfs_station{$station}{station_id} = $response_stations->{shareejson}->{stations}->{$station}->{station};
$gbfs_station{$station}{name} = Encode::encode('utf-8', Encode::decode('iso-8859-1',$response_stations->{shareejson}->{stations}->{$station}->{description}));
$gbfs_station{$station}{capacity} = $response_stations->{shareejson}->{stations}->{$station}->{capacity};
$gbfs_station{$station}{lat} = $response_stations->{shareejson}->{stations}->{$station}->{gps}->{latitude};
$gbfs_station{$station}{lon} = $response_stations->{shareejson}->{stations}->{$station}->{gps}->{longitude};
$gbfs_station{$station}{is_charging_station} = 1 if(grep(/300102/, @{$response_stations->{shareejson}->{stations}->{$station}->{station_group}}));#E-L
push (@gbfs_stations, $gbfs_station{$station});
}
$gbfs_resp = {
"last_updated" => 1653031183,
"ttl" => 10,
"version" => "2.2",
"data" => {
"stations" => [ @gbfs_stations ]
}
};
my $jrout = $json->pretty->encode($gbfs_resp);
print $jrout;
return;
}#end station_information
sub vehicle_status {
my $authcookie = shift || { authcookie => '' };
my $varenv = shift;
my $users_sharee = shift || { c_id => 0 };
my $uri_request = shift || "";
my $project = shift || "all";
my $json = JSON->new->allow_nonref;
my $rest_bikes = "request=bikes_available&project=$project&authcookie=$authcookie->{authcookie}";
my $gbfs_resp = {};
my $bikes_json = fetch_primary_json("",$uri_request,$rest_bikes);
#decode json to hash
my $response_bikes = decode_json($bikes_json);
my @gbfs_bikes = ();
foreach my $bike (keys (%{ $response_bikes->{shareejson}->{bikes} })) {
#if($response_bikes->{shareejson}->{bikes}->{$bike}->{station} eq "FR105"){
my %gbfs_bike = ();
$gbfs_bike{$bike}{station_id} = $response_bikes->{shareejson}->{bikes}->{$bike}->{station};
$gbfs_bike{$bike}{vehicle_id} = $response_bikes->{shareejson}->{bikes}->{$bike}->{bike};
$gbfs_bike{$bike}{vehicle_name} = Encode::encode('utf-8', Encode::decode('iso-8859-1',$response_bikes->{shareejson}->{bikes}->{$bike}->{description}));#not part of gbfs
$gbfs_bike{$bike}{vehicle_type_id} = $response_bikes->{shareejson}->{bikes}->{$bike}->{bike_group}[0];
#$gbfs_bike{$bike}{is_reserved} = 0;
#$gbfs_bike{$bike}{is_disabled} = 0;
push (@gbfs_bikes, $gbfs_bike{$bike});
#}
}
#{
#"vehicle_id":"987fd100-b822-4347-86a4-b3eef8ca8b53",
#"last_reported":1609866204,
#"is_reserved":false,
#"is_disabled":false,
#"vehicle_type_id":"def456",
#"current_range_meters":6543.0,
#"station_id":"86",
#"pricing_plan_id":"plan3"
#}
$gbfs_resp = {
"last_updated" => 1653031183,
"ttl" => 0,
"version" => "3.0",
"data" => {
"vehicles" => [ @gbfs_bikes ]
}
};
my $jrout = $json->pretty->encode($gbfs_resp);
print $jrout;
return;
}#end vehicle_status
#requestor
sub fetch_primary_json {
my $self = shift;
my $primary_server = shift || "";
my $rest = shift || "";
my $primary_request = "$primary_server/APIjsonserver?$rest";
$bw->log("GBFS primary_request: ",$primary_request,"");
my $ua = LWP::UserAgent->new;
$ua->agent("sharee GBFSout");
my $req = HTTP::Request->new(GET => "$primary_request");
$req->content_type('application/x-www-form-urlencoded');
$req->content($rest);
#Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
#print $res->content;
return $res->content;
#print $res->status_line, "\n";
}else {
return "";
#print $res->status_line, "\n";
}
}
1;

View file

@ -72,18 +72,14 @@ sub handler {
return Apache2::Const::OK;
}
sub kmlGenerator {
my $authcookie = shift || { authcookie => '' };
my $varenv = shift;
my $users_sharee = shift || { c_id => 0 };
$users_sharee->{c_id} = "0" if(!$users_sharee->{c_id});
my $q = new CGI;
my $dbt = new DBtank;
my $json = JSON->new->allow_nonref;
my $cf = new Config;
my $lang="de";
my $dbh = "";
my $project = "all";
$project = $dbt->{website}->{$varenv->{syshost}}->{project} if($dbt->{website}->{$varenv->{syshost}}->{project});
@ -93,9 +89,12 @@ sub kmlGenerator {
my $icon_red = "Open_Red.png";
my $icon_blue = "Open_Blue.png";
if($project eq "Bayern"){
$icon_green = "LastenradBay-custom-marker-gruen.png";
$icon_red = "LastenradBay-custom-marker-rot.png";
$icon_blue = "LastenradBay-custom-marker-bayblau.png";
$icon_green = "LastenradBay_Standortpfeil_gruen_03a.png";
$icon_red = "LastenradBay_Standortpfeil_rot_03a.png";
$icon_blue = "LastenradBay_Standortpfeil_blau_03a.png";
#$icon_green = "LastenradBay-custom-marker-gruen.png";
#$icon_red = "LastenradBay-custom-marker-rot.png";
#$icon_blue = "LastenradBay-custom-marker-bayblau.png";
}
my $timestamp = strftime "%Y%m%d%H%M%S", localtime;
@ -225,31 +224,9 @@ sub kmlGenerator {
print XML "</Document>\n";
print XML "</kml>\n";
close(XML);
chmod 0666, "$varenv->{basedir}/xml/$kmlfile";
#my $update_kml = {};
#if($users_sharee->{c_id} > 0){
# $update_kml = {
# table => "contentadr",
# atime => "now()",
# c_id => $users_sharee->{c_id},
# };
#}else{
# $update_kml = {
# table => "content",
# mtime => "now()",
# c_id => "3",
# };
#}
#my $dbh_primary = $dbt->dbconnect_extern("sharee_primary");
#$dbt->update_one($dbh_primary,$update_kml,"txt20='$kmlfile'");
#print "station_hash ALL:" . Dumper($station_hash);
#print "bike_hash ALL:" . Dumper($bike_hash);
#
return $kmlfile;
}#end kmlGenerator
#requestor

194
copri4/main/src/Tpl/Karte_osm.pm Executable file
View file

@ -0,0 +1,194 @@
package Karte_osm;
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
use strict;
use warnings;
use CGI ':standard';
use Lib::Config;
use Mod::DBtank;
use Mod::APIfunc;
sub new {
my $class = shift;
my $self = {};
bless($self,$class);
return $self;
}
#Template
sub tpl(){
my $node_meta = shift;
my $users_dms = shift || "";
my $mode = shift || "";
my $varenv = shift;
my $users_sharee = shift || { c_id => 0 };
my $return = shift || "";
my $q = new CGI;
my $dbt = new DBtank;
my $apif = new APIfunc;
my $api_file = "/var/www/copri4/shareeconf/apikeys.cfg";
my $aconf = Config::General->new($api_file);
my %apikeyconf = $aconf->getall;
my $api_return = { authcookie => '' };
my $coo = $q->cookie(-name=>'domcookie') || $R::sessionid;
($api_return,$users_sharee) = $apif->auth_verify($q,$coo,"");
my $initMap = $dbt->{website}->{$varenv->{syshost}}->{initMap};
my $map_zoom = $dbt->{website}->{$varenv->{syshost}}->{map_zoom} || "10";
my $project = "all";
my $uri_request = $dbt->{primary}->{sharee_primary}->{primaryApp};
if($dbt->{website}->{$varenv->{syshost}}->{merchant_id}){
$api_return->{authcookie} = $dbt->{website}->{$varenv->{syshost}}->{merchant_id} if(!$api_return->{authcookie});
$project = $dbt->{website}->{$varenv->{syshost}}->{project} if($dbt->{website}->{$varenv->{syshost}}->{project});
$uri_request = $dbt->{website}->{$varenv->{syshost}}->{operatorWeb};
print $q->div({-class=>"content2_contact"},"Hier können Lastenfahrräder gemietet werden:"),"\n";
}elsif($dbt->{operator}->{$varenv->{dbname}}->{merchant_id}){
$api_return->{authcookie} = $dbt->{operator}->{$varenv->{dbname}}->{merchant_id} if(!$api_return->{authcookie});
$initMap = $dbt->{operator}->{$varenv->{dbname}}->{initMap} if($dbt->{operator}->{$varenv->{dbname}}->{initMap});
$map_zoom = $dbt->{operator}->{$varenv->{dbname}}->{map_zoom} if($dbt->{operator}->{$varenv->{dbname}}->{map_zoom});
$project = $dbt->{operator}->{$varenv->{dbname}}->{project} if($dbt->{operator}->{$varenv->{dbname}}->{project});
$uri_request = $dbt->{operator}->{$varenv->{dbname}}->{operatorDMS};
print $q->div({-style=>'padding-top:25px;'},""),"\n";
}elsif($dbt->{primary}->{$varenv->{dbname}}->{merchant_id}){
$api_return->{authcookie} = $dbt->{primary}->{$varenv->{dbname}}->{merchant_id} if(!$api_return->{authcookie});
$initMap = $dbt->{primary}->{$varenv->{dbname}}->{initMap} if($dbt->{primary}->{$varenv->{dbname}}->{initMap});
$uri_request = $dbt->{primary}->{$varenv->{dbname}}->{primaryDMS};
print $q->div({-style=>'padding-top:25px;'},""),"\n";
}
my $icon_green = "Open_Green.png";
my $icon_red = "Open_Red.png";
my $icon_blue = "Open_Blue.png";
my $mapheight = "600px;";
if($project eq "Bayern"){
$icon_green = "LastenradBay_Standortpfeil_gruen_03a.png";
$icon_red = "LastenradBay_Standortpfeil_rot_03a.png";
$icon_blue = "LastenradBay_Standortpfeil_blau_03a.png";
$mapheight = "800px;" if($varenv->{syshost} !~ /shareedms-/);
}
$users_sharee->{c_id} = "0" if(!$users_sharee->{c_id});
$initMap =~ s/\s//g;
my ($lat,$lng) = split(/,/,$initMap);
print "<div style='background-color:#cccccc;width:100%;margin-top:1em;'>\n";
print<<EOF
<link rel="stylesheet" href="https://unpkg.com/leaflet\@1.8.0/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet\@1.8.0/dist/leaflet.js"
integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ=="
crossorigin=""></script>
<style>
#map {
height: $mapheight
width: 100%;
}
</style>
EOF
;
print "<div id='map'></div>\n";
print<<EOF
<script>
var map = L.map('map').setView([$lat, $lng], $map_zoom);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var icon_green = L.icon({
iconUrl: '$varenv->{metahost}/img/$icon_green',
iconSize: [37, 41],
iconAnchor: [20, 41],
popupAnchor: [-2, -40]
//shadowUrl: 'marker-shadow.png',
//shadowSize: [68, 95],
//shadowAnchor: [22, 94]
});
var icon_red = L.icon({
iconUrl: '$varenv->{metahost}/img/$icon_red',
iconSize: [37, 41],
iconAnchor: [20, 41],
popupAnchor: [-2, -40]
});
Promise.all([
fetch(
"$uri_request/GBFSout?request=stations_available&authcookie=$api_return->{authcookie}"
),
fetch("$uri_request/GBFSout?request=bikes_available&authcookie=$api_return->{authcookie}")
]).then(async ([response1, response2]) => {
const responseData1 = await response1.json();
const responseData2 = await response2.json();
const data1 = responseData1.data.stations;
const data2 = responseData2.data.vehicles;
const layerGroup = L.featureGroup().addTo(map);
data1.forEach(({ lat, lon, name, address, station_id: stationId }) => {
let bikesonstation = '';
console.log('Station: ' + stationId , name);
data2.forEach(({ station_id, vehicle_name, vehicle_id }) => {
if(typeof station_id !== 'undefined' && station_id == stationId){
bikesonstation = bikesonstation.concat('&bull; Verfügbar: ' + vehicle_name + ' ' + vehicle_id + '<br/>');
}
});
console.log(bikesonstation);
//bike_array.forEach((bike, index) => {
//console.log('xxxx ' + index + ':' + bike);
//});
if(bikesonstation){
layerGroup.addLayer(
L.marker([lat, lon], { icon:icon_green }).bindPopup(
`<b>Mietradstation: \${name} \${stationId} </b><br/>
\${bikesonstation}
`
)
);
}else{
layerGroup.addLayer(
L.marker([lat, lon], { icon:icon_red }).bindPopup(
`<b>Mietradstation: \${name} \${stationId} </b><br/>
`
)
);
}
});
map.fitBounds(layerGroup.getBounds());
});
</script>
EOF
;
print "</div>\n";
#print $q->div({-class=>"content2_legende", -style=>'font-weight:bold;'}, "&bull; Ist ein Lastenrad an einer Mietradstation verfügbar?"),"\n";
print $q->div({-class=>"content2_legende"}, $q->img({-style=>'height:38px;', -src=>"$varenv->{metahost}/img/$icon_green"}), "Lastenrad verfügbar"),"\n";
print $q->div({-class=>"content2_legende"}, $q->img({-style=>'height:38px;', -src=>"$varenv->{metahost}/img/$icon_red"}), "Lastenrad nicht verfügbar"),"\n";
#print $q->div({-class=>"content2_legende"}, "&nbsp;"),"\n";
print "$initMap|$varenv->{dbname}|$api_return->{authcookie}|$users_sharee->{c_id}" if($users_dms->{u_id} == $dbt->{copri_conf}->{superu_id});
}
1;

View file

@ -36,10 +36,10 @@ my $dbh = "";
my $todo = $ARGV[1] || "";
my $user_id = $ARGV[2] || "";
my $sig_bike_id = $ARGV[3] || "";
my $pos_id = $ARGV[3] || "";
open(FILE,">>$varenv{logdir}/APIsigclient.log");
print FILE "\n*** $now_dt 'sig_client fork with todo:$todo|user_id:$user_id|sig_bike_id:$sig_bike_id' \n";
print FILE "\n*** $now_dt 'sig_client fork with todo:$todo|user_id:$user_id|pos_id:$pos_id' \n";
#get user and bike in copri by id
my $apref = {
@ -58,10 +58,10 @@ my $posref = {
fetch => "one",
ca_id => "$ctadr->{c_id}",
int10 => "IN::('3','2')",
txt22 => "$sig_bike_id",
c_id => "$pos_id",
};
my $ctpos = { c_id => 0 };
$ctpos = $dbt->fetch_tablerecord($dbh,$posref) if($user_id =~ /^\d+$/ && $user_id > 0 && $sig_bike_id);
$ctpos = $dbt->fetch_tablerecord($dbh,$posref) if($user_id =~ /^\d+$/ && $user_id > 0 && $pos_id);
print FILE "fetched from DB ctadr:$ctadr->{c_id}|ctpos:$ctpos->{c_id}\n";

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1 @@
../../../main/src/Tpl/Karte_osm.pm

View file

@ -74,6 +74,12 @@
Allow from all
</Location>
<Location /GBFSout>
SetHandler perl-script
PerlInitHandler Apache2::Reload
PerlResponseHandler Mod::GBFSout
</Location>
<Location /ajax_json>
SetHandler perl-script
PerlInitHandler Apache2::Reload

View file

@ -343,8 +343,8 @@ EOF
require "Tpl/MandantConf.pm";
$return = &MandantConf::tpl($node_meta,$users_dms,$mode,$return);
}elsif($node_meta->{tpl_id} == 1 && $node_meta->{main_id} == 200017){
require "Tpl/Karte.pm";
&Karte::tpl($node_meta,$users_dms,$mode,$varenv,"",$return);
require "Tpl/Karte_osm.pm";
&Karte_osm::tpl($node_meta,$users_dms,$mode,$varenv,"",$return);
}elsif($node_meta->{ct_table} =~ /contentpos|contentadrpos|users$/){#contentpos or contentadrpos
require "Tpl/SubListe.pm";
$return = &SubListe::tpl($node_meta,$users_dms,$mode,$return);

View file

@ -75,11 +75,11 @@ SSLCertificateKeyFile /etc/letsencrypt/live/example.tld-0003/privkey.pem
Allow from all
</Location>
<Location /APIvelo>
SetHandler perl-script
PerlInitHandler Apache2::Reload
PerlResponseHandler Mod::APIvelo
</Location>
#<Location /APIvelo>
# SetHandler perl-script
# PerlInitHandler Apache2::Reload
# PerlResponseHandler Mod::APIvelo
#</Location>
<Location /APIjsonserver>
SetHandler perl-script
@ -87,6 +87,12 @@ SSLCertificateKeyFile /etc/letsencrypt/live/example.tld-0003/privkey.pem
PerlResponseHandler Mod::APIjsonserver
</Location>
<Location /GBFSout>
SetHandler perl-script
PerlInitHandler Apache2::Reload
PerlResponseHandler Mod::GBFSout
</Location>
<Location /FileOut>
SetHandler perl-script
PerlInitHandler Apache2::Reload

View file

@ -188,8 +188,8 @@ sub tpl(){
print $q->div({-style=>"text-align:left;border:0px dotted #$fgcolor1;"},$q->ul({-id=>'TopNavi'},$lmenu0)),"\n";
if(($node_meta->{tpl_id} == 1 || $node_meta->{tpl_id} == 3) && $node_meta->{main_id} == 200017){
require "Tpl/Karte.pm";
&Karte::tpl($node_meta,$users_dms,$mode,$varenv,$users_sharee,$return);
require "Tpl/Karte_osm.pm";
&Karte_osm::tpl($node_meta,$users_dms,$mode,$varenv,$users_sharee,$return);
}else{
$self->tplselect($node_meta,$users_dms,$mode,$varenv,$users_sharee,$return);
}