Marorin
Marorin

Reputation: 167

Why does this map not show up?

Trying to figure out why this doesn't show up, it is supposed to show a map with layers to show the weather. I used a combination of Openlayers and OWM APII've tried this on Google Chrome and Firefox and yet to no avail:

<body onload="init()">
<div id="map" class="map"></div>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script src="http://openweathermap.org/js/OWM.OpenLayers.1.3.2.js" >         </script>

<script type="text/javascript">
    var map;
    function init() {
//Center  ( mercator coordinates )
var lat = 515566; 
var lon = 4688454;

// 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>
</body>

Upvotes: 1

Views: 167

Answers (1)

Fin Dev
Fin Dev

Reputation: 309

If you change

<div id="map" class="map"></div>

to

<div id="basicMap" class="map"></div>

it will work.

It's because when you create the map initially you set the name to basicMap, and the div id has to match:

map = new OpenLayers.Map("basicMap");

Upvotes: 1

Related Questions