﻿// JScript 文件
function browser(){
	this.isIE=false;
	this.isOP=false;
	this.isNS=false;
	var userAgent=navigator.userAgent;
	if(userAgent.indexOf("MSIE")!=-1&&document.all){
		this.isIE=true;
		return;
	}
	if(window.opera){
		this.isOP=true;
		return;
	}
	if(userAgent.indexOf('Gecko')!=-1||userAgent.indexOf('Netscape6/')!=-1){
		this.isNS=true;
		return;
	}
}
function CustomMark(point,width,height,text,img,label,size){
	this.point_=point;
	this.text_=text;
	this.img_=img;
	this.label_=label;
	this.size_=size;
	this.width_=width;
	this.height_=height;
}
CustomMark.prototype=new GOverlay();
CustomMark.prototype.initialize=function(map){
	var img=document.createElement("img");
	img.src=this.img_;
	img.style.height=this.height_;
	img.style.width=this.width_;
	img.style.position="absolute";

	var span=document.createElement("div");
	span.innerHTML=this.text_;

	var span_text=document.createElement("div");
	span_text.innerHTML=this.label_;
	span_text.style.visibility='hidden';

	if(browser.isIE){
		span.style.color='#ff0000';
		span.style.fontSize='12';
		span.style.filter='glow(Color=black,Strength=1)';
		span_text.style.color='#000000';
		span_text.style.fontSize='12';
		span_text.style.filter='glow(Color=black,Strength=1)';
	}else{
		span.style.color='#ff0000';
		span.style.fontSize='12';
		span.style.filter='glow(Color=white,Strength=0.5)';
		span_text.style.color='#000000';
		span_text.style.fontSize='12';
		span_text.style.backgroundColor="wheat";
		span_text.style.filter='glow(Color=white,Strength=0.5)';
	}
	span.style.width='180px';
	span.style.position="absolute";

	span_text.style.width='180px';
	span_text.style.position="absolute";
	span_text.style.backgroundColor="wheat";
	span_text.style.borderStyle="double";
	span_text.style.borderWidth="2px";
	span_text.style.borderColor="Goldenrod";

	map.getPane(G_MAP_MAP_PANE).appendChild(img);
	map.getPane(G_MAP_MAP_PANE).appendChild(span);
	map.getPane(G_MAP_MAP_PANE).appendChild(span_text);

	this.map_=map;
	this.label_=span;
	this.label2_=span_text;
	this.icon_=img;
	this.icon_.onmouseout=function(){span_text.style.visibility='hidden';};
	this.icon_.onmouseover=function(){span_text.style.visibility='visible'};
}
CustomMark.prototype.remove=function(){
	this.icon_.parentNode.removeChild(this.icon_);
	this.label_.parentNode.removeChild(this.label_);
	this.label2_.parentNode.removeChild(this.label2_);
}
CustomMark.prototype.copy=function(){
	return this;
}
CustomMark.prototype.moveto=function(point){
    this.point_=point;
    this.redraw();
}
CustomMark.prototype.redraw=function(force){
	var c=this.map_.fromLatLngToDivPixel(this.point_);
	this.icon_.style.left=(c.x-this.size_/2)+"px";
	this.icon_.style.top=(c.y-this.size_/2)+"px";
	this.label_.style.left=(c.x+8)+"px";
	this.label_.style.top=(c.y-7)+"px";
	this.label2_.style.left=(c.x+10)+"px";
	this.label2_.style.top=(c.y+3)+"px";
}
function SelectListControl(select_id,width,left,top,onchangehandle) {
    this.select_id = select_id;
    this.width = width;
    this.left = left;
    this.top = top;
    this.onchangehandle = onchangehandle;
}
SelectListControl.prototype = new GControl();
SelectListControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var selectInDiv = document.createElement("select");
  selectInDiv.style.width = this.width;
  selectInDiv.id = this.select_id;
  container.appendChild(selectInDiv);
  GEvent.addDomListener(selectInDiv, "change", this.onchangehandle);
  map.getContainer().appendChild(container);
  return container;
}
SelectListControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(this.left, this.top));
}

function TrackRedoControl() {}
TrackRedoControl.prototype = new GControl();
TrackRedoControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var zoomInDiv = document.createElement("div");
  this.setButtonStyle_(zoomInDiv);
  container.appendChild(zoomInDiv);
  zoomInDiv.appendChild(document.createTextNode("停止轨迹回放"));
  GEvent.addDomListener(zoomInDiv, "click", function() {									//用户中止轨迹回放
    window.clearTimeout(timerTrackID);		
    maps.removeControl(trackControl);														//移除停止轨迹回放div
  });
  map.getContainer().appendChild(container);
  return container;
}
TrackRedoControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(66, 25));
}
TrackRedoControl.prototype.setButtonStyle_ = function(button) {
  button.style.color = "#ff0000";
  button.style.backgroundColor = "white";
  button.style.font = "x-small 宋体";
  button.style.border = "1px solid black";
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.textAlign = "center";
  button.style.width = "100px";
  button.style.cursor = "pointer";
}
function TextualZoomControl() {}
TextualZoomControl.prototype = new GControl();
TextualZoomControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var zoomInDiv = document.createElement("div");
  this.setButtonStyle_(zoomInDiv);
  container.appendChild(zoomInDiv);
  
  zoomInDiv.appendChild(document.createTextNode("清除GPS点"));
  GEvent.addDomListener(zoomInDiv, "click", function() {maps.clearOverlays();});
  map.getContainer().appendChild(container);
  
  return container;
}
TextualZoomControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(66, 7));
}
TextualZoomControl.prototype.setButtonStyle_ = function(button) {
  button.style.color = "#0000ff";
  button.style.backgroundColor = "white";
  button.style.font = "x-small 宋体";
  button.style.border = "1px solid black";
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.textAlign = "center";
  button.style.width = "100px";
  button.style.cursor = "pointer";
}

function LonLatShowControl(width,left,top) {
    this.width = width;
    this.left = left;
    this.top = top;
}

LonLatShowControl.prototype = new GControl();
LonLatShowControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  lonlatDiv = document.createElement("div");
  container.appendChild(lonlatDiv);
  map.getContainer().appendChild(container);
  
  map._LonLatShowControl = this;
  this._map = map;
  this._lonlatDiv = lonlatDiv;
  this.mapClickHandle_ = GEvent.addListener(this._map, 'click', this.onMapClick_);
  return container;
}
LonLatShowControl.prototype.onMapClick_ = function(marker,latlng) {
   if(marker == null) return;
   if(this._LonLatShowControl._lonlatDiv){
        lng = forDight(latlng.lng(),5);
        lat = forDight(latlng.lat(),5);
        this._LonLatShowControl._lonlatDiv.innerHTML = lng + "," + lat;
   }
}
LonLatShowControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(this.left, this.top));
}
function forDight(Dight,How){  
   Dight  =  Math.round  (Dight*Math.pow(10,How))/Math.pow(10,How);  
   return  Dight;  
}  
