/**
 * MapIconMaker v1.0
 * Copyright (c) 2008 Pamela Fox
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 *
 *
 *  Author: Pamela Fox
 *
 *  This gives you static function(s) for creating dynamically sized and
 *  colored marker icons using the Charts API marker output.
 */

var MapIconMaker = {};

MapIconMaker.createRegIcon = function(opts) {
  var taille = opts.taille || 32;
  var nb = opts.nb || 0;
  var color = opts.color || 1;

     
  var baseUrl = "http://www.radarkiller.fr/script/geneicon.php" + "?taille=" + taille + "&nb=" + nb;
  var iconUrl = baseUrl + "&color=" + color;
  var icon = new GIcon();
  icon.image = iconUrl ;
  icon.iconSize = new GSize(taille, taille);
  icon.shadowSize = new GSize(0, 0);
  icon.iconAnchor = new GPoint(Math.floor(taille/2), Math.floor(taille/2));
  icon.infoWindowAnchor = new GPoint(Math.floor(taille/2), Math.floor(taille/12));
  icon.transparent = iconUrl;
  icon.imageMap = [0,0, taille, 0, taille,taille, 0,taille];
     

  return icon;
}


MapIconMaker.createRadar = function(opts) {
  var type = opts.type || "rf" ;
  var vitesse = opts.vitesse || 150;
  var width = opts.width || 28;
  var height = opts.height || 46;

   
  var baseUrl = "http://www.radarkiller.fr/script/ico_";
  var iconUrl = baseUrl + type + vitesse + ".png";
  var icon = new GIcon();
  icon.image = iconUrl;
  icon.iconSize = new GSize(width, height);
  icon.shadowSize = new GSize(Math.floor(width*1.6), height);
  switch(type)
  {
  case 'rf' :
   icon.iconAnchor = new GPoint(Math.floor(width*0.46), height);
  break;
  case 'rm' :
  icon.iconAnchor = new GPoint(Math.floor(width*0.58), height);
  break;
  default :
  icon.iconAnchor = new GPoint(Math.floor(width*0.46), height);
  break;
  }
  icon.infoWindowAnchor = new GPoint(Math.floor(1.4*width/2), 0);

icon.imageMap = [
      width, height,
      width, 0,
      0, 0,
      0, height,
      
  ];
  for (var i = 0; i < icon.imageMap.length; i++) {
    icon.imageMap[i] = parseInt(icon.imageMap[i]);
  }

  return icon;
}

