Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
	<head>
		<title>Ultimate Guide to Openlayers: Free Maps for the Web</title>
		<style>
		#map {
			height: 500px;
			width: 500px;
		}
		</style>
		<script src="//maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
		<script src="https://openlayers.org/dev/OpenLayers.js"></script>
	</head>
	<body>
		<div id="map"></div>
		<div id="verticesStr"></div>
		<script>
			//Convert the coordinates into GPS format
			var cent_lonlat = new OpenLayers.LonLat(77.2300, 28.6100)
				.transform(new OpenLayers.Projection('EPSG:4326'), new OpenLayers.Projection('EPSG:3857'));

			//The layers
			var osm_layer = new OpenLayers.Layer.OSM();

			//Google Hybrid
			var ghyb = new OpenLayers.Layer.Google(
				"Google Hybrid", {
					type: google.maps.MapTypeId.HYBRID
				}
			);

			var map = new OpenLayers.Map({
				div: "map",
				displayProjection: new OpenLayers.Projection("EPSG:4326", "EPSG:3857"),
				center: cent_lonlat,
				zoom: 3,
				layers: [osm_layer, ghyb]
			});

			//Add the Layer switcher control
			//to switch between layers
			map.addControl(new OpenLayers.Control.LayerSwitcher());
			
			//Add the vector layer
			var polygonLayer = new OpenLayers.Layer.Vector("My Polygon");
			//Add the layer to map
			map.addLayer(polygonLayer);

			//Drawing controls
			drawControls = {
                polygon: new OpenLayers.Control.DrawFeature(polygonLayer, OpenLayers.Handler.Polygon)
            };
			//Add the drawing control to polygon
			map.addControl(drawControls.polygon);
			
			//Activate the drawing control
			drawControls.polygon.activate();

			//You can add the select control to the polygons
			//This is not a necessary step
			var options = {
				hover: false
			};
			var select = new OpenLayers.Control.SelectFeature(polygonLayer, options);
			select.onSelect = function(e) {
				var mapProjv = map.getProjectionObject();
				var epsg4326v = new OpenLayers.Projection("EPSG:4326");
				var verticesNative = e.geometry.getVertices();
				var verticesLatLon = [];
				var verticesStr = "";
				for (var x in verticesNative) {
				   verticesLatLon.push(verticesNative[x].clone().transform(mapProjv, epsg4326v));
				   verticesStr +=  verticesLatLon[x].toShortString() + ";";
				}
				document.getElementById("verticesStr").innerHTML = "Area Vertices: " + verticesStr;
			}
			//Add the select control to the map
			map.addControl(select);
			//Activate the select control
			select.activate();
		</script>
	</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console