/**
 * Author: Akshay Bhurtun
 * Date: 30 May 2008
 *
 *
 * This class represents a marker to be placed on a map. This current 
 * implementation plots a flag and a circle at the base of the flag
 *
 * $Id: CustomMarker.js,v 1.11 2009/02/23 05:55:12 vpulla Exp $
 */

qxp.OO.defineClass("ia.vector.CustomMarker", com.ptvag.webcomponent.map.vector.VectorElement, 
function(x, y) 
{
   com.ptvag.webcomponent.map.vector.VectorElement.call(this);
   var image = "";
   var radius;
   var fill;
   var fillColor;
   
   var self = this;
   
   if (x != null) 
   {
      self.setX(x);
   }
   if (y != null) 
   {
      self.setY(y);
   }
   
   self.getRadius=function()
   {
      return radius;
   };
   
   self.setRadius=function(radius_)
   {
      radius = radius_;
   };
   
   self.setFill=function setFill(fill_)
   {
      fill = fill_;
   };
   
   self.setFillColor=function setFillColor(fillColor_)
   {
      fillColor = fillColor_;
   };
   
   self.getFillColor=function getFillColor()
   {
      return fillColor;
   };
   
   self.getImage = function()
   {
      return image;
   };
   
   self.setImage = function(img)
   {
      image = img;
   };
   
   function getImageObject()
   {
      var imageObj = new Image();
      imageObj.src = image;
      return imageObj;
   };
   // overridden
   self.usesCanvas = function () 
   {
      return true;
   };

   // overridden
   var superDraw = self.draw;
   self.draw = function (container, topLevelContainer, ctx, mapLeft, mapTop, mapZoom) 
   {
      superDraw.apply(self, arguments);
      var suPoint = {x:self.getX(), y:self.getY()};
      var pixCoords = com.ptvag.webcomponent.map.CoordUtil.smartUnit2Pixel(suPoint, mapZoom);
      var realX = pixCoords.x - mapLeft + self.getFlexX();
      var realY = mapTop - pixCoords.y + self.getFlexY();
      
      ctx.lineWidth = self.getLineWidth();
      ctx.beginPath();
      
      var col = self.getColor();
      if(col == null || col.length == 0)
         col = "rgba(0,0,0,1)";
      ctx.fillStyle = col;
      ctx.arc(realX, realY, radius, 0, 2 * Math.PI, false);
      ctx.fill();
      
      ctx.beginPath();  
      if(fill == true)
         ctx.fillStyle=col;
      else
      {
         if(fillColor != null && fillColor.length > 0)
            ctx.fillStyle = fillColor;
         else
            ctx.fillStyle = "rgba(255,255,255,1)";
      }
      ctx.arc(realX, realY, radius-1, 0, 2 * Math.PI, false);
      ctx.fill();

      //var icon = new com.ptvag.webcomponent.map.vector.ImageMarker2();
      //var imageObject = getImageObject();
      //ctx.drawImage(imageObject, realX, realY - imageObject.height);
      
   };
});
qxp.OO.addProperty({name:"x", type:qxp.constant.Type.NUMBER, allowNull:false, defaultValue:4355664});
qxp.OO.addProperty({name:"y", type:qxp.constant.Type.NUMBER, allowNull:false, defaultValue:5464867});
qxp.OO.addProperty({name:"color", type:qxp.constant.Type.STRING, allowNull:false, defaultValue:"rgba(255,0,0,0.7)"});
qxp.OO.addProperty({name:"pixelSize", type:qxp.constant.Type.NUMBER, allowNull:false, defaultValue:20});
qxp.OO.addProperty({name:"lineWidth", type:qxp.constant.Type.NUMBER, allowNull:false, defaultValue:2});

