/webportal/src/main/webapp/scripts/mapLayers.js
JavaScript | 437 lines | 270 code | 119 blank | 48 comment | 15 complexity | 0d380cd1e6160daecb131235df8f8fe5 MD5 | raw file
1 2var markers,argos,aatams,geo, aatamsWA; 3var lonlat, popupClass, popupContentHTML, iconName, itemLabel; 4var popups = []; 5var AutoSizeFramedCloud = OpenLayers.Class(OpenLayers.Popup.FramedCloud, { 6 'autoSize': true, 7 'panMapIfOutOfView': true 8 }); 9var AutoSizeFramedCloudMinSize = OpenLayers.Class(OpenLayers.Popup.FramedCloud, { 10 'autoSize': true, 11 'minSize': new OpenLayers.Size(400,400), 12 'panMapIfOutOfView': true 13 }); 14var AutoSizeFramedCloudMaxSize = OpenLayers.Class(OpenLayers.Popup.FramedCloud, { 15 'autoSize': true, 16 'maxSize': new OpenLayers.Size(100,100), 17 'panMapIfOutOfView': true 18 }); 19 20function addLayers() { 21 22 // proxy.cgi script provided by OpenLayers written in Python, must be on the same domain 23 OpenLayers.ProxyHost = '/cgi-bin/proxy.cgi?url='; 24 25 var ausimage = new OpenLayers.Layer.Image("auslandia", 26 "img/aus_default.jpg", 27 new OpenLayers.Bounds(0,-90,180,0), 28 new OpenLayers.Size(3600,1800) 29 ); 30 //map.addLayer(ausimage); 31 32 //markers = new OpenLayers.Layer.Markers( "Markers", {isBaseLayer:false}); 33 //map.addLayer(markers); 34 //markers.setVisibility(false); 35 36 37 // addArgos(); 38 //addtestArgos(); 39 //addAatams(); 40 //addWMS130test(); 41 //addWFStest(); 42 //addGeoRssAttams(); 43 //addTestMarkers(); 44 //addTestOverloadMarkers(); // NEEDS A PROXY SETUP TO USE 45 //addMarkers(); 46 //addRssAIMS(); 47 48 49 /* 50 // featureClass: OpenLayers.Feature.WFS, extractAttributes: true, 51 var aatams = new OpenLayers.Layer.WFS("AATAMS","http://obsidian.bluenet.utas.edu.au:8080/deegree-wfs/services?service=WFS", 52 {typename:'aatams:DeploymentSummary', 53 namespace:'xmlns(aatams=http://www.imos.org.au/aatams)', 54 outputformat: 'text/xml; subtype=gml/3.1.1'}, 55 { extractAttributes: true,isBaseLayer: false} 56 ); 57 //map.addLayer(aatams); 58 */ 59 60} 61 62function addWFStest() { 63 64 65 // featureClass: OpenLayers.Feature.WFS, extractAttributes: true, 66 var wfstest = new OpenLayers.Layer.WMS("WFS_test","http://obsidian.bluenet.utas.edu.au:8080/geoserver/wms", 67 {layers:'slip_SWAN-001'}, 68 { extractAttributes: true,isBaseLayer: false} 69 ); 70 map.addLayer(wfstest); 71 72} 73 74function addWMS130test() { 75 // version 1.3.0 creation 76 aatamsWA = new OpenLayers.Layer.WMS("aatamsWA","http://obsidian.bluenet.utas.edu.au:8080/ncWMS/wms", 77 {layers:'67/v', 78 transparent:"true", 79 version: "1.3.0", 80 EXCEPTIONS: "application-vnd.ogc.se_xml", 81 CRS:"EPSG:4326" 82 83 }, 84 {isBaseLayer: false, 85 version: "1.3.0", 86 tileSize: new OpenLayers.Size(32,32), 87 maxExtent: new OpenLayers.Bounds(150,-90,180,-30), 88 displayOutsideMaxExtent: false 89 }); 90 //aatamsWA.displayOutsideMaxExtent = false; 91 92 map.addLayer(aatamsWA); 93 //alert(aatamsWA.getFullRequestString()); 94 95} 96 97function addRssAIMS() { 98 geo = new OpenLayers.Layer.GeoRSS("AIMS-RSS","http://data.aims.gov.au/gbroosdata/services/rss/project/1", 99 {icon: getIcon('plain')}); 100 map.addLayer(geo); 101 //geo.loadRSS(); 102 //getRSSFeatureinfo(geo); 103} 104 105 106 107function addtestArgos() { 108 // Create 850 random features, and give them a "type" attribute that 109 // will be used to style them by size. 110 var features = new Array(850); 111 for (var i=0; i<features.length; i++) { 112 lon = (360 * Math.random()) - 180; 113 lat = (180 * Math.random()) - 90; 114 label = 'id-'+[i]+' at '+lon+' '+lat; 115 features[i] = {'label': label,'lonlat': new OpenLayers.LonLat(lon , lat), 116 'type': 15 + parseInt(15 * Math.random())}; 117 } 118 119 // Create a styleMap to style your features for two different 120 // render intents. The style for the 'default' render intent will 121 // be applied when the feature is first drawn. The style for the 122 // 'select' render intent will be applied when the feature is 123 // selected. 124 var myStyles = new OpenLayers.StyleMap({ 125 "default": new OpenLayers.Style({ 126 pointRadius: "${type}"//, // sized according to type attribute 127 }), 128 "select": new OpenLayers.Style({ 129 }) 130 }); 131 132 // Create a layer and give it your style map. 133 var points = new OpenLayers.Layer.Markers( 134 'Points', {styleMap: myStyles} 135 ); 136 137 138 for (var i=0; i<features.length; i++) { 139 lonlat = features[i]['lonlat']; 140 itemLabel = features[i]['label']; 141 addMarker(argos,'argo', lonlat, AutoSizeFramedCloudMinSize, '<p>this is '+itemLabel+'</p>', itemLabel, false, false, false); 142 } 143 144} 145 146 147function addMarkers() { 148 149 var icon = getIcon('plain'); 150 151 152 153 var err = new OpenLayers.Layer.Markers( "test2", {parentMenuId: "test",menuId: "special1"} ); 154 err.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(137.309937,-39.838604),icon.clone())); 155 err.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(120,-40.6),icon.clone())); 156 map.addLayer(err); 157 158 var ch = new OpenLayers.Layer.Markers( "test3", {parentMenuId: "test",menuId: "special2"} ); 159 ch.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(136.309937,-35.838604),icon.clone())); 160 ch.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(129,-39.6),icon.clone())); 161 map.addLayer(ch); 162 163 164 165} 166 167function addTestMarkers() { 168 169 170 //anchored bubble popup lonlat contents autosize minsize 171 lonlat = new OpenLayers.LonLat(150,-20); 172 popupClass = AutoSizeFramedCloudMinSize; 173 iconName = 'plain'; 174 itemLabel = "A test"; 175 popupContentHTML = '<iframe src="http://www.google.com"></iframe>'; 176 addMarker(markers, iconName, lonlat, popupClass, popupContentHTML, itemLabel, false, true, false); 177 178 //anchored bubble popup smalonlat contents autosize minsize closebox 179 lonlat = new OpenLayers.LonLat(155.5,-30); 180 popupClass = AutoSizeFramedCloud; 181 iconName = 'plain'; 182 itemLabel = "A test"; 183 popupContentHTML = '<div><h4>Test</h4><p><b>Lon:</b> 28.4765625<br><b>Lat:</b> -29.1796875<br><b>Value:</b> test of possibilities</p></div>'; 184 addMarker(markers, iconName, lonlat, popupClass, popupContentHTML, itemLabel, true, true, false); 185 186 //anchored bubble popup bigger contents autosize closebox 187 lonlat = new OpenLayers.LonLat(149.9,-40); 188 popupClass = AutoSizeFramedCloud; 189 iconName = 'plain'; 190 itemLabel = "A test framed cloud"; 191 popupContentHTML = '<iframe src="http://www.google.com"></iframe>'; 192 addMarker(markers, iconName, lonlat, popupClass, popupContentHTML, itemLabel, false, true, false ); 193 194 195 196 197 198} 199 200function addTestOverloadMarkers() { 201 202 203 204 var test = new OpenLayers.Layer.WMS("marine-geo","http://www.marine-geo.org/exe/mapserv", 205 {map:'/home/mgds/web/www.marine-geo.org/htdocs/services/ogc/wms.map', 206 typename:'Stations-World' 207 }, 208 { extractAttributes: false, isBaseLayer: false} 209 ); 210 map.addLayer(test); 211 212} 213 214function addArgostest () { 215 216 // create the parent layer 217 argos = new OpenLayers.Layer.Markers( "Argo Floats", {isBaseLayer:false}); 218 map.addLayer(argos); 219 220 // add markers to argos layer 221 lonlat = new OpenLayers.LonLat(152.9,-45); 222 popupClass = false; 223 iconName = 'argo'; // open new window 224 itemLabel = "Argo 1900047"; 225 popupContentHTML = 'http://www.cmar.csiro.au/remotesensing/oceancurrents/profiles/1900047/latest.html'; 226 addMarker(argos,iconName, lonlat, popupClass, popupContentHTML, itemLabel, false, true, true); 227} 228 229 230function addMarker(thelayer, iconName, lonlat, popupClass, popupContentHTML, itemLabel, closeBox, overflow, window) { 231 232 233 var icon = getIcon(iconName); 234 235 var feature = new OpenLayers.Feature(markers, lonlat,{icon:icon}); 236 feature.closeBox = closeBox; 237 feature.popupClass = popupClass; 238 feature.data.popupContentHTML = popupContentHTML; 239 feature.data.overflow = (overflow) ? "auto" : "hidden"; 240 241 var marker = feature.createMarker(); 242 243 var markerClick = function (evt) { 244 if (this.popup == null) { 245 this.popup = this.createPopup(this.closeBox); 246 map.addPopup(this.popup); 247 this.popup.show(); 248 } else { 249 this.popup.toggle(); 250 } 251 currentPopup = this.popup; 252 OpenLayers.Event.stop(evt); 253 }; 254 var markerTooltip = function(evt) { 255 256 feature.popupClass = OpenLayers.Class(OpenLayers.Popup.Anchored, { 257 'autoSize': true, 'panMapIfOutOfView': true,'closeBox':false}); 258 feature.data.popupContentHTML = markerTooltipDiv(itemLabel); 259 if (this.popup == null) { 260 this.popup = this.createPopup(this.closeBox); 261 map.addPopup(this.popup); 262 this.popup.show(); 263 } else { 264 this.popup.toggle(); 265 } 266 currentPopup = this.popup; 267 OpenLayers.Event.stop(evt); 268 269 } 270 271 var markerURLClick = function (evt) { 272 open(popupContentHTML,'thiswindow'); 273 }; 274 275 if (popupClass) { 276 marker.events.register("mousedown", feature, markerClick); 277 } 278 else { 279 marker.events.register("mouseover", feature, markerTooltip); 280 marker.events.register("mouseout", feature, markerTooltip); 281 marker.events.register("mousedown", feature, markerURLClick); 282 } 283 thelayer.addMarker(marker); 284} 285 286 287function markerTooltipDiv(text){ 288 return "<div class=\"spacer\">"+text+"</div>"; 289} 290 291function getIcon(iconName) { 292 293 var iconArray = new Array(); 294 var size,offset; 295 296 size = new OpenLayers.Size(18,18); 297 offset = new OpenLayers.Pixel(-(size.w/2-8), -size.h+6); 298 iconArray['action'] = new OpenLayers.Icon('img/blank.png',size,offset); 299 300 size = new OpenLayers.Size(20,18); 301 offset = new OpenLayers.Pixel(-(size.w/2-8), -size.h+6); 302 iconArray['plain'] = new OpenLayers.Icon('img/vector-marker.png',size,offset); 303 304 size = new OpenLayers.Size(30,24); 305 offset = new OpenLayers.Pixel(-(size.w/2), -size.h+6); 306 iconArray['argo']= new OpenLayers.Icon('img/argo_float.png',size,offset); 307 308 return iconArray[iconName]; 309} 310 311 312 313function addAatams() { 314 315 aatams = new OpenLayers.Layer.WMS("AATAMS-wms","http://obsidian.bluenet.utas.edu.au:8080/geoserver/wms", 316 {layers:'DEPLOYMENT_SUMMARY2', 317 transparent:"true" 318 }, 319 {isBaseLayer: false}); 320 321 map.addLayer(aatams); 322 323 } 324 325function addArgos() { 326 327 argos = new OpenLayers.Layer.WMS("ARGOS","http://obsidian.bluenet.utas.edu.au:8080/geoserver/wms", 328 {layers:'LAST_PROFILE_POINT', 329 transparent:"true" 330 }, 331 {isBaseLayer: false, 332 tileSize: new OpenLayers.Size(32,32), 333 maxExtent: new OpenLayers.Bounds(150,-90,180,-30), 334 displayOutsideMaxExtent: false}); 335 336 map.addLayer(argos); 337 338 } 339 340function addGeoRssAttams() { 341 geo = new OpenLayers.Layer.GeoRSS("AATAMS-geoRSS","http://obsidian.bluenet.utas.edu.au:8080/geoserver/wms/reflect?layers=DEPLOYMENT_SUMMARY2&format=rss", 342 {icon: getIcon('plain')}); 343 map.addLayer(geo); 344 geo.loadRSS(); 345} 346 347 function crap_to_delete() { 348 349 350 var size = new OpenLayers.Size(150,150); 351 var tempPopup = new OpenLayers.Popup("tpop", 352 lonlat, 353 size, 354 "Loading... please wait...", 355 true, null 356 ); 357 tempPopup.panMapIfOutOfView= true; 358 tempPopup.autoSize = true; 359 tempPopup.keepInMap = true; 360 tempPopup.setBorder("3px solid white"); 361 tempPopup.updateSize(); 362 map.addPopup(tempPopup); 363 364 365 //updateFeatureInfoFilters(url); 366 OpenLayers.loadURL(url, '', this, setHTML, anError); 367 //OpenLayers.loadURL(url, '', this, setHTML_inpop, anError); 368 369} 370 371 372function setHTML(response) { 373 374 375 376 resultPopup.setContentHTML(response.responseText); 377 378 if (true) { 379 setTimeout("clearPopups()",1000); 380 } 381} 382 383 384function setHTML_inpop(response) { 385 386 resultPopup = new OpenLayers.Popup("pop", 387 lonlat, 388 size, 389 "<div><p>No data at </p></div>", 390 true,close); 391 392 393 if (true) { 394 resultPopup.setContentHTML(response.responseText); 395 } 396 else { 397 var closepopup = true; 398 } 399 resultPopup.autoSize = true; 400 resultPopup.panMapIfOutOfView= true; 401 resultPopup.keepInMap = true; 402 resultPopup.updateSize(); 403 resultPopup.setBorder("10px solid white"); 404 map.addPopup(resultPopup,true); // closes all other popups 405 popups.push(resultPopup); 406 if (closepopup) { 407 setTimeout("clearPopups()",3000); 408 } 409 } 410 411 412// server might be down 413function anError(response) { 414 resultPopup.setContentHTML("<div><h3>ERROR</h3>"+response.responseText+"</div>"); 415} 416 417 418 419//Clear the popups 420function clearPopups() { 421 for (var i = 0; i < popups.length; i++) { 422 map.removePopup(popups[i]); 423 } 424 popups = []; 425} 426 427 428 429 430 431 432 433 434 435 436 437