1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
 
   2  * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
 
   3  * text of the license. */
 
   7 OpenLayers.Marker = Class.create();
 
   8 OpenLayers.Marker.prototype = {
 
  10     /** @type OpenLayers.Icon */
 
  13     /** location of object
 
  14     * @type OpenLayers.LonLat */
 
  17     /** @type OpenLayers.Events*/
 
  20     /** @type OpenLayers.Map */
 
  26     * @param {OpenLayers.Icon} icon
 
  27     * @param {OpenLayers.LonLat lonlat
 
  29     initialize: function(lonlat, icon) {
 
  31         this.icon = (icon) ? icon : OpenLayers.Marker.defaultIcon();
 
  33         this.events = new OpenLayers.Events(this, this.icon.imageDiv, null);
 
  39         if (this.icon != null) {
 
  46     * @param {OpenLayers.Pixel} px
 
  48     * @return A new DOM Image with this markerĀ“s icon set at the 
 
  53         return this.icon.draw(px);
 
  57     * @param {OpenLayers.Pixel} px
 
  59     moveTo: function (px) {
 
  60         if ((px != null) && (this.icon != null)) {
 
  66      * @returns Whether or not the marker is currently visible on screen.
 
  73             var screenBounds = this.map.getExtent();
 
  74             onScreen = screenBounds.contains(this.lonlat.lon, this.lonlat.lat);
 
  80      * @param {float} inflate
 
  82     inflate: function(inflate) {
 
  84             var newSize = new OpenLayers.Size(this.icon.size.w * inflate,
 
  85                                               this.icon.size.h * inflate);
 
  86             this.icon.setSize(newSize);
 
  90     /** @final @type String */
 
  91     CLASS_NAME: "OpenLayers.Marker"
 
  96  * @returns A default OpenLayers.Icon to use for a marker
 
  97  * @type OpenLayers.Icon
 
  99 OpenLayers.Marker.defaultIcon = function() {
 
 100     var url = OpenLayers.Util.getImagesLocation() + "marker.png";
 
 101     var size = new OpenLayers.Size(21, 25);
 
 102     var calculateOffset = function(size) {
 
 103                     return new OpenLayers.Pixel(-(size.w/2), -size.h);
 
 106     return new OpenLayers.Icon(url, size, null, calculateOffset);