Intersect
Use intersect function between polygons and dissolve
by Stefano
HTML
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Intersect</title>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.1/mapbox-gl.css' rel='stylesheet' />
<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>
</head>
<body>
<div id='map' style='width: 100%; height: 500px;'></div>
</body>
</html>
JavaScript
var map = new mapboxgl.Map({
container: 'map',
accessToken: 'pk.eyJ1IjoibWF4cGVudGEiLCJhIjoiY2szNzJ5M3RtMDdsZzNtbzluMzRqczB2cyJ9.oBCPa5oV2driLsx-tEiugg',
style: 'mapbox://styles/maxpenta/ck3733qvp0tn81cmxe0m4whkf',
center: [14.36149,40.835692],
zoom: 14,
});
map.on('load', function() {
var line = {
"id": 8,
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
14.3589111,
40.8391469
],
[
14.3586336,
40.8392848
],
[
14.360673,
40.837083
],
[
14.3639037,
40.8354795
],
[
14.3653988,
40.8332378
],
[
14.3669238,
40.8312481
],
[
14.3682214,
40.8296107
],
[
14.3705268,
40.8273662
],
[
14.3726347,
40.8253014
],
[
14.3740272,
40.82394
],
[
14.3767689,
40.8212471
],
[
14.3767643,
40.8215147
]
]
},
"properties": {}
};
var polygon = {
"id": 3130,
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
14.3613346,
40.8358225
],
[
14.361336,
40.8358242
],
[
14.3614867,
40.8358077
],
[
14.3614763,
...