Basic map with Leaflet.js and OpenStreetMap
Leaflet is an an open-source JavaScript library for mobile-friendly interactive maps http://leafletjs.com/ Here data is provided by OpenStreetMap
by aidankirrane
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-beta.2.rc.2/leaflet.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-beta.2.rc.2/leaflet.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div id="map"></div>
CSS
#map {
height: 400px;
}
JavaScript
// center of the map
var center = [-41.2769, 174.7731];
// Create the map
var map = L.map('map').setView(center, 5);
// Set up the OSM layer
L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18
}).addTo(map);
// add a marker in the given location
L.marker(center).addTo(map);
var myGeoJSONPath = 'https://fwhgj.csb.app/WFSOutPutFromStatsOneBoundary.json';
var myCustomStyle = {
stroke: false,
fill: true,
fillColor: '#FFA500',
fillOpacity: 1
}
$.getJSON(myGeoJSONPath,function(data){
// var map = L.map('map').setView([39.74739, -105], 4);
L.geoJson(data, {
clickable: false,
style: myCustomStyle
}).addTo(map);
})
var geojsonFeature = {
"type": "Feature",
"properties": {
"name": "Coors Field",
"amenity": "Baseball Stadium",
"popupContent": "This is where the Rockies play!"
},
"geometry": {
"type": "Point",
"coordinates": [-104.99404, 39.75621]
}
};
L.geoJSON(geojsonFeature).addTo(map);