Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <body onload="init()">
- <div id="basicMap"></div>
- </body>
- <script src="http://openlayers.org/api/OpenLayers.js"></script>
- <script src="http://openweathermap.org/js/OWM.OpenLayers.1.3.4.js" ></script>
- <script type="text/javascript">
- var map;
- function init() {
- //Center ( mercator coordinates )
- var lat = 7486473;
- var lon = 4193332;
- // if you use WGS 1984 coordinate you should convert to mercator
- // lonlat.transform(
- // new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
- // new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
- // );
- var lonlat = new OpenLayers.LonLat(lon, lat);
- map = new OpenLayers.Map("basicMap");
- // Create overlays
- // map layer OSM
- var mapnik = new OpenLayers.Layer.OSM();
- // Create station layer
- var stations = new OpenLayers.Layer.Vector.OWMStations("Stations");
- // Create weather layer
- var city = new OpenLayers.Layer.Vector.OWMWeather("Weather");
- //connect layers to map
- map.addLayers([mapnik, stations, city]);
- // Add Layer switcher
- map.addControl(new OpenLayers.Control.LayerSwitcher());
- map.setCenter( lonlat, 10 );
- }
- </script>
- var StyleMap = new OpenLayers.Style({
- fontColor: "black",
- fontSize: "12px",
- fontFamily: "Arial, Courier New",
- labelAlign: "lt",
- labelXOffset: "-15",
- labelYOffset: "-17",
- labelOutlineColor: "white",
- labelOutlineWidth: 3,
- externalGraphic: "${icon}",
- graphicWidth: 60,
- label : "${myCustomLabel}"
- },
- {
- context:
- {
- icon: function(feature) {
- return "http://openweathermap.org"+GetWeatherIcon(feature.attributes.station);
- },
- myCustomLabel: function(feature) {
- return Math.round(feature.attributes.station.main.temp-273.15) + 'c';
- }
- }
- }
- ));
- var stations = new OpenLayers.Layer.Vector.OWMWeather("Weather", { styleMap: StyleMap });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement