On Github Delawen / codeCombat-LeafletOpenLayers
<div id="mapRasterLayer" class="map" style="height: 300px"> </div>
function initmap() { // set up the map map = new L.Map('mapRasterLayer'); // create the tile layer with correct attribution var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; var osmAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'; var osm = new L.TileLayer(osmUrl, {attribution: osmAttrib}); map.setView(new L.LatLng(41.9793006, 2.8199439), 14); map.addLayer(osm); }
<div id="mapVectorLayer" class="map" style="height: 300px"> </div>
function initmap() { // set up the map map = new L.Map('mapVectorLayer'); // create the tile layer with correct attribution var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; var osmAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'; var osm = new L.TileLayer(osmUrl, {attribution: osmAttrib}); map.setView(new L.LatLng(41.9793006, 2.8199439), 14); map.addLayer(osm); // Add vector features var circle = L.circle([41.9793006, 2.8199439], 500, { color: 'red', fillColor: '#f03', fillOpacity: 0.5 }).addTo(map); }
<div id="map" style="width:100%;height:330px" class="smallmap"></div>
function init() { var map = new OpenLayers.Map({ div: "map" }); var osm = new OpenLayers.Layer.OSM(); map.addLayers([osm]); map.setCenter( new OpenLayers.LonLat(2.8199439, 41.9793006) .transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()), 12); }
<div id="map" style="width:100%;height:330px" class="smallmap"></div>
function init() { var map = new OpenLayers.Map("map"); var feature = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point( 313914.7189699, 5157879.2777324 ), {type: 40}); var layer = new OpenLayers.Layer.Vector('Points', { styleMap: new OpenLayers.StyleMap({ pointRadius: "${type}", // based on feature.attributes.type fillColor: "#FF6666",fillOpacity: 0.3 })}); layer.addFeatures([feature]); map.addLayer(layer); }
<div id="mapControls" class="map" style="height: 300px"> </div>
function initmap() { // Creamos el mapa, el zoom (+/-) viene por defecto map = new L.Map('mapControls'); // Modificamos el centro del mapa map.setView(new L.LatLng(41.9793006, 2.8199439), 14); // Create the tile layer url var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; // el control de atribución viene por defecto, // pero lo podemos personalizar de la siguiente forma var attrib = 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors. Imagery © 2011 CloudMade'; // Creamos la capa con el mapa de OSM var osm = new L.TileLayer(osmUrl, {attribution: attrib}); // Añadimos la capa al mapa map.addLayer(osm); // Creamos una capa con un círculo al que se le puede hacer clic var circle = L.circle([41.9793006, 2.8199439], 500, { color: 'red', fillColor: '#f03', fillOpacity: 0.5 }).bindPopup("Clic").addTo(map); var cmUrl = 'http://{s}.tile.cloudmade.com/36c9ef9aa99742b48650db1124bf483f/{styleId}@2x/256/{z}/{x}/{y}.png'; var midnight = L.tileLayer(cmUrl, {styleId: 999, attribution: attrib}).addTo(map); var baseLayers = { "OpenStreetMap": osm, "Night View": midnight }; var overlays = { "Circle": circle }; // Añadimos el intercambiador de capas L.control.layers(baseLayers, overlays).addTo(map); // Añadimos la escala L.control.scale().addTo(map); }
<div id="map" style="width:100%;height:330px" class="smallmap"></div>
function init() { //zoom y selector de capas vienen por defecto // atribution viene por defecto para OSM, pero vamos a añadirlos explícitamente para otra capa var map = new OpenLayers.Map("map"); var options = {attribution: { title: "Provided by OSGeo", href: "http://www.osgeo.org/" }}; map.addLayer(new OpenLayers.Layer.WMS("OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers:'basic'}, options)); map.setCenter([2.8199439, 41.9793006], 12); var vectors = new OpenLayers.Layer.Vector("vector", { styleMap: new OpenLayers.StyleMap({ pointRadius: "${type}", // based on feature.attributes.type fillColor: "#FF6666", fillOpacity: 0.3})} ); map.addLayer(vectors); var feature = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point(2.8199439, 41.9793006), {type:40}); vectors.addFeatures([feature]); var highlightCtrl = new OpenLayers.Control.SelectFeature(vectors, { hover: true, highlightOnly: false, eventListeners: {featurehighlighted: report} }); var selectCtrl = new OpenLayers.Control.SelectFeature(vectors,{clickout: true}); map.addControl(highlightCtrl); map.addControl(selectCtrl); highlightCtrl.activate(); selectCtrl.activate(); map.addControls([new OpenLayers.Control.ScaleLine()]); }