JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script src="//api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"></script>
<div id="myMap"></div>
<div id="display"></div>
CSS
#myMap {
width: 100%;
height: 400px;
}
JavaScript
var map;
$.getJSON('https://maptimeatx.github.io/intro-to-turf/data/historic_landmarks.geojson', function (landmarks) {
$.getJSON('https://maptimeatx.github.io/intro-to-turf/data/austin_districts.geojson', function (districts) {
setupMap();
main(landmarks, districts);
});
});
function main(landmarks, districts) {
console.log("landmarks:", landmarks);
console.log("districts:", districts);
//YOUR MISSION: Use methods from turf to
// have fun with the landmark and district datasets.
//
//You can use the showResult function to display
// some text below the map.
//
//You can use the showOnMap function to display your
// GeoJSON result on the map with popups.
// Example: Combine (merge) the districts into a single feature
var merged = turf.merge(districts);
showOnMap(merged);
}
function showResult(any) {
$('#display').text("Result: " + any.toString());
}
//This function shows the given features as a layer on the map.
//It also adds popups to each of the features.
//You should not need to modify this function -- it's here as a handy helper
function showOnMap(geojsonFeatures) {
if (!geojsonFeatures) { return; }
L.geoJson(geojsonFeatures, {
onEachFeature: function (feature, layer) {
var text = [];
for (prop in feature.properties) {
if (hasOwnProperty.call(feature.properties, prop)) {
text.push("<b>" + prop + "</b>: " + feature.properties[prop]);
}
}
if (text.length) {
layer.bindPopup(text.join('<br>'));
}
}
}).addTo(map);
}
//This function sets up the map. It does not need to be modified.
function setupMap() {
map = L.map('myMap', {
center: [30.26715, -97.74306],
zoom: 11,
layers: [L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution:...