﻿
	//====================================线要素类============================================
	
	/**
	 * 定义线要素类
	 */		
	function KPolyLine(points, color, lineWidth, scale)
    {
        this.points = points?points:new Array(0);		//经过点数组
        this.color = color ? color : "blue";			//颜色
        this.lineWidth = lineWidth ? lineWidth : 2;		//线宽度
        this.opacity = scale ? scale : 0.5;				//透明度
        this.added=false;
        
        if (KBase.getBrowserType()=="IE")
        {
            //创建形状
            this.polyline = KBase.createElement("v:shape");
            KBase.getStyle(this.polyline)["position"] = "absolute";
            this.polyline.unselectable = "on";
            this.polyline.filled = false;
            this.polyline.fill = false;    	
			//创建线样式
            this.stroke = KBase.createElement("v:stroke");
            this.stroke.weight = this.weight;
            this.stroke.color = this.color;
            this.stroke.joinstyle = "round";
            this.stroke.endcap = "round";
            this.stroke.opacity = this.opacity;
            //added by qqm start 2006-12-04
            this.stroke.startarrow="none";
            this.stroke.endarrow="open";
            //added by qqm end 2006-12-04
            this.polyline.appendChild(this.stroke);            
        }
        else
        {
            this.polyline = KBase.createDiv(0);
            this.polyline.ID = "KPolyLineDiv";
            this.graphics = new jsGraphics(this.polyline);            
            KBase.getStyle(this.polyline)["MozOpacity"] = this.opacity;
        }
        KBase.getStyle(this.polyline)["position"] = "absolute";
        KBase.setZIndex(this.polyline, 10);
    }
    
	/**
	 * 初始化
	 */		
    var KPolyLine_initialize = function(mapObject)
    {
        var lineObject = this;
        lineObject.Map = mapObject; 
        
        //获取地图容器大小
        var mapSize=lineObject.Map.getContainerSize();
        
        //设置线要素画布大小和刻度
        this.polyline.style.width=mapSize[0];        
		this.polyline.style.height=mapSize[1];				
        lineObject.polyline.coordsize =mapSize;
        
        lineObject.added = true;
    }
    
    /**
	 * 获取VML画线字符串--用于IE画线
	 */		
    var KPolyLine_getPointsString = function()
    {
        var lineObject = this;
        var pointText="";        
        for (var i = 0; i < lineObject.points.length;i++)
        {            
            if (i==0)
            {
				pointText += "m" + lineObject.points[i][0] + "," + lineObject.points[i][1] + " ";				
			}
			else	//注意：此处"l"为L的小写
			{
				pointText += "l" + lineObject.points[i][0] + "," + lineObject.points[i][1] + " ";
			}
        }        
        return pointText;
    }
    
    /**
	 * 画线--用于FireFox
	 */		
    var KPolyLine_drawGraphics = function()
    {
        var lineObject = this;
        lineObject.graphics.setStroke(lineObject.lineWidth);	//设置线宽度
        lineObject.graphics.setColor(lineObject.color);			//设置颜色
        for (var i = 0; i < lineObject.points.length;i++)
        {            
            if (i!=0)
            {
				lineObject.graphics.drawLine(parseInt(lineObject.points[i-1][0]),parseInt(lineObject.points[i-1][1]),parseInt(lineObject.points[i][0]),parseInt(lineObject.points[i][1]));
			}
        }
        lineObject.graphics.paint();
    }
    
    /**
	 * 重新绘制
	 */	
    var KPolyLine_reDraw = function()
    {
        var lineObject = this;        
        if (KBase.getBrowserType()=="IE")
        {                    
            lineObject.stroke.weight = lineObject.lineWidth;
            lineObject.stroke.color = lineObject.color;            
            this.polyline.path=lineObject.getPointsString();  
        }
        else
        {
            lineObject.graphics.clear();
            lineObject.drawGraphics();
        }        
    }   
    
    /**
	 * 获取HTML控件
	 */	
    var KPolyLine_getObject = function()
    {
        var lineObject = this;
        return lineObject.polyline;
    }
    
    /**
	 * 释放线要素
	 */	
    var KPolyLine_depose = function()
    {
        var lineObject = this;
        if (!KBase.getBrowserType()=="IE")
        {
            lineObject.graphics.clear();
            lineObject.graphics = null;
        }
        lineObject.added = false;
    }
    
    /**
	 * 获取线的颜色
	 */	
    var KPolyLine_getLineColor = function()
    {
        var lineObject = this;
        return lineObject.color;
    }
    
    /**
	 * 获取线的宽度
	 */	
    var KPolyLine_getLineWidth = function()
    {
        var lineObject = this;
        return lineObject.lineWidth;
    }
    
    /**
	 * 设置经过点的集合
	 */	
    var KPolyLine_setPoints = function(points)
    {
        var lineObject = this;
        lineObject.points = points;        
        if (lineObject.Map)
        {
            lineObject.reDraw(true);
        }
    }
    
    /**
	 * 设置线的颜色
	 */	
    var KPolyLine_setLineColor = function(color)
    {
        var lineObject = this;
        lineObject.color = color;        
    }
    
    /**
	 * 设置线的透明度
	 */	
    var KPolyLine_setOpacity = function(scale)
    {
        var lineObject = this;
        lineObject.opacity = scale;
        if (KBase.getBrowserType()=="IE")
        {
            lineObject.stroke.opacity = lineObject.opacity;
        }
        else
        {
            KBase.getStyle(lineObject.polyline)["MozOpacity"] = lineObject.opacity;
        }
    }
    
    /**
	 * 设置线的宽度
	 */	
    var KPolyLine_setLineWidth = function(width)
    {
        var lineObject = this;
        lineObject.lineWidth = width;       
    }
    
    KConfig.defineClass("KPolyLine", KPolyLine);    

    KConfig.defineFunction(KPolyLine, "initialize", KPolyLine_initialize);
    KConfig.defineFunction(KPolyLine, "getPointsString", KPolyLine_getPointsString);
	KConfig.defineFunction(KPolyLine, "drawGraphics", KPolyLine_drawGraphics);
    KConfig.defineFunction(KPolyLine, "reDraw", KPolyLine_reDraw);
    
    KConfig.defineFunction(KPolyLine, "getObject", KPolyLine_getObject);
    KConfig.defineFunction(KPolyLine, "depose", KPolyLine_depose);
    
    KConfig.defineFunction(KPolyLine, "getLineColor", KPolyLine_getLineColor);
    KConfig.defineFunction(KPolyLine, "getLineWidth", KPolyLine_getLineWidth);
    KConfig.defineFunction(KPolyLine, "setPoints", KPolyLine_setPoints);
    KConfig.defineFunction(KPolyLine, "setLineColor", KPolyLine_setLineColor);
    KConfig.defineFunction(KPolyLine, "setOpacity", KPolyLine_setOpacity);
    KConfig.defineFunction(KPolyLine, "setLineWidth", KPolyLine_setLineWidth);
    
    //====================================线要素类[END]==========================================
	
