turf.geometryCollection

Creates a Feature based on a coordinate array. Properties can be added optionally.

<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="https://rawcdn.githack.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
    <link rel="stylesheet" href="assets/css/styles.css" type="text/css">
    <script src="//cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>
    <script src="https://rawcdn.githack.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js" type="text/javascript"></script>
    <title>Turf and OpenLayers 3 - Helper geometryCollection</title>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script type="text/javascript">

      var geometryCollection = turf.geometryCollection([{"type":"MultiPolygon","coordinates":[[[[68.982921,-48.798517],[69.214529,-49.12127],[70.139903,-49.3388],[70.12322,-49.713556],[69.114513,-49.603123],[68.755544,-49.047621],[68.982921,-48.798517]]],[[[-62.838857,17.881984999999986],[-62.857411,17.92503500000001],[-62.79165600000001,17.915472999999977],[-62.838857,17.881984999999986]]],[[[-109.21202600000001,10.302679999999995],[-109.218577,10.281561999999994],[-109.234242,10.307929000000001],[-109.21202600000001,10.302679999999995]]],[[[55.50131300000001,-20.873224000000008],[55.85450300000001,-21.156995999999992],[55.820811000000006,-21.324964999999978],[55.354502999999994,-21.274591],[55.225434,-21.048271999999997],[55.50131300000001,-20.873224000000008]]],[[[-51.683217,4.039373999999995],[-51.988424,3.704554999999999],[-52.707708,2.3589269999999942],[-52.959683,2.1752170000000035],[-53.344103999999994,2.349625000000003],[-53.866811,2.3049250000000114],[-54.134907999999996,2.11067300000002],[-54.615292,2.3262670000000014],[-54.212526,2.776420999999999],[-54.190459999999995,3.1781019999999955],[-53.988819,3.6109950000000026],[-54.355153,4.0665229999999895],[-54.482122,4.912801999999999],[-54.170965,5.348376000000002],[-53.94434999999999,5.744641000000001],[-52.994581,5.457623999999996],[-51.931264,4.590399000000005],[-51.801503,4.612697999999995],[-51.683217,4.039373999999995]]],[[[9.449392000000001,42.682603],[9.552745,42.113023],[9.210704,41.44086300000001],[8.695567,41.729438000000016],[8.805431,41.90692799999999],[8.565766,42.17450600000001],[8.667491,42.50971100000001],[9.107107,42.725898],[9.449392000000001,42.682603]]],[[[5.790685,49.53775300000004],[6.345307,49.45534900000001],[6.843489,49.21105399999999],[8.18873,48.965746000000024],[7.810251999999999,48.615017999999964],[7.572642999999999,48.094971999999984],[7.586028,47.584619],[7.044303,47.34049700000003],[6.064157,46.47111799999999],[6.762667,46.42925999999997],[7.022082999999999,45.92526000000001],[6.800804000000001,45.82645500000004],[7.062183,45.21853299999998],[6.602728000000001,45.10345000000001],[7.018982,44.73887200000004],[6.838838,44.502917999999994],[7.033451,44.24293399999999],[7.691911999999999,44.08464900000001],[7.502289,43.79222200000001],[7.437454,43.74336099999999],[7.406969,43.763506000000035],[7.365749999999999,43.72273000000001],[6.731145999999999,43.407847000000004],[6.679801000000001,43.20155299999999],[6.027008000000001,43.078194999999994],[5.338883,43.33428900000001],[4.566289,43.371094],[3.939301,43.53253800000002],[3.3854270000000004,43.28392199999999],[3.0389920000000004,42.94277600000001],[3.18097,42.43148400000001],[2.051688,42.352351],[1.7070060000000002,42.50278100000003],[1.429297,42.59538599999999],[0.656321,42.838419999999985],[0.608159,42.68799000000001],[-0.038933,42.685148],[-0.307418,42.831830999999994],[-1.274879,43.046831],[-1.7940750000000003,43.386014999999986],[-1.476877,43.58006399999999],[-1.247304,44.50454300000001],[-1.048695,46.03880399999997],[-1.179596,46.229478],[-1.804799,46.50360699999999],[-2.118764,46.819973000000005],[-1.9925839999999997,47.052313999999996],[-2.404897,47.28644400000002],[-2.501698,47.52667899999997],[-3.073842,47.576482999999996],[-3.345123,47.721259],[-4.434641,47.975652999999994],[-4.457631,48.24896899999999],[-4.783354999999999,48.37640999999999],[-4.563629,48.629624999999976],[-3.515289,48.84194600000001],[-3.077056,48.82827399999999],[-2.636342,48.538804],[-2.312489,48.68695700000001],[-1.5797009999999998,48.64325600000001],[-1.610422,49.21588800000001],[-1.8846740000000002,49.530911],[-1.391265,49.712714000000005],[-1.072255,49.396795999999995],[-0.21947200000000003,49.28009700000001],[0.256847,49.46405699999997],[0.23584999999999998,49.729314999999986],[1.172618,49.961005],[1.521007,50.21466699999999],[1.580577,50.86880099999999],[2.5218,51.08754099999999],[2.786734,50.723365],[4.022731,50.33811700000001],[4.435109,49.93225000000001],[4.788265,49.97426300000001],[5.4020779999999995,49.602451],[5.790685,49.53775300000004]]],[[[-63.017568999999995,18.033390999999995],[-63.107003999999996,18.062108999999992],[-63.01764899999999,18.122138000000007],[-63.017568999999995,18.033390999999995]]],[[[164.01352,-20.083102999999994],[164.495616,-20.300225999999995],[165.406749,-21.05543399999999],[166.938813,-22.079848],[166.91163199999997,-22.385024],[166.47836299999997,-22.287205],[165.677745,-21.76140699999999],[165.290782,-21.57675499999999],[164.800792,-21.08220800000001],[164.365571,-20.758071],[164.01352,-20.083102999999994]]],[[[-149.303944,-17.712091],[-149.587514,-17.731215000000006],[-149.604319,-17.525811000000004],[-149.354115,-17.54013399999998],[-149.303944,-17.712091]]],[[[-56.27379299999999,46.99909099999999],[-56.311757,46.90013299999998],[-56.249257,46.84227099999998],[-56.346262,46.78359599999999],[-56.336780999999995,46.95424999999997],[-56.395904,47.11359300000001],[-56.253326,47.05369699999997],[-56.27379299999999,46.99909099999999]]],[[[-178.04674200000002,-14.312594999999988],[-178.146921,-14.310153999999997],[-178.14232299999998,-14.243584999999996],[-178.04674200000002,-14.312594999999988]]]]}, {"type":"Point","coordinates":[69.179513,34.529205]},{"type":"Point","coordinates":[28.225991,-25.771914]},{"type":"Point","coordinates":[19.808009,41.330181]},{"type":"Point","coordinates":[3.034576,36.751711]},{"type":"Point","coordinates":[13.37914,52.517299]},{"type":"Point","coordinates":[21.425312,41.979535]},{"type":"Point","coordinates":[1.525174,42.509102]},{"type":"Point","coordinates":[13.236358,-8.816313]},{"type":"Point","coordinates":[-60.998036,14.020162]},{"type":"Point","coordinates":[46.628273,24.684613]},{"type":"Point","coordinates":[-58.382549,-34.591831]},{"type":"Point","coordinates":[44.506624,40.174078]},{"type":"Point","coordinates":[149.117607,-35.304603]},{"type":"Point","coordinates":[16.374493,48.198711]},{"type":"Point","coordinates":[49.840314,40.370465]},{"type":"Point","coordinates":[50.595281,26.238752]},{"type":"Point","coordinates":[90.419079,23.789267]},{"type":"Point","coordinates":[-61.519167,10.665851]},{"type":"Point","coordinates":[4.368089,50.846807]},{"type":"Point","coordinates":[2.413607,6.352733]},{"type":"Point","coordinates":[27.55465,53.903513]},{"type":"Point","coordinates":[96.14248,16.790223]},{"type":"Point","coordinates":[-68.108597,-16.526352]},{"type":"Point","coordinates":[18.415719,43.860703]},{"type":"Point","coordinates":[25.917454,-24.659741]},{"type":"Point","coordinates":[-47.873939,-15.805592]},{"type":"Point","coordinates":[114.942783,4.887675]},{"type":"Point","coordinates":[23.340979,42.69493]},{"type":"Point","coordinates":[-1.510924,12.371967]},{"type":"Point","coordinates":[29.369953,-3.381042]},{"type":"Point","coordinates":[-23.51194,14.90722]},{"type":"Point","coordinates":[104.916065,11.583486]},{"type":"Point","coordinates":[11.512263,3.850181]},{"type":"Point","coordinates":[-75.694736,45.443325]},{"type":"Point","coordinates":[-70.628689,-33.435926]},{"type":"Point","coordinates":[116.468384,39.951625]},{"type":"Point","coordinates":[33.352842,35.158966]},{"type":"Point","coordinates":[-74.047354,4.67429]},{"type":"Point","coordinates":[43.246779,-11.710107]},{"type":"Point","coordinates":[15.282261,-4.275031]},{"type":"Point","coordinates":[126.965608,37.561206]},{"type":"Point","coordinates":[-84.04004,9.923164]},{"type":"Point","coordinates":[-4.017429,5.326404]},{"type":"Point","coordinates":[15.977482,45.809429]},{"type":"Point","coordinates":[-82.419931,23.124628]},{"type":"Point","coordinates":[12.587178,55.681068]},{"type":"Point","coordinates":[43.151249,11.607725]},{"type":"Point","coordinates":[31.21668,30.023457]},{"type":"Point","coordinates":[54.36769,24.456106]},{"type":"Point","coordinates":[-78.494719,-0.209016]},{"type":"Point","coordinates":[38.93596,15.338132]},{"type":"Point","coordinates":[-3.68999,40.420631]},{"type":"Point","coordinates":[24.735801,59.428287]},{"type":"Point","coordinates":[-77.078367,38.912629]},{"type":"Point","coordinates":[38.770854,9.054062]},{"type":"Point","coordinates":[24.960475,60.156809]},{"type":"Point","coordinates":[9.446805,0.383242]},{"type":"Point","coordinates":[-17.448353,14.687542]},{"type":"Point","coordinates":[44.81167,41.670528]},{"type":"Point","coordinates":[-0.189162,5.576713]},{"type":"Point","coordinates":[23.737972,37.976308]},{"type":"Point","coordinates":[-90.515544,14.584653]},{"type":"Point","coordinates":[-13.715267,9.511741]},{"type":"Point","coordinates":[8.771289,3.753237]},{"type":"Point","coordinates":[-15.625952,11.863508]},{"type":"Point","coordinates":[-55.153289,5.827636]},{"type":"Point","coordinates":[-72.334833,18.539136]},{"type":"Point","coordinates":[-87.19134,14.101718]},{"type":"Point","coordinates":[19.075704,47.514744]},{"type":"Point","coordinates":[174.7754,-41.290198]},{"type":"Point","coordinates":[178.42481,-18.138154]},{"type":"Point","coordinates":[147.150761,-9.477577]},{"type":"Point","coordinates":[77.188546,28.595436]},{"type":"Point","coordinates":[106.822684,-6.196992]},{"type":"Point","coordinates":[44.420865,33.308747]},{"type":"Point","coordinates":[51.410793,35.697194]},{"type":"Point","coordinates":[-6.221277,53.320348]},{"type":"Point","coordinates":[-21.946898,64.14803]},{"type":"Point","coordinates":[34.767796,32.081229]},{"type":"Point","coordinates":[12.470864,41.895072]},{"type":"Point","coordinates":[-76.777847,18.018446]},{"type":"Point","coordinates":[139.72654,35.648223]},{"type":"Point","coordinates":[35.904102,31.95376]},{"type":"Point","coordinates":[71.424446,51.147247]},{"type":"Point","coordinates":[36.817868,-1.284697]},{"type":"Point","coordinates":[74.602966,42.867295]},{"type":"Point","coordinates":[21.154377,42.669215]},{"type":"Point","coordinates":[47.992553,29.36032]},{"type":"Point","coordinates":[102.613028,17.961506]},{"type":"Point","coordinates":[28.226273,-25.77239]},{"type":"Point","coordinates":[24.113193,56.95225]},{"type":"Point","coordinates":[35.508167,33.878005]},{"type":"Point","coordinates":[-10.783473,6.292451]},{"type":"Point","coordinates":[13.192949,32.882308]},{"type":"Point","coordinates":[25.287322,54.680907]},{"type":"Point","coordinates":[6.120932,49.60905]},{"type":"Point","coordinates":[47.52273,-18.907378]},{"type":"Point","coordinates":[101.72239,3.16052]},{"type":"Point","coordinates":[28.304499,-15.420085]},{"type":"Point","coordinates":[-7.994936,12.63592]},{"type":"Point","coordinates":[14.510064,35.898211]},{"type":"Point","coordinates":[-6.847293,34.007197]},{"type":"Point","coordinates":[57.501039,-20.16644]},{"type":"Point","coordinates":[-15.983954,18.095342]},{"type":"Point","coordinates":[-99.19958,19.428179]},{"type":"Point","coordinates":[28.826773,47.016487]},{"type":"Point","coordinates":[7.433903,43.749075]},{"type":"Point","coordinates":[106.91371,47.91696]},{"type":"Point","coordinates":[19.274708,42.444579]},{"type":"Point","coordinates":[32.601843,-25.960423]},{"type":"Point","coordinates":[17.084608,-22.555114]},{"type":"Point","coordinates":[85.319449,27.720052]},{"type":"Point","coordinates":[-86.286026,12.146971]},{"type":"Point","coordinates":[2.078116,13.524683]},{"type":"Point","coordinates":[7.506827,9.079955]},{"type":"Point","coordinates":[10.705677,59.913235]},{"type":"Point","coordinates":[174.7754,-41.290198]},{"type":"Point","coordinates":[58.426874,23.603947]},{"type":"Point","coordinates":[32.576678,0.320061]},{"type":"Point","coordinates":[69.286467,41.305005]},{"type":"Point","coordinates":[73.106135,33.716737]},{"type":"Point","coordinates":[-79.532374,8.950267]},{"type":"Point","coordinates":[147.150761,-9.477577]},{"type":"Point","coordinates":[-57.615861,-25.286271]},{"type":"Point","coordinates":[4.316183,52.083]},{"type":"Point","coordinates":[-77.031831,-12.09981]},{"type":"Point","coordinates":[121.027235,14.560871]},{"type":"Point","coordinates":[21.027279,52.223704]},{"type":"Point","coordinates":[-9.156602,38.707288]},{"type":"Point","coordinates":[51.536628,25.329931]},{"type":"Point","coordinates":[18.590508,4.363025]},{"type":"Point","coordinates":[15.273254,-4.320709]},{"type":"Point","coordinates":[121.027235,14.560871]},{"type":"Point","coordinates":[-69.882969,18.474394]},{"type":"Point","coordinates":[14.40631,50.085925]},{"type":"Point","coordinates":[26.094611,44.445036]},{"type":"Point","coordinates":[-0.158288,51.502415]},{"type":"Point","coordinates":[37.613823,55.732073]},{"type":"Point","coordinates":[30.066742,-1.948609]},{"type":"Point","coordinates":[-60.998036,14.020162]},{"type":"Point","coordinates":[-89.23021,13.703093]},{"type":"Point","coordinates":[174.7754,-41.290198]},{"type":"Point","coordinates":[-17.427627,14.668372]},{"type":"Point","coordinates":[20.452647,44.819023]},{"type":"Point","coordinates":[55.456416,-4.630078]},{"type":"Point","coordinates":[-13.270913,8.47167]},{"type":"Point","coordinates":[103.814122,1.322199]},{"type":"Point","coordinates":[17.108711,48.143736]},{"type":"Point","coordinates":[14.501256,46.046028]},{"type":"Point","coordinates":[36.817868,-1.284697]},{"type":"Point","coordinates":[32.546803,15.580735]},{"type":"Point","coordinates":[31.586552,4.854634]},{"type":"Point","coordinates":[79.872403,6.914562]},{"type":"Point","coordinates":[18.079235,59.338856]},{"type":"Point","coordinates":[7.466492,46.947005]},{"type":"Point","coordinates":[-55.153289,5.827636]},{"type":"Point","coordinates":[36.285677,33.525395]},{"type":"Point","coordinates":[68.78088,38.614624]},{"type":"Point","coordinates":[39.278606,-6.789127]},{"type":"Point","coordinates":[15.030836,12.116254]},{"type":"Point","coordinates":[100.497919,13.697892]},{"type":"Point","coordinates":[106.822684,-6.196992]},{"type":"Point","coordinates":[1.220886,6.121908]},{"type":"Point","coordinates":[178.42481,-18.138154]},{"type":"Point","coordinates":[-61.519167,10.665851]},{"type":"Point","coordinates":[10.179153,36.798942]},{"type":"Point","coordinates":[58.361137,37.953496]},{"type":"Point","coordinates":[32.856791,39.902572]},{"type":"Point","coordinates":[30.507938,50.453954]},{"type":"Point","coordinates":[-56.198194,-34.903405]},{"type":"Point","coordinates":[168.313582,-17.737119]},{"type":"Point","coordinates":[-66.859753,10.483375]},{"type":"Point","coordinates":[105.850586,21.020992]},{"type":"Point","coordinates":[44.200899,15.335625]},{"type":"Point","coordinates":[28.304595,-15.420095]},{"type":"Point","coordinates":[31.048617,-17.826134]}], {name: 'France, including part with sovereignty and embassies'});

      // Declare a formatter to read GeoJSON
      var format = new ol.format.GeoJSON();

      // Declare a source
      var vectorSource = new ol.source.Vector();

      // When reading feature, reproject to EPSG 3857
      var feature = format.readFeature(geometryCollection, {
        featureProjection: 'EPSG:3857'
      });
      // Add a feature
      vectorSource.addFeature(feature);

      // Declare a vector layer with the already
      // created source containing added features
      var vectorLayer = new ol.layer.Vector({
        source: vectorSource
      });

      // Instanciate a map and add layers
      var map = new ol.Map({
        target: 'map',
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          }),
          vectorLayer
        ],
        view: new ol.View({
          center: ol.proj.fromLonLat([0, 0]),
          zoom: 1
        })
      });
    </script>
  </body>
</html>

results matching ""

    No results matching ""