OpenLayers OpenLayers

Ticket #103: 103.patch

File 103.patch, 7.4 kB (added by crschmidt, 10 months ago)
  • tests/Control/test_Attribution.html

    old new  
     1<html> 
     2<head> 
     3  <script src="../../lib/OpenLayers.js"></script> 
     4  <script type="text/javascript"><!-- 
     5    var map;  
     6    function test_01_Control_Attribution_constructor (t) { 
     7        t.plan( 2 ); 
     8     
     9        control = new OpenLayers.Control.Attribution(); 
     10        t.ok( control instanceof OpenLayers.Control.Attribution, "new OpenLayers.Control returns object" ); 
     11        t.eq( control.displayClass,  "olControlAttribution", "displayClass is correct" ); 
     12    } 
     13    function test_Control_Attribution_draw (t) { 
     14        t.plan(3); 
     15        control = new OpenLayers.Control.Attribution(); 
     16        map = new OpenLayers.Map("map"); 
     17        map.addControl(control); 
     18        map.addLayer(new OpenLayers.Layer("name",{'attribution':'My layer!'})); 
     19        t.eq(control.div.innerHTML, 'My layer!', "Attribution correct with one layer."); 
     20        map.addLayer(new OpenLayers.Layer("name", {'attribution':'My layer 2!'})); 
     21        t.eq(control.div.innerHTML, 'My layer!, My layer 2!', "Attribution correct with two layers."); 
     22        control.seperator = '|'; 
     23        map.addLayer(new OpenLayers.Layer("name",{'attribution':'My layer 3!'})); 
     24        t.eq(control.div.innerHTML, 'My layer!|My layer 2!|My layer 3!', "Attribution correct with three layers and diff seperator."); 
     25    }     
     26  // --> 
     27  </script> 
     28</head> 
     29<body> 
     30    <div id="map" style="width: 1024px; height: 512px;"/> 
     31</body> 
     32</html> 
  • tests/list-tests.html

    old new  
    6262    <li>Tile/test_Image.html</li> 
    6363    <li>Tile/test_WFS.html</li> 
    6464    <li>test_Control.html</li> 
     65    <li>Control/test_Attribution.html</li> 
    6566    <li>Control/test_SelectFeature.html</li> 
    6667    <li>Control/test_DragFeature.html</li> 
    6768    <li>Control/test_DragPan.html</li> 
  • theme/default/style.css

    old new  
    1010    left: 2px; 
    1111    bottom: 15px;    
    1212} 
    13  
     13.olControlAttribution { 
     14    font-size: smaller;  
     15    right: 3px;  
     16    bottom: 4.5em;  
     17    position: absolute;  
     18    display: block; 
     19
    1420.olControlScale { 
    1521    right: 3px; 
    1622    bottom: 3em; 
  • lib/OpenLayers/Control/Attribution.js

    old new  
     1/* Copyright (c) 2006-2007 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 * @requires OpenLayers/Control.js 
     7 *  
     8 * Class: OpenLayers.Control.Attribution 
     9 * Add attribution from layers to the map display. Uses 'attribution' property 
     10 * of each layer. 
     11 */ 
     12OpenLayers.Control.Attribution =  
     13  OpenLayers.Class(OpenLayers.Control, { 
     14     
     15    /** 
     16     * APIProperty: seperator 
     17     * {String} String used to seperate layers. 
     18     */ 
     19    seperator: ", ", 
     20        
     21    /** 
     22     * Constructor: OpenLayers.Control.Attribution  
     23     *  
     24     * Parameters: 
     25     * options - {Object} Options for control. 
     26     */ 
     27    initialize: function(options) { 
     28        OpenLayers.Control.prototype.initialize.apply(this, arguments); 
     29    }, 
     30 
     31    /** 
     32     * Method: updateAttribution 
     33     * Update attribution string. 
     34     */ 
     35    updateAttribution: function() { 
     36        var attributions = []; 
     37        for(var i=0; i < this.map.layers.length; i++) { 
     38            var layer = this.map.layers[i]; 
     39            if (layer.attribution && layer.getVisibility()) { 
     40                attributions.push( layer.attribution ); 
     41            } 
     42        }   
     43        this.div.innerHTML = attributions.join(this.seperator); 
     44    }, 
     45     
     46    /** 
     47     * Method: draw 
     48     * Initialize control. 
     49     */     
     50    draw: function() { 
     51        OpenLayers.Control.prototype.draw.apply(this, arguments); 
     52        this.map.events.register('changelayer', this, this.updateAttribution); 
     53        this.map.events.register('addlayer', this, this.updateAttribution); 
     54        this.map.events.register('removelayer', this, this.updateAttribution); 
     55        this.updateAttribution(); 
     56        return this.div;     
     57    }, 
     58 
     59    /**  
     60     * Method: destroy 
     61     * Destroy control. 
     62     */ 
     63    destroy: function() { 
     64        this.map.events.unregister("removelayer", this, this.updateAttribution); 
     65        this.map.events.unregister("addlayer", this, this.updateAttribution); 
     66        this.map.events.unregister("changelayer", this, this.updateAttribution); 
     67         
     68        OpenLayers.Control.prototype.destroy.apply(this, arguments); 
     69    },     
     70     
     71    /** @final @type String */ 
     72    CLASS_NAME: "OpenLayers.Control.Attribution" 
     73}); 
  • lib/OpenLayers/Layer.js

    old new  
    7373     */ 
    7474    visibility: true, 
    7575 
     76    /** 
     77     * APIProperty: attribution 
     78     * {String} Attribution string, displayed when Attribution Control is used. 
     79     */ 
     80    attribution: null,  
     81 
    7682    /**  
    7783     * Property: inRange 
    7884     * {Boolean} The current map resolution is within the layer's min/max  
  • lib/OpenLayers.js

    old new  
    125125            "OpenLayers/Handler/MouseWheel.js", 
    126126            "OpenLayers/Handler/Keyboard.js", 
    127127            "OpenLayers/Control.js", 
     128            "OpenLayers/Control/Attribution.js", 
    128129            "OpenLayers/Control/ZoomBox.js", 
    129130            "OpenLayers/Control/ZoomToMaxExtent.js", 
    130131            "OpenLayers/Control/DragPan.js", 
  • 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        var map;  
     13        function init(){ 
     14            map = new OpenLayers.Map('map'); 
     15             
     16            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
     17                "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, 
     18                {'attribution': 'Provided by OpenLayers'});  
     19 
     20            var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic", 
     21                "http://wms.jpl.nasa.gov/wms.cgi",  
     22                {layers: "modis,global_mosaic"},{attribution:"Provided by NASA"}); 
     23 
     24            map.addLayers([ol_wms, jpl_wms]); 
     25            map.addControl(new OpenLayers.Control.LayerSwitcher()); 
     26            map.addControl(new OpenLayers.Control.Attribution()); 
     27            // map.setCenter(new OpenLayers.LonLat(0, 0), 0); 
     28            map.zoomToMaxExtent(); 
     29        } 
     30    </script> 
     31  </head> 
     32  <body onload="init()"> 
     33    <h1>OpenLayers Example</h1> 
     34    <div id="map"></div> 
     35  </body> 
     36</html>