Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


    <script src=''></script>
    <link href='' rel='stylesheet' />
      <h1>Koordinates tile services with Mapbox GL demo</h1>
    <!-- Map container -->
    <div id='map'></div>

    <!-- HTML5 template for popup content -->
    <template id="popup-template">
      <div class="popup">
        <h2>Nearest Quake</h2>
          <dd class="origintime"></dd>
          <dd class="magnitude"></dd>
          <dd><span class="depth"></span> km</dd>


body {
  height: 100%;
  margin: 0;
  padding: 0 10px;
  font-family: sans-serif;
body {
  display: flex;
  flex-direction: column;
header {
  min-height: 60px;

/* make the map expand to fill available space */
#map {
  flex-grow: 1;
  overflow: auto;
/* set the cursor for map navigation */
#map canvas {
  cursor: crosshair;

/* popup styling */
.popup dt {
  font-weight: bold;
  text-transform: uppercase;
.popup dd {
  margin-left: 10px;


                mapboxgl.accessToken =

var map = new mapboxgl.Map({
  container: "map", // container id
  style: "mapbox://styles/mapbox/outdoors-v11",
  center: [175, -41],
  zoom: 6

// Insert the Koordinates layer *below* the basemap labels + roads
map.on("load", function() {
  // Find the ID of the first symbol layer in the map style
  // We use this to insert our layer beneath roads/pois/labels/etc
  var firstSymbolId = map.getStyle().layers.find(l => (l.type === "symbol")).id;

      id: "koordinates-earthquakes",
      type: "raster",
      source: {
        type: "raster",
        tiles: [
          // This is the XYZ template URL from the Koordinates layer
          // services page:
        tileSize: 256,
        maxzoom: 22,
          "<a href=''>New Zealand Earthquakes</a>"
    firstSymbolId // Insert the layer beneath the first symbol layer.

  // When a click event occurs on a feature in the states layer, open a popup at the
  // location of the click, with description HTML from its properties.
  var quakeMarker;
  map.on("click", function(e) {
    // construct the query url
    let queryUrl = new URL('');
    // documentation of parameters at
    let queryParams = {
      key: '1c6ead7c5174463eab66bcea1005233d',  // Koordinates API Key
      layer: 7328,                              // Koordinates Layer ID
      x: e.lngLat.lng,                          // map click location
      max_results: 1,                           // find the closest result
      radius: 1000,                             // max. search distance 1km
      geometry: true                            // Include geometry in the response
    }; = new URLSearchParams(queryParams);
    // make the API request
      .then(function(response) {
        if (!response.ok) {
          throw new Error("HTTP error, status = " + response.status);
        return response.json();
      .then(function(response) {
        // extract the first feature from the response
        const feature = response.vectorQuery.layers['7328'].features[0];
        console.log("Feature:", feature);

        if (feature === undefined) {
          // no features within 1km
          if (quakeMarker) {
            // remove marker from map
            quakeMarker = null;

        // position map marker
        if (!quakeMarker) {
          // add marker
          quakeMarker = new mapboxgl.Marker()
        } else {
          // move existing marker

        // create popup content
        let popupTemplate = document.getElementById('popup-template');
        let popupContent = document.importNode(popupTemplate.content, true);
        popupContent.querySelector('.origintime').textContent =;
        popupContent.querySelector('.magnitude').textContent =;
        popupContent.querySelector('.depth').textContent =;

        // open map popup
        let popup = new mapboxgl.Popup({anchor: 'left', offset: 10})