JSFiddle - React, Tailwind, and code Playground
by nathansnider
HTML
<script src="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.css">
<script src="https://rawgit.com/perliedman/leaflet-routing-machine/master/dist/leaflet-routing-machine.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/perliedman/leaflet-routing-machine/master/dist/leaflet-routing-machine.css">
<script src="https://rawgit.com/perliedman/leaflet-routing-machine/master/examples/Control.Geocoder.js"></script>
<div id="map"></div>
CSS
html,
body,
#map {
height: 100%;
width: 100%;
padding: 0px;
margin: 0px;
background: white;
}
.leaflet-routing-container {
display: none;
}
JavaScript
/////////////////////////////////////////////////////////////////////////////////////////////
//setting up the map//
/////////////////////////////////////////////////////////////////////////////////////////////
// initialize map
var map = L.map('map').setView([0, 0], 0);
ATTR = '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> | ' +
'© <a href="http://cartodb.com/attributions">CartoDB</a>';
CDB_URL = 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png';
L.tileLayer(CDB_URL, {
attribution: ATTR
}).addTo(map);
/////////////////////////////////////////////////////////////////////////////////////////////
//adding data//
/////////////////////////////////////////////////////////////////////////////////////////////
var geojson = [{
"type": "Polygon",
"coordinates": [
[
[-102.774299999583, 27.280200001318],
[-88.0033999995794, 28.9369000000879],
[-87.7235000003129, 15.2657999992371],
[-95.6770999999717, 14.6623000004329],
[-103.630699999514, 14.0588000016287],
[-102.774299999583, 27.280200001318]
]
]
}, {
"type": "Polygon",
"coordinates": [
[
[-102.774299999583, 27.280200001318],
[-88.0033999995794, 28.9369000000879],
[-87.7235000003129, 15.2657999992371],
[-95.6770999999717, 14.6623000004329],
[-103.630699999514, 14.0588000016287],
[-102.774299999583, 27.280200001318]
]
]
}];
var jsonLayer = L.geoJson().addTo(map);
jsonLayer.addData(geojson);
map.fitBounds(jsonLayer.getBounds());