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 17 17 * @type str */ 18 18 location:null, 19 19 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 20 48 /** @type Array(OpenLayers.Feature) */ 21 49 features: null, 22 50 … … 23 51 /** @type OpenLayers.Feature */ 24 52 selectedFeature: null, 25 53 54 /** @type OpenLayers.Layer.Boxes */ 55 boxes: null, 56 26 57 /** 27 58 * @constructor 28 59 * … … 29 60 * @param {String} name 30 61 * @param {String} location 31 62 */ 32 initialize: function(name, location ) {63 initialize: function(name, location, icon) { 33 64 OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name]); 34 65 this.location = location; 66 this.icon = icon; 35 67 this.features = new Array(); 36 68 OpenLayers.loadURL(location, null, this, this.parseData); 69 this.boxes = new OpenLayers.Layer.Boxes( "Boxes" ); 37 70 }, 38 71 39 72 /** … … 42 75 destroy: function() { 43 76 this.clearFeatures(); 44 77 this.features = null; 78 this.icon = null; 79 OpenLayers.Layer.Markers.prototype.destroy.apply(this.boxes, arguments); 45 80 OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); 46 81 }, 47 82 … … 80 115 } 81 116 } 82 117 118 var geoms = new Array(); 119 var descs = new Array(); 120 var bboxes = new Array(); 121 83 122 for (var i = 0; i < itemlist.length; i++) { 84 123 var data = {}; 85 124 var point = OpenLayers.Util.getNodes(itemlist[i], 'georss:point'); 125 var box = OpenLayers.Util.getNodes(itemlist[i], 'georss:box'); 86 126 var lat = OpenLayers.Util.getNodes(itemlist[i], 'geo:lat'); 87 127 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 101 130 /* Provide defaults for title and description */ 102 131 var title = "Untitled"; 103 132 try { … … 143 172 catch (e) {} 144 173 } 145 174 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); 148 182 if ((title != null) && (description != null)) { 149 183 contentHTML = '<div class="olLayerGeoRSSClose">[x]</div>'; 150 184 contentHTML += '<div class="olLayerGeoRSSTitle">'; … … 157 191 contentHTML += '</div>'; 158 192 data['popupContentHTML'] = contentHTML; 159 193 } 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 } 165 253 } 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"); 166 272 }, 167 273 168 274 /**
