//呼叫資料庫資料
function loadXmlData() {
var xmlfile = 'resights.xml.php';
var speciesid = document.getElementById('species').value;
var flag1_p = document.getElementById('flag1').value;
var flag1_c = document.getElementById('flagcolor1').value;
var flag2_p = document.getElementById('flag2').value;
var flag2_c = document.getElementById('flagcolor2').value;
var flagfilter = '&f1p='+flag1_p+'&f1c='+flag1_c+'&f2p='+flag2_p+'&f2c='+flag2_c;
/*if(flag1_p==""){
flagfilter = "";
}else{
if(flag1_c!=""){
flagfilter = '&f1p='+flag1_p+'&f1c='+flag1_c;
}else{
flagfilter = '&f1p='+flag1_p;
}
if(flag2_p!=""){
if(flag2_p==flag1_p){
if(flag2_p=="R1"){flag2_p="R2";}
if(flag2_p=="R4"){flag2_p="R5";}
if(flag2_p=="L1"){flag2_p="L2";}
if(flag2_p=="L4"){flag2_p="L5";}
}
if(flag2_c!=""){
flagfilter = flagfilter+'&f2p='+flag2_p+'&f2c='+flag2_c;
}else{
flagfilter = flagfilter+'&f2p='+flag2_p;
}
}
}*/
var StartDate = document.getElementById('datestart').value;
var EndDate = document.getElementById('dateend').value;
var pageNum_Recordset1 = document.getElementById("pageNum_Recordset1");
var bounds = map.getBounds();
var bw = bounds.getSouthWest().lng;
var be = bounds.getNorthEast().lng;
var bs = bounds.getSouthWest().lat;
var bn = bounds.getNorthEast().lat;
downloadUrl(xmlfile+"?speciesid="+speciesid+"&bn="+bn+"&be="+be+"&bw="+bw+"&bs="+bs+"&sd="+StartDate+"&ed="+EndDate+"&pageNum_Recordset1="+pageNum_Recordset1.value+flagfilter, function(data) {
var pagecontrol = document.getElementById("pagecontrol");
var resights = data.documentElement.getElementsByTagName("resights");//獲取resights節點
var startrecord = parseInt(resights[0].getAttribute("startRow_Recordset1"))+1;
var endrecord = 0;
if((parseInt(resights[0].getAttribute("startRow_Recordset1"))+parseInt(resights[0].getAttribute("maxRows_Recordset1")))<(parseInt(resights[0].getAttribute("totalRows_Recordset1")))){
endrecord = parseInt(resights[0].getAttribute("startRow_Recordset1"))+parseInt(resights[0].getAttribute("maxRows_Recordset1"));
tourist = tourist + ' ';
}else{
endrecord = parseInt(resights[0].getAttribute("totalRows_Recordset1"));
}
var tourist1 = "The "+startrecord+" ~ "+endrecord+" Records,Total "+resights[0].getAttribute("totalRows_Recordset1")+" Records
";
var tourist2 = "The "+(parseInt(resights[0].getAttribute("pageNum_Recordset1"))+1)+" Page,Total "+(parseInt(resights[0].getAttribute("totalPages_Recordset1"))+1)+" Page";
if(parseInt(resights[0].getAttribute("pageNum_Recordset1"))>0){
tourist2 = ' ' + tourist2;
}
if((parseInt(resights[0].getAttribute("startRow_Recordset1"))+parseInt(resights[0].getAttribute("maxRows_Recordset1")))<(parseInt(resights[0].getAttribute("totalRows_Recordset1")))){
tourist2 = tourist2 + ' ';
}
var tourist = tourist1 + tourist2
pagecontrol.innerHTML = tourist;
// 處理每一個resights節點
markerLayer.clearLayers();
cleardatasheet();
for (var i = 1; i < resights.length; i++) {
addBirds(resights[i],i);
}
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto();
});
});
}
//載入鳥類紀錄
function addBirds(node,j) {
var date = node.getAttribute("date");
var RecordDate = new Date(date.replace("-", "/"));
var StartDate = new Date(document.getElementById('datestart').value);
var EndDate = new Date(document.getElementById('dateend').value);
var resight_sn = node.getAttribute("resight_sn");
var lng = node.getAttribute("lng");
var lat = node.getAttribute("lat");
var locat = node.getAttribute("location");
var observer = node.getAttribute("observer");
var species = node.getAttribute("species");
var region = node.getAttribute("region");
var photolist = node.getAttribute("photolist");
var memberid = node.getAttribute("memberid");
var bandno = node.getAttribute("bandno");
var resighttype = node.getAttribute("resighttype");
if(resighttype=="resight"){
var pngfile = 'images/'+j+'.png';
}else{
var pngfile = 'images/'+j+'.png';
}
var notes = species + "(" + date + ')';
var myIcon = L.icon({
iconUrl: pngfile,
});
var marker = L.marker([lat, lng], {icon: myIcon, title: notes}).addTo(markerLayer);
//插入紀錄表
var Table = document.getElementById("recordlist");
var j=Table.rows.length;
Cell = new Array(7);
Cell[0] = ''+"
"+resight_sn+"";
Cell[1] = ''+species+'';
Cell[2] = ''+date+'
'+locat+"("+region+")";
//Cell[3] = '';
Cell[3] = '';
Cell[4] = observer;
if(photolist!=""){
Cell[5] = '';
}else{
Cell[5] = '';
}
Cell[6] = bandno;
newRow = Table.insertRow(-1);
newRow.setAttribute("align","center");
for(var k=0;k<7;k++){
newcell = newRow.insertCell(-1);
newcell.innerHTML = Cell[k];
if((k==0)){newcell.setAttribute("nowrap",true);}
if((k==4)){newcell.setAttribute("align",'center');}
}
}
function cleardatasheet(){
var Table = document.getElementById("recordlist");
var j=Table.rows.length;
for(var i=0;iLocation(Region)";
Cell[3] = "Mark";
Cell[4] = "Observer";
Cell[5] = "Photo";
Cell[6] = "Band Number";
newRow = Table.insertRow(-1);
newRow.setAttribute("align","center");
for(var k=0;k<7;k++){
newcell = newRow.insertCell(-1);
if((k==1)||(k==2)){
newcell.setAttribute("nowrap",true);
}
newcell.innerHTML = Cell[k];
}
}
/**匯入xml檔
* Returns an XMLHttp instance to use for asynchronous
* downloading. This method will never throw an exception, but will
* return NULL if the browser does not support XmlHttp for any reason.
* @return {XMLHttpRequest|Null}
*/
function createXmlHttpRequest() {
try {
if (typeof ActiveXObject != 'undefined') {
return new ActiveXObject('Microsoft.XMLHTTP');
} else if (window["XMLHttpRequest"]) {
return new XMLHttpRequest();
}
} catch (e) {
changeStatus(e);
}
return null;
};
/**匯入xml函式
* This functions wraps XMLHttpRequest open/send function.
* It lets you specify a URL and will call the callback if
* it gets a status code of 200.
* @param {String} url The URL to retrieve
* @param {Function} callback The function to call once retrieved.
*/
function downloadUrl(url, callback) {
var status = -1;
var request = createXmlHttpRequest();
if (!request) {
return false;
}
request.onreadystatechange = function() {
//if (request.readyState == 4) {//有些瀏覽器没有readyState属性
try {
status = request.status;
} catch (e) {
// Usually indicates request timed out in FF.
}
if (status == 200) {
callback(request.responseXML, request.status);
request.onreadystatechange = function() {};
}
//}
}
request.open('GET', url, true);
try {
request.send(null);
} catch (e) {
changeStatus(e);
}
};
/**
* Parses the given XML string and returns the parsed document in a
* DOM data structure. This function will return an empty DOM node if
* XML parsing is not supported in this browser.
* @param {string} str XML string.
* @return {Element|Document} DOM.
*/
function xmlParse(str) {
if (typeof ActiveXObject != 'undefined' && typeof GetObject != 'undefined') {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
}
if (typeof DOMParser != 'undefined') {
return (new DOMParser()).parseFromString(str, 'text/xml');
}
return createElement('div', null);
}
/**
* Appends a JavaScript file to the page.
* @param {string} url
*/
function downloadScript(url) {
var script = document.createElement('script');
script.src = url;
document.body.appendChild(script);
}