Weather layer with array of data

You can embed current weather map and weather station map into your application by using array of weather data technology.

Weather layers embedded via array of weather data

Name Area
Current weather for cities worldwide
Weather stations worldwide

OpenLayers library

Library connection

To work with maps you need to connect two libraries:

  • OpenLayers.js - free library for dealing with different cartographic services like Google Maps, OpenStreetMaps etc. More detailed information about library is here
  • OWM.OpenLayers.1.3.4.js - library for dealing with weather data of OpenWeatherMap service.

<script src="">
<script src="/themes/openweathermap/assets/vendor/owm/js/OWM.OpenLayers.1.3.4.js">

Map creation

	// for OSM layer
        var mapnik = new OpenLayers.Layer.OSM();
	// Make weather station layer. Client clastering of markers is using. 
	var stations = new OpenLayers.Layer.Vector.OWMStations("Stations");
	// Make weather layer. Server clastering of markers is using.
	var city = new OpenLayers.Layer.Vector.OWMWeather("Weather");

	// Add weather layers to map
	map.addLayers([mapnik, stations, city]);

Example of layer embedding

This example shows how to connect weather stations layer and current weather in the cities layer. Both layers operate independently and can be used together or separately from each other.

<title>Open Weather Map</title>
    <style type="text/css">
        #map {
            width: 100%;
            height: 99%;
            border: 1px solid black;

<body  onload="init()">
<div id="basicMap"></div>

<script src=""></script>
<script src="" ></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 );

How it works

Style customization

By creating a class of your own style you can redefine a style of information displaying on the map.


More about style

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}"
				icon:  function(feature) {
					return ""+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 });

Pop-up window

When you click on the icon on the map you can get a pop-up menu with information about weather in the city.

selectControl = new OpenLayers.Control.SelectFeature(stations);
How it works

Leaflet library

About Leaflet library

The javascript library is designed to work with the Leaflet mapping service. The current version of the library allows embedding of current weather in cities layer and weather station layer. The library supports customer clustering. You can find example of this library on the

    <meta charset="utf-8" />
    <link rel="stylesheet" href="" />
    <!--[if lte IE 8]><link rel="stylesheet" href="" /><![endif]-->
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>


    <div id="map" style="width: 100%; height: 100%"></div>

      var osmUrl = 'http://{s}{z}/{x}/{y}.png',
          osmAttribution = 'Map data © <a href="">OpenStreetMap</a> contributors, <a href="">CC-BY-SA</a>';
          osmLayer = new L.TileLayer(osmUrl, {maxZoom: 18, attribution: osmAttribution});
      var map = new L.Map('map');
      map.setView(new L.LatLng(55.5, 37.5), 9)
      var validatorsLayer = new OsmJs.Weather.LeafletLayer({lang: 'ru'});


Example of weather layer embedding

var city = 
new OpenLayers.Layer.Vector.OWMWeather("Weather");