import GeoJSON from '../src/ol/format/GeoJSON.js';
import Layer from '../src/ol/layer/Layer.js';
import Map from '../src/ol/Map.js';
import Source from '../src/ol/source/Source.js';
import VectorLayer from '../src/ol/layer/Vector.js';
import VectorSource from '../src/ol/source/Vector.js';
import View from '../src/ol/View.js';
import {Stroke, Style} from '../src/ol/style.js';
import {fromLonLat, toLonLat} from '../src/ol/proj.js';

const center = [-98.8, 37.9];
const key = 'get_your_own_D6rA4zTHduk6KOKTXzGB';

const mbMap = new mapboxgl.Map({
  style: 'https://api.maptiler.com/maps/bright/style.json?key=' + key,
  attributionControl: false,
  boxZoom: false,
  center: center,
  container: 'map',
  doubleClickZoom: false,
  dragPan: false,
  dragRotate: false,
  interactive: false,
  keyboard: false,
  pitchWithRotate: false,
  scrollZoom: false,
  touchZoomRotate: false,
});

const mbLayer = new Layer({
  render: function (frameState) {
    const canvas = mbMap.getCanvas();
    const viewState = frameState.viewState;

    const visible = mbLayer.getVisible();
    canvas.style.display = visible ? 'block' : 'none';

    const opacity = mbLayer.getOpacity();
    canvas.style.opacity = opacity;

    // adjust view parameters in mapbox
    const rotation = viewState.rotation;
    mbMap.jumpTo({
      center: toLonLat(viewState.center),
      zoom: viewState.zoom - 1,
      bearing: (-rotation * 180) / Math.PI,
      animate: false,
    });

    // cancel the scheduled update & trigger synchronous redraw
    // see https://github.com/mapbox/mapbox-gl-js/issues/7893#issue-408992184
    // NOTE: THIS MIGHT BREAK IF UPDATING THE MAPBOX VERSION
    if (mbMap._frame) {
      mbMap._frame.cancel();
      mbMap._frame = null;
    }
    mbMap._render();

    return canvas;
  },
  source: new Source({
    attributions: [
      '<a href="https://www.maptiler.com/copyright/" target="_blank">© MapTiler</a>',
      '<a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>',
    ],
  }),
});

const style = new Style({
  stroke: new Stroke({
    color: '#319FD3',
    width: 2,
  }),
});

const vectorLayer = new VectorLayer({
  source: new VectorSource({
    url: 'data/geojson/countries.geojson',
    format: new GeoJSON(),
  }),
  style: style,
});

const map = new Map({
  target: 'map',
  view: new View({
    center: fromLonLat(center),
    zoom: 4,
  }),
  layers: [mbLayer, vectorLayer],
});

@@ -40,24 +40,79 @@
 eoJSON.js';%0A
+import HeatmapLayer from '../src/ol/layer/Heatmap.js';%0A
 import Layer
@@ -234,61 +234,8 @@
 s';%0A
-import VectorLayer from '../src/ol/layer/Vector.js';%0A
 impo
@@ -327,58 +327,8 @@
 s';%0A
-import %7BStroke, Style%7D from '../src/ol/style.js';%0A
 impo
@@ -1074,16 +1074,56 @@
  'none';
+%0A    canvas.style.position = 'absolute';
 %0A%0A    co
@@ -2044,128 +2044,28 @@
 nst 
-style = new Style(%7B%0A  stroke: new Stroke(%7B%0A    color: '#319FD3',%0A    width: 2,%0A  %7D),%0A%7D);%0A%0Aconst vectorLayer = new Vector
+cities = new Heatmap
 Laye
@@ -2124,14 +2124,17 @@
 son/
-countr
+world-cit
 ies.
@@ -2182,20 +2182,110 @@
 ,%0A  
-style: style
+weight: function (feature) %7B%0A    return feature.get('population') / 1e7;%0A  %7D,%0A  radius: 15,%0A  blur: 15
 ,%0A%7D)
@@ -2420,19 +2420,14 @@
 er, 
-vectorLayer
+cities
 %5D,%0A%7D

Update MapboxGL layer example