OpenLayers OpenLayers

Changeset 107

Show
Ignore:
Timestamp:
05/17/06 13:21:57 (3 years ago)
Author:
crschmidt
Message:

Add working code for Markers -- marker layer and marker object. Also add markers.html to demo use of markers functionality.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Layer/Marker.js

    r102 r107  
    44     
    55    // markers: store internal marker list 
    6     markers:null
     6    markers: []
    77     
    88    initialize: function(name) { 
     
    1111     
    1212    // Implement this. It may not need to do anything usually. 
    13     moveTo:function(bounds,zoomChanged) { 
    14      
     13    moveTo: function(bounds,zoomChanged) { 
     14        if (zoomChanged) { 
     15            this.div.innerHTML=""; 
     16            for(i=0; i < this.markers.length; i++) { 
     17                this.drawMarker(this.markers[i]); 
     18            } 
     19        } 
    1520    }, 
    16     addMarker:function(marker) { 
     21    addMarker: function(marker) { 
    1722        this.markers.append(marker); 
     23        if (this.map && this.map.getExtent()) { 
     24            this.drawMarker(marker); 
     25        } 
     26    }, 
     27    drawMarker: function(marker) { 
    1828        var resolution = this.map.getResolution(); 
    1929        var extent = this.map.getExtent(); 
    2030        var pixel = new OpenLayers.Pixel( 
    21                        resolution * (this.lonlat.lon - extent.minlon), 
    22                        resolution * (extent.maxlat - this.lonlat.lat) 
     31                       1/resolution * (marker.lonlat.lon - extent.minlon), 
     32                       1/resolution * (extent.maxlat - marker.lonlat.lat) 
    2333                       ); 
    2434        var m = marker.generateMarker(pixel); 
    2535        this.div.appendChild(m); 
    26     }, 
     36    } 
    2737}); 
  • trunk/openlayers/lib/OpenLayers/Marker.js

    r102 r107  
    2929    }, 
    3030    generateMarker: function(pixel) { 
    31         var markerObject; 
    32         // Create a div here, and set the location to the pixel above 
     31        // Create a div here, and set the location to the pixel above modified 
     32        // by the icon size. 
     33        var markerObject = OpenLayers.Util.createImage( 
     34            this.icon.url, 
     35            this.icon.size, 
     36            new OpenLayers.Pixel( 
     37              pixel.x-(this.icon.size.w/2),  
     38              pixel.y-this.icon.size.h) 
     39            ); 
    3340        return markerObject; 
    3441    }