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

              
                <div id="panel">
	<h2>GeoJSON Viewer</h2>
	<p>
		To use this application, drag and drop a <code>.geojson</code> file into the page. I'll 
		read it and display it on the map. You can
		click a feature to see the properties.
	</p>
	<p id="status"></p>
</div>
<div id="map"></div>

              
            
!

CSS

              
                body {
	margin: 0px;
}

#panel {
	position: absolute;
	top: 10px;
	left: 10px;
	width: 250px;
	height: 230px;
	z-index: 9999;
	background-color: bisque;
	padding: 8px;
	opacity: 0.8;
}

#map {
	height: 100vh;
	width: 100%;
}
              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', init, false);

let map;
let $status;

function updateStatus(s) {
	if(!$status) $status = document.querySelector('#status');
	$status.innerHTML = s;
}

function handleDrop(e) {
		e.preventDefault();
		let droppedFiles = e.dataTransfer.files;
		if(!droppedFiles) return;
		let myFile = droppedFiles[0];
		let ext = myFile.name.split('.').pop();
		if(ext !== 'geojson') {
			alert('Drag/drop a .geojson file only.');
			return;
		}
		
		let reader = new FileReader();
		reader.onload = e => {
			loadGeoJSON(JSON.parse(e.target.result));
		};
		
		updateStatus('Reading .geojson');
		reader.readAsText(myFile);	
}

async function loadGeoJSON(data) {
	updateStatus(`.geojson loaded with ${data.features.length} features. Adding to map now.`);

	L.geoJSON(data, {
	}).bindPopup(function (layer) {
			return `
			<p>
			<b>Properties:</b><br>
			<pre style='white-space:pre-wrap'><code>
${JSON.stringify(layer.feature.properties,null,'  ')}
			</code></pre>
			</p>
			`;
	},{minWidth:450}).addTo(map);


}

async function init() {

	document.addEventListener('dragover', e => e.preventDefault());
	document.addEventListener('drop', handleDrop);
	// https://stackoverflow.com/questions/33614912/how-to-locate-leaflet-zoom-control-in-a-desired-position
	map = L.map('map', { zoomControl:false}).setView([37.09024, -95.712891], 3);
	
	L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 16,
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
	}).addTo(map);
	
	L.control.zoom({
			position: 'bottomright'
	}).addTo(map);
};




              
            
!
999px

Console