<!doctype html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="https://tiles.locationiq.com/v3/libs/openlayers/8.2.0/ol.css" type="text/css">
        <script src="https://tiles.locationiq.com/v3/libs/openlayers/8.2.0/ol.js"></script>
        <style>
            body { margin:0px; padding:0px; }
            #map { position:absolute; top:0px; bottom:0px; width:100%; }
        </style>
        <script src="https://tiles.locationiq.com/v3/libs/olms/12.0.0/olms.js" type="text/javascript"></script>
        <title>Show Polygons</title>
    </head>
    <body>
        <div id="map"></div>
        <script type="text/javascript">
            var key = 'pk.aa7f5d0539c5675b7f3429402939d8fa';   //Insert your LocationIQ access token here

            var styleJson = 'https://tiles-staging.locationiq.com/v3/streets/vector.json?key=' + key;

            const map = new ol.Map({
                target: 'map',
                view: new ol.View({
                    center: ol.proj.fromLonLat([-122.42, 37.779]),
                    zoom: 12
                })
            });

                
            var polygon = new ol.geom.Polygon([[
                                        [-122.4775065, 37.7882933],
                                        [-122.4752749, 37.7500271],
                                        [-122.4442042, 37.7357740],
                                        [-122.4055804, 37.7363170],
                                        [-122.3932208, 37.7570848],
                                        [-122.3909033, 37.7881577],
                                        [-122.4775065, 37.7882933]
                                    ]]); 
            //To transform the coordinate system 
            polygon.transform('EPSG:4326', 'EPSG:3857');      

            //Converting the polygon to feature
            var polygonFeature = new ol.Feature(polygon);
        
            //configuring the style of the polygon
            var polygonStyle = new ol.style.Style({
                fill: new ol.style.Fill({
                    color: 'rgba(210, 12, 12, 0.5)',
                    weight: 0.1
                })
            });

            //adding the styles to the features
            polygonFeature.setStyle(polygonStyle);

            //Let’s include the markers and create a vector source with it
            var vectorSource = new ol.source.Vector({
                features: [polygonFeature]
            });

            //Let’s create a vector layer, with a source created above
            var vectorLayer = new ol.layer.Vector({
                source: vectorSource,
                zIndex: 1
            });

            map.addLayer(vectorLayer);
            olms.apply(map, styleJson);
        </script>
    </body>
</html>