Advertisement
M00371202

weatherAPI codes in html coursework2

Apr 25th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <body onload="init()">
  2. <div id="basicMap"></div>
  3. </body>
  4.  
  5. <script src="http://openlayers.org/api/OpenLayers.js"></script>
  6. <script src="http://openweathermap.org/js/OWM.OpenLayers.1.3.4.js" ></script>
  7.  
  8. <script type="text/javascript">
  9. var map;
  10. function init() {
  11.  
  12. //Center ( mercator coordinates )
  13. var lat = 7486473;
  14. var lon = 4193332;
  15.  
  16. // if you use WGS 1984 coordinate you should convert to mercator
  17. // lonlat.transform(
  18. // new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
  19. // new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
  20. // );
  21.  
  22. var lonlat = new OpenLayers.LonLat(lon, lat);
  23.  
  24. map = new OpenLayers.Map("basicMap");
  25.  
  26. // Create overlays
  27. // map layer OSM
  28. var mapnik = new OpenLayers.Layer.OSM();
  29. // Create station layer
  30. var stations = new OpenLayers.Layer.Vector.OWMStations("Stations");
  31. // Create weather layer
  32. var city = new OpenLayers.Layer.Vector.OWMWeather("Weather");
  33.  
  34. //connect layers to map
  35. map.addLayers([mapnik, stations, city]);
  36.  
  37. // Add Layer switcher
  38. map.addControl(new OpenLayers.Control.LayerSwitcher());
  39.  
  40. map.setCenter( lonlat, 10 );
  41. }
  42. </script>
  43. var StyleMap = new OpenLayers.Style({
  44. fontColor: "black",
  45. fontSize: "12px",
  46. fontFamily: "Arial, Courier New",
  47. labelAlign: "lt",
  48. labelXOffset: "-15",
  49. labelYOffset: "-17",
  50. labelOutlineColor: "white",
  51. labelOutlineWidth: 3,
  52. externalGraphic: "${icon}",
  53. graphicWidth: 60,
  54. label : "${myCustomLabel}"
  55. },
  56. {
  57. context:
  58. {
  59. icon: function(feature) {
  60. return "http://openweathermap.org"+GetWeatherIcon(feature.attributes.station);
  61. },
  62. myCustomLabel: function(feature) {
  63. return Math.round(feature.attributes.station.main.temp-273.15) + 'c';
  64. }
  65. }
  66. }
  67.  
  68. ));
  69.  
  70. var stations = new OpenLayers.Layer.Vector.OWMWeather("Weather", { styleMap: StyleMap });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement