﻿
/*    マーカーの描画　 ----------------------------------------------------------*/

    var c_marker;
    var map;

    function drawMarker(map, id, name, lang, lng, lat, type) {
      var icon = new GIcon();
      var point = new GLatLng(lat, lng);

      /* type に対応するアイコンのセット */

      if ( type == "" )   { type = "0"; }
    
      if ( (type >= "0") && (type <= "9")  )  {
         if (type == "1")	{ icon.image = "../img/red.png";    } else	
         if (type == "2")       { icon.image = "../img/yellow.png"; } else
         if (type == "3")       { icon.image = "../img/green.png";  } else
         if (type == "4")       { icon.image = "../img/blue.png";   } else
         if (type == "5")       { icon.image = "../img/purple.png"; } else
                                { icon.image = "../img/base.png";   }
      icon.iconSize = new GSize(20,34);
 /*     icon.shadow = "./img/shadow.png";  
      icon.shadowSize = new GSize(28, 28); */
      icon.iconAnchor = new GPoint(10, 34);
      icon.infoWindowAnchor = new GPoint(15, 1);
      }

      var options = { title: name,
                      icon : icon,
                      draggable: false,
                      bouncy: false};
      var marker = new GMarker(point, options);
      map.addOverlay(marker);

      GEvent.addListener(marker, "click", function() {

      curMarker(map, id, name, lang, point.x, point.y); 

      }); 

/*      return marker; */

    }

/*    カレントマーカーの描画　 ----------------------------------------------------------*/

    function curMarker(map, id, name, lang, lng, lat) {
      var icon = new GIcon();
      var point = new GLatLng(lat, lng);

      icon.image = "../img/red.png";
      icon.iconSize = new GSize(20,34);
 /*     icon.shadow = "./img/shadow.png";  
      icon.shadowSize = new GSize(28, 28); */
      icon.iconAnchor = new GPoint(10, 34);
      icon.infoWindowAnchor = new GPoint(15, 1);

      if ( id == "" ) {
        var options = { title: name,
                        icon : icon,
                        draggable: false,
                        bouncy: false}; 
        c_marker = new GMarker(point, options);
        map.addOverlay(c_marker);  

        GEvent.addListener(map, "zoomend", function(zoomold,zoomnew) {
          if ( map.getZoom() > 15 ) {
            svOverlay = new GStreetviewOverlay();
            map.addOverlay(svOverlay); 
            } else {
           if ( zoomold > 15 ) { map.removeOverlay(svOverlay); }
          }
        });

      }   else  {

        c_marker.setPoint(point); 
        top.calframe.location.href='http://www.map-asp.net/Spatial_Gateway/pl/LiveE2GM_v3.cgi?id='+id+'&lang='+lang+'&name='+name;

        var myPano;
        myPano = new GStreetviewPanorama(document.getElementById("pano"));
         // myPano = new GStreetviewPanorama(top.document.getElementById("pano"));

          myPOV = {yaw:0,pitch:-10};
          myPano.setLocationAndPOV(point, myPOV);
      GEvent.addListener(myPano, "error", errorHandler);

      }

/*      return marker; */

    }

    function errorHandler(errorCode) {
      if (errorCode == 603) {
        alert("エラー: Flashが使えません");
        return;
      }
    }


// 
function createXMLHttpRequest(cbFunc) {
  var XMLhttpObject = null;
  try {
    XMLhttpObject = new XMLHttpRequest();
  } catch(e) {
      try{
        XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
      }catch(e) {
         try {
           XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
         }catch(e) {
            return null;
          }
       }
     }
  if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
  return XMLhttpObject;
}

function loadCSV(file) {

  httpObj = createXMLHttpRequest(readCSV);
  if (httpObj) {
    httpObj.open("GET",file,true);
    httpObj.send(null);
  }
}

function readCSV() {
  var s_id = document.ajaxForm.requestText.value; 
  if ((httpObj.readyState == 4) && (httpObj.status == 200)) {
    var tabText = httpObj.responseText;
    var CR = String.fromCharCode(13); // 改行コード (CR)
    lineData = tabText.split(CR);
    for (var i=0; i<lineData.length; i++) {
      wCount = lineData[i].split(",");
//alert(lineData[i]);
      nid = wCount[7]; // データ
      lon = wCount[1];
      lat = wCount[2];
      nam = wCount[4];
//alert(s_id);
alert(nid);
alert(nam);

      if ( nid == s_id )  {

        top.mapframe.curMarker(map, s_id, nam, lang, lon, lat);  
        return;
      }
    }


  }
}

