OpenLayers OpenLayers

Ticket #103: Attribution.patch

File Attribution.patch, 5.3 kB (added by openlayers, 1 year ago)

A patch for adding the copyright text to each layer

  • examples/attribution.html

    old new  
     1<html xmlns="http://www.w3.org/1999/xhtml"> 
     2  <head> 
     3    <style type="text/css"> 
     4        #map { 
     5            width: 512px; 
     6            height: 512px; 
     7            border: 1px solid black; 
     8        } 
     9    </style> 
     10    <script src="../lib/OpenLayers.js"></script> 
     11    <script type="text/javascript"> 
     12        <!-- 
     13        function init(){ 
     14            var map = new OpenLayers.Map('map'); 
     15 
     16            var options = {  
     17                            resolutions: [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.00137329101], attribution:"Provided by OpenLayers" 
     18            }; 
     19             
     20            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
     21                "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, 
     22                options);  
     23 
     24            var options2 = {  
     25                            resolutions: [0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.00137329101], attribution:"Provided by NASA" 
     26            }; 
     27            var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic", 
     28                "http://wms.jpl.nasa.gov/wms.cgi",  
     29                {layers: "modis,global_mosaic"}, options2); 
     30 
     31            var dm_wms = new OpenLayers.Layer.WMS( "DM Solutions Demo", 
     32                "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap", 
     33                {layers: "bathymetry,land_fn,park,drain_fn,drainage," + 
     34                         "prov_bound,fedlimit,rail,road,popplace", 
     35                 transparent: "true", format: "image/png"}, 
     36                 {minResolution: 0.17578125, 
     37                  maxResolution: 0.703125}); 
     38 
     39            map.addLayers([ol_wms, jpl_wms, dm_wms]); 
     40            map.addControl(new OpenLayers.Control.LayerSwitcher()); 
     41            map.addControl(new OpenLayers.Control.Attribution()); 
     42            // map.setCenter(new OpenLayers.LonLat(0, 0), 0); 
     43            map.zoomToMaxExtent(); 
     44        } 
     45        // --> 
     46    </script> 
     47  </head> 
     48  <body onload="init()"> 
     49    <h1>OpenLayers Example</h1> 
     50    <div id="map"></div> 
     51  </body> 
     52</html> 
  • lib/OpenLayers.js

    old new  
    120120        "OpenLayers/Control/DrawFeature.js", 
    121121        "OpenLayers/Control/Panel.js", 
    122122        "OpenLayers/Control/SelectFeature.js", 
     123        "OpenLayers/Control/Attribution.js",         
    123124        "OpenLayers/Geometry.js", 
    124125        "OpenLayers/Geometry/Rectangle.js", 
    125126        "OpenLayers/Geometry/Collection.js", 
  • lib/OpenLayers/Control/Attribution.js

    old new  
     1/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4 
     5/** 
     6 * @class 
     7 *  
     8 * @requires OpenLayers/Control.js 
     9 */ 
     10OpenLayers.Control.Attribution = OpenLayers.Class.create(); 
     11OpenLayers.Control.Attribution.prototype =  
     12  OpenLayers.Class.inherit( OpenLayers.Control, { 
     13                
     14 /** 
     15     * @constructor 
     16     *  
     17     * @param {DOMElement} options Options for control. 
     18     */ 
     19    initialize: function(options) { 
     20        OpenLayers.Control.prototype.initialize.apply(this, arguments); 
     21    }, 
     22 
     23    updateAttribution: function() { 
     24          var attributions = []; 
     25          for(var i=0; i<this.map.layers.length; i++) { 
     26              if (this.map.layers[i].attribution && this.map.layers[i].getVisibility()) { 
     27                  attributions.push( this.map.layers[i].attribution ); 
     28              } 
     29          }    
     30          this.div.innerHTML = attributions.join(", "); 
     31      }, 
     32     
     33    /** 
     34     * @type DOMElement 
     35     */     
     36    draw: function() { 
     37        OpenLayers.Control.prototype.draw.apply(this, arguments); 
     38          OpenLayers.Control.prototype.draw.apply(this, arguments); 
     39          this.div.style.fontSize="smaller"; 
     40          this.div.style.right="3px"; 
     41          this.div.style.bottom="1.5em"; 
     42          this.div.style.position="absolute"; 
     43          // this.map is always null :(  
     44          this.map.events.register('changelayer', this, this.updateAttribution); 
     45          this.map.events.register('changebaselayer', this, this.updateAttribution); 
     46          return this.div;     
     47    }, 
     48    /** @final @type String */ 
     49    CLASS_NAME: "OpenLayers.Control.Attribution" 
     50}); 
  • lib/OpenLayers/Layer.js

    old new  
    5858     */ 
    5959    visibility: true, 
    6060 
     61    /** 
     62    * @type string 
     63    */ 
     64    attribution: "", 
     65     
    6166    /** Whether or not the map's current resolution is within this layer's 
    6267     *   min/max range -- this is set in map's setCenter() whenever zoom 
    6368     *   changes