國道高速公路交通路況圖擷取小程式


這是一支專門下載國道高速公路交通路況圖的小程式。
程式下載:FreewayTrafficPics.zip
需要環境:dotNet Framework 4.5dotNet Framework 4.5 語言套件

使用方式:

  1. 設定程式設定檔 FreewayTrafficPics.ini 裡面有個 SavePath 路徑,這個是你要儲存圖檔的路徑(該路徑資料夾必須先建立好,程式不會主動建立資料夾)。
  2. 設定 Windows 工作排程器,把程式放入排程,設定為每1分鐘執行一次(或5分鐘,程式會自動把缺少的檔案補齊)。


這個國道路況圖的路況,在交通部高速公路局發布,每分鐘更新一次圖檔,這個圖檔分成北中南 3 個區塊,檔案名稱命名規則如下:

  • 北部:map_n_3_{分鐘}.jpg
  • 中部:map_c_3_{分鐘}.jpg
  • 南部:map_s_3_{分鐘}.jpg


圖片樣式如下:
北部
中部

南部


由我們的程式依照排程每分鐘去抓一次(原則上是抓前一分鐘比較不會有問題),抓到我們指定的資料夾:


※應用方式:
寫個主動式網頁,不管是透過 ajax 或是 refresh 或是 flash 方式都可以,輪播最新的北中南三個檔案就可以在畫面上讓使用者看到畫面了


下面是使用 HTML 展示的範例:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<title>國道路況</title>
<style>
body{margin:0px;padding:0px;}
#showit{
width:427px;
height:480px;
overflow:hidden;
}
#imgbox{
position:relative;
}
img{
width:427px;
height:480px;
}
#wmt{
position:absolute;
float:inherit;
top:48px;
left:50px;
}
</style>
<script type="text/javascript" src="../jquery-1.7.2.min.js"></script>
<script type="text/livescript">
var sqid=0;
var sURL;
var isStop=false;

//若長度小於3位,則在其左邊補0
function padLeft(str){
if(str.length>=3) return str;
else return padLeft("0"+str);
}
//若長度小於3位,則在其右邊補0
function padRight(str){
if(str.length>=3) return str;
else return padRight(str+"0");
}
function RenewImg(){
//
// 因為圖片直接放在web服務器路徑下的tanf(或是以虛擬路徑設定),所以直接取用
sURL = window.location.protocol+'//'+window.location.host+'/tanf/';
var d=new Date();
var n=d.getMinutes() - 5;
if(n<0) n=60+n;
sqid ++;
var p=sqid%3;
//如果第一張開始就更新全部圖片
if(p==1){
//更新圖片
$('#imgbox').hide();
$('#north').attr("src",sURL+"map_n_3_"+n.toString()+".jpg?"+Math.round(Math.random() * 100000));
$('#center').attr("src",sURL+"map_c_3_"+n.toString()+".jpg?"+Math.round(Math.random() * 100000));
$('#south').attr("src",sURL+"map_s_3_"+n.toString()+".jpg?"+Math.round(Math.random() * 100000));
$('#imgbox').show();
//顯示北區
//$('#imgbox').animate({top:0},1000,function(){});
$('#imgbox').css({top:0});
$('#wmt').css({top:48,left:50});
}else if(p==2){
//顯示中區
$('#imgbox').animate({top:-480},1700,function(){});
$('#wmt').animate({top:45,left:50},1700,function(){});
}else{
//顯示南區
$('#imgbox').animate({top:-960},1700,function(){});
$('#wmt').animate({top:450,left:5},1700,function(){});
//重置計數器
spid=0;
}

}
function letsgo(){
if(isStop) return;
RenewImg();
//10秒更新畫面
setTimeout("letsgo()",10000);
}
$(document).ready(function(){
letsgo();
});
</script>
</head>

<body>
<div id="showit">
 <div id="imgbox">
 <img id="north" />
 <img id="center" />
 <img id="south" />
 </div>
 <div id="wmt">資料來源:交通部臺灣區國道高速公路</div>
</div>
</body>
</html>




留言

這個網誌中的熱門文章

【研究】列印的條碼為什麼很難刷(掃描)

C# 使用 Process.Start 執行外部程式

統一發票列印小程式