JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.js"></script>
<link rel="stylesheet" href="https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.css">
<div id="mapid" style="height:100%;width:100%;position:fixed;"></div>
JavaScript
var mapLayer = L.map('mapid', {
zoomAnimation: false
});
var pid = 'karan44.pdmio34k';
var at = 'pk.eyJ1Ijoia2FyYW40NCIsImEiOiJjaWx0Y3A3MmkwMDhjdmdrc20xazM4M25vIn0.hUFDaS5EPmoJwiZi1Wz5AQ';
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
id: pid,
accessToken: at
}).addTo(mapLayer);
var polygon1 = turf.polygon([
[
[152.67056386250164, -27.668546103065918],
[152.670570753125, -27.668448187499962],
[152.66339354224846, -27.667412690538576],
[152.66337495312501, -27.66751430937495],
[152.67056386250164, -27.668546103065918]
]
], {
"fill": "#00000F",
"stroke": "#00000F",
"stroke-width": 1
});
var polygon2 = turf.polygon([
[
[152.66367674399675, -27.66755762413956],
[152.66365917740868, -27.667555102881636],
[152.6636517030028, -27.667552420346716],
[152.66364398942125, -27.66755027023464],
[152.66363610793672, -27.66754867419075],
[152.66362810866983, -27.667547642366124],
[152.66362004249186, -27.667547181321932],
[152.6636119606991, -27.6675472939904],
[152.66360744876388, -27.66754767848851],
[152.66355747931533, -27.667540506585365],
[152.66356888999357, -27.66748699925803],
[152.66357902968906, -27.667439451864727],
[152.66369754244585, -27.667456550373],
[152.66367674399675, -27.66755762413956]
]
], {
"fill": "#0000FF",
"stroke": "#0000FF",
"stroke-width": 1
});
var polygon = turf.intersect(polygon1, polygon2);
polygon.properties = {
"fill": "#FF0000",
"stroke": "#FF0000",
"stroke-width": 1
};
L.mapbox.featureLayer().setGeoJSON(polygon1).addTo(mapLayer);
L.mapbox.featureLayer().setGeoJSON(polygon2).addTo(mapLayer);
L.mapbox.featureLayer().setGeoJSON(polygon).addTo(mapLayer);
mapLayer.setView([-27.66755762413956, 152.66365917740868], 16);