OpenLayers OpenLayers

Ticket #721: georsslib.patch

File georsslib.patch, 6.8 kB (added by openlayers, 2 years ago)
  • D:/WORKSPACE/lib/OpenLayers/Layer/GeoRSS.js

    old new  
    1717    * @type str */ 
    1818    location:null, 
    1919 
     20    /** store url of icon file 
     21    * @type str */ 
     22    icon:null, 
     23 
     24    /** store minx 
     25    * @type float */ 
     26    minx:180, 
     27 
     28    /** store maxx 
     29    * @type float */ 
     30    maxx:-180, 
     31 
     32    /** store miny 
     33    * @type float */ 
     34    miny:90, 
     35 
     36    /** store maxy 
     37    * @type float */ 
     38    maxy:-90, 
     39 
     40    /** store popupsize width 
     41    * @type int */ 
     42    popw:180, 
     43 
     44    /** store popupsize height 
     45    * @type int */ 
     46    poph:180, 
     47 
    2048    /** @type Array(OpenLayers.Feature) */ 
    2149    features: null, 
    2250 
     
    2351    /** @type OpenLayers.Feature */ 
    2452    selectedFeature: null, 
    2553 
     54    /** @type OpenLayers.Layer.Boxes */ 
     55    boxes: null, 
     56 
    2657    /** 
    2758    * @constructor 
    2859    * 
     
    2960    * @param {String} name 
    3061    * @param {String} location 
    3162    */ 
    32     initialize: function(name, location) { 
     63    initialize: function(name, location, icon) { 
    3364        OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name]); 
    3465        this.location = location; 
     66        this.icon = icon; 
    3567        this.features = new Array(); 
    3668        OpenLayers.loadURL(location, null, this, this.parseData); 
     69        this.boxes = new OpenLayers.Layer.Boxes( "Boxes" ); 
    3770    }, 
    3871 
    3972    /** 
     
    4275    destroy: function() { 
    4376        this.clearFeatures(); 
    4477        this.features = null; 
     78        this.icon = null; 
     79        OpenLayers.Layer.Markers.prototype.destroy.apply(this.boxes, arguments); 
    4580        OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); 
    4681    }, 
    4782         
     
    80115            } 
    81116        } 
    82117 
     118        var geoms  = new Array(); 
     119        var descs  = new Array(); 
     120        var bboxes = new Array(); 
     121             
    83122        for (var i = 0; i < itemlist.length; i++) { 
    84123            var data = {}; 
    85124            var point = OpenLayers.Util.getNodes(itemlist[i], 'georss:point'); 
     125            var box = OpenLayers.Util.getNodes(itemlist[i], 'georss:box'); 
    86126            var lat = OpenLayers.Util.getNodes(itemlist[i], 'geo:lat'); 
    87127            var lon = OpenLayers.Util.getNodes(itemlist[i], 'geo:long'); 
    88             if (point.length > 0) { 
    89                 var location = point[0].firstChild.nodeValue.split(" "); 
    90                  
    91                 if (location.length !=2) { 
    92                     var location = point[0].firstChild.nodeValue.split(","); 
    93                 } 
    94             } else if (lat.length > 0 && lon.length > 0) { 
    95                 var location = [parseFloat(lat[0].firstChild.nodeValue), parseFloat(lon[0].firstChild.nodeValue)]; 
    96             } else { 
    97                 continue; 
    98             } 
    99             location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0])); 
    100              
     128            var bounds = null; 
     129                         
    101130            /* Provide defaults for title and description */ 
    102131            var title = "Untitled"; 
    103132            try { 
     
    143172              catch (e) {} 
    144173            } 
    145174 
    146             data.icon = OpenLayers.Marker.defaultIcon(); 
    147             data.popupSize = new OpenLayers.Size(250, 120); 
     175            if (this.icon){ 
     176                data.icon = new OpenLayers.Icon(this.icon);//,size,offset 
     177            }else{ 
     178                data.icon = OpenLayers.Marker.defaultIcon(); 
     179            } 
     180             
     181            data.popupSize = new OpenLayers.Size(this.popw, this.poph); 
    148182            if ((title != null) && (description != null)) { 
    149183                contentHTML = '<div class="olLayerGeoRSSClose">[x]</div>';  
    150184                contentHTML += '<div class="olLayerGeoRSSTitle">'; 
     
    157191                contentHTML += '</div>'; 
    158192                data['popupContentHTML'] = contentHTML;                 
    159193            } 
    160             var feature = new OpenLayers.Feature(this, location, data); 
    161             this.features.push(feature); 
    162             var marker = feature.createMarker(); 
    163             marker.events.register('click', feature, this.markerClick); 
    164             this.addMarker(marker); 
     194 
     195            // TODO : Set extent for point feature 
     196            if (point.length > 0) { 
     197                var location = point[0].firstChild.nodeValue.split(" "); 
     198                
     199                if (location.length !=2) { 
     200                    var location = point[0].firstChild.nodeValue.split(","); 
     201                } 
     202 
     203            } else if (lat.length > 0 && lon.length > 0) { 
     204                var location = [parseFloat(lat[0].firstChild.nodeValue), parseFloat(lon[0].firstChild.nodeValue)]; 
     205                 
     206            } else if (box.length > 0) { 
     207                var ext = box[0].firstChild.nodeValue.split(" "); 
     208                bounds = new OpenLayers.Bounds(ext[1], ext[0], ext[3], ext[2]);  
     209                var location = [parseFloat(ext[2]), 
     210                                parseFloat(ext[1])]; 
     211 
     212                if (this.minx == null || (this.minx > parseFloat(ext[1]) && ext[1] != "")) 
     213                {   this.minx = parseFloat(ext[1]); 
     214                } 
     215                if (this.maxx == null || (this.maxx < parseFloat(ext[3]) && ext[3] != "")) 
     216                {   this.maxx = parseFloat(ext[3]); 
     217                } 
     218                if (this.miny == null || (this.miny > parseFloat(ext[0]) && ext[0] != "")) 
     219                {   this.miny = parseFloat(ext[0]); 
     220                } 
     221                if (this.maxy == null || (this.maxy < parseFloat(ext[2]) && ext[2] != "")) 
     222                {   this.maxy = parseFloat(ext[2]); 
     223                } 
     224            } else { 
     225                continue; 
     226            } 
     227 
     228            location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0])); 
     229 
     230     
     231            // Aggregate contents 
     232            var hereAgain = false; 
     233            for(var j = 0; j < geoms.length; j++){ 
     234                if(String(location) == String(geoms[j])){ 
     235                    hereAgain = true; 
     236                    if(descs[j]){ 
     237                        descs[j].popupContentHTML = descs[j].popupContentHTML + contentHTML; // Concatenate contents 
     238                        descs[j].icon.size.w += 2; // Increase icon size 
     239                        descs[j].icon.size.h += 2;  
     240                    }else{ 
     241                        alert("find but void"); 
     242                        descs[j] = data; 
     243                    } 
     244                } 
     245            } 
     246 
     247            if(!hereAgain){ 
     248                var i = geoms.length; 
     249                geoms[i] = location; 
     250                descs[i] = data; 
     251                bboxes[i] = bounds; 
     252            } 
    165253        } 
     254         
     255        // Add all geoms to point and boxes layers 
     256        for(var i = 0; i < geoms.length; i++) 
     257        { 
     258            var feature = new OpenLayers.Feature(this, geoms[i], descs[i]); 
     259            this.features.push(feature); 
     260            var marker = feature.createMarker(); 
     261            marker.events.register('click', feature, this.markerClick); 
     262            this.addMarker(marker); 
     263 
     264            if (bboxes[i]) 
     265            { 
     266                box = new OpenLayers.Marker.Box(bboxes[i], '#cdc450', 1); 
     267                this.boxes.addMarker(box); 
     268            } 
     269        } 
     270 
     271        this.events.triggerEvent("loadend");  
    166272    }, 
    167273     
    168274    /**