This is a basic example, slightly modified from the OpenLayers website.
- When I use WMS (r2 commented, r3 uncommented) it works.
- When I use OSM (r2 uncommented, r2 commented) it wont work.
I want to use OSM, what am I missing here?
var map = new OpenLayers.Map('map');
//osmLayer = new OpenLayers.Layer.OSM();
osmLayer = new OpenLayers.Layer.WMS("OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'});
map.addLayer(osmLayer);
map.setCenter(new OpenLayers.LonLat(10, 45), 6);
var myGeoJSON = {
"type": "FeatureCollection",
"features": [
{"geometry":{
"type":"GeometryCollection",
"geometries":[
{
"type":"LineString",
"coordinates":
[[11.0878902207, 45.1602390564],
[15.01953125, 48.1298828125]]
}
]
},
"type":"Feature",
"properties": {}}
]
};
var geojson_format = new OpenLayers.Format.GeoJSON();
var vector_layer = new OpenLayers.Layer.Vector();
map.addLayer(vector_layer);
vector_layer.addFeatures(geojson_format.read(myGeoJSON));
This snippet code can be used in a html page with:
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<div style="width: 100%; height: 100%;" id="map"></div>