/webportal/src/main/webapp/scripts/mapLayers.js

http://alageospatialportal.googlecode.com/ · JavaScript · 437 lines · 270 code · 119 blank · 48 comment · 15 complexity · 0d380cd1e6160daecb131235df8f8fe5 MD5 · raw file

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