Pen Settings

HTML

CSS

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                 <div id="map">
              
            
!

CSS

              
                
/*DOM basic styles*/
html, body {
  border: 0;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased; 
  height: 100%;
  width: 100%;
  overflow-y: hidden;
  overflow-x: hidden;
  webkit-overflow-scrolling: auto;
  position: absolute;
  color: #000;
}


/* MAP CANVAS & related styles */
#map { 
  height: 900px;
  width: 100%;
  background-color: #f2f2f2;
  cursor: move;
  -webkit-tap-highlight-color: transparent;
}

              
            
!

JS

              
                let style = {
  version: 8,
  name: "artisticPatterns",
  glyphs: "https://ta.webmapper.nl/wm/glyphs/{fontstack}/{range}.pbf",
  sprite: "https://tc.webmapper.nl/wm/sprites/pattern",
  sources: {
    wm_visdata: {
      type: "vector",
      url: "https://tb.webmapper.nl/wm/styles/tile.json"
    }
  },
  layers: [
    {
      id: "background",
      type: "background",
      paint: {
        "background-color": "#f2f2f2",
        "background-pattern": "paper"
      }
    },
    {
      id: "water-shadow-inside",
      type: "line",
      source: "wm_visdata",
      "source-layer": "water",
      minzoom: 9,
      filter: ["!in", "type", "tidal_flat"],
      layout: {
        "line-cap": "square",
        "line-join": "round",
        "line-round-limit": 5
      },
      paint: {
        "line-color": "#000",
        "line-width": [
          "interpolate",
          ["exponential", 1.25],
          ["zoom"],
          9,
          0,
          20,
          24
        ],
        "line-blur": [
          "interpolate",
          ["exponential", 1.1],
          ["zoom"],
          9,
          0,
          20,
          12
        ],
        "line-translate": [
          "interpolate",
          ["exponential", 1.25],
          ["zoom"],
          9,
          ["literal", [0.5, 0.5]],
          20,
          ["literal", [6, 6]]
        ],
        "line-translate-anchor": "viewport",
        "line-opacity": [
          "interpolate",
          ["exponential", 1],
          ["zoom"],
          9,
          0.05,
          20,
          0.9
        ]
      }
    },
    {
      id: "land-3",
      source: "wm_visdata",
      "source-layer": "builtup",
      type: "fill",
      paint: {
        "fill-color": "#f2f2f2",
        "fill-outline-color": "#f2f2f2",
        "fill-opacity": 0.9
      }
    },
    {
      id: "water2",
      source: "wm_visdata",
      "source-layer": "water",
      type: "fill",
      filter: ["!in", "type", "tidal_flat"],
      paint: {
        "fill-pattern": "dots-fill"
      }
    },
    {
      id: "land-1",
      source: "wm_visdata",
      "source-layer": "natural",
      type: "fill",
      paint: {
        "fill-color": "#f2f2f2",
        "fill-outline-color": "#f2f2f2"
      }
    },
    {
      id: "land-2",
      source: "wm_visdata",
      "source-layer": "agricultural",
      type: "fill",
      paint: {
        "fill-color": "#f2f2f2",
        "fill-outline-color": "#f2f2f2"
      }
    },
    {
      id: "agriculture",
      source: "wm_visdata",
      "source-layer": "agricultural",
      type: "fill",
      paint: {
        "fill-pattern": "agri"
      }
    },
    {
      id: "land-4",
      source: "wm_visdata",
      "source-layer": "infrastructure",
      type: "fill",
      paint: {
        "fill-color": "#f2f2f2",
        "fill-outline-color": "#f2f2f2"
      }
    },
    {
      id: "water",
      source: "wm_visdata",
      "source-layer": "water",
      type: "line",
      filter: ["!in", "type", "tidal_flat"],
      layout: {
        "line-cap": "square",
        "line-join": "round",
        "line-miter-limit": 1
      },
      paint: {
        "line-pattern": "line-dots",
        "line-width": [
          "interpolate",
          ["exponential", 1.4],
          ["zoom"],
          9,
          0,
          20,
          32
        ],
        "line-offset": [
          "interpolate",
          ["exponential", 1.1],
          ["zoom"],
          9,
          0,
          20,
          -2
        ]
      }
    },
    {
      id: "water-line-z0-z9",
      source: "wm_visdata",
      "source-layer": "water",
      type: "line",
      maxzoom: 11,
      filter: ["!in", "type", "tidal_flat"],
      layout: {
        "line-cap": "square",
        "line-join": "round",
        "line-miter-limit": 1
      },
      paint: {
        "line-width": 0.1,
        "line-color": "#535353"
      }
    },
    {
      id: "natural",
      source: "wm_visdata",
      "source-layer": "natural",
      type: "fill",
      layout: {
        visibility: "none"
      },
      paint: {
        "fill-color": "#f2f2f2",
        "fill-outline-color": "#f2f2f2"
      }
    },
    {
      id: "railways",
      source: "wm_visdata",
      "source-layer": "railways",
      type: "line",
      paint: {
        "line-color": "#535353",
        "line-width": 2,
        "line-opacity": 0.5,
        "line-dasharray": [2, 3]
      }
    },

    {
      id: "urban-area-line",
      source: "wm_visdata",
      "source-layer": "builtup",
      type: "line",
      maxzoom: 14.5,
      filter: ["all", ["==", "type", "area"]],
      layout: {
        "line-cap": "round",
        "line-join": "round"
      },
      paint: {
        "line-color": "#535353",
        "line-width": 3.5,
        "line-blur": 0.5
      }
    },
    {
      id: "urban-area-fill",
      source: "wm_visdata",
      "source-layer": "builtup",
      type: "fill",
      maxzoom: 14.5,
      filter: ["all", ["==", "type", "area"]],
      layout: {},
      paint: {
        "fill-color": "#f2f2f2"
      }
    },
    {
      id: "urban-area",
      source: "wm_visdata",
      "source-layer": "builtup",
      type: "fill",
      maxzoom: 14.5,
      filter: ["all", ["==", "type", "area"]],
      layout: {},
      paint: {
        "fill-opacity": ["interpolate", ["linear"], ["zoom"], 13.5, 1, 15.9, 0],
        "fill-pattern": [
          "step",
          ["zoom"],
          "house-fill-small",
          10,
          "house-fill",
          11,
          "house-fill-big"
        ]
      }
    },
    {
      id: "bos-lijn-shadow",
      source: "wm_visdata",
      "source-layer": "natural",
      type: "line",
      filter: ["==", "type", "high"],
      layout: {
        "line-cap": "square",
        "line-join": "round",
        "line-round-limit": 5
      },
      paint: {
        "line-color": "#000",
        "line-width": [
          "interpolate",
          ["exponential", 1],
          ["zoom"],
          9,
          0,
          20,
          10
        ],
        "line-blur": ["interpolate", ["exponential", 1], ["zoom"], 9, 0, 20, 5],
        "line-translate": [
          "interpolate",
          ["exponential", 1],
          ["zoom"],
          9,
          ["literal", [0.5, 0.5]],
          20,
          ["literal", [1.5, 1.5]]
        ],
        "line-translate-anchor": "viewport",
        "line-opacity": [
          "interpolate",
          ["exponential", 1],
          ["zoom"],
          9,
          0.05,
          20,
          0.9
        ]
      }
    },
    {
      id: "roads",
      source: "wm_visdata",
      "source-layer": "roads",
      type: "line",
      paint: {
        "line-color": "#ffffff",
        "line-width": [
          "match",
          ["get", "type"],
          "highway",
          8,
          "motorway",
          7,
          "local",
          4,
          5
        ],
        "line-opacity": 1,
        "line-blur": 0.5
      }
    },
    {
      id: "roads2",
      source: "wm_visdata",
      "source-layer": "roads",
      type: "line",
      layout: {
        "line-join": "round",
        "line-cap": "round"
      },
      paint: {
        "line-pattern": "line",
        "line-width": [
          "match",
          ["get", "type"],
          "highway",
          4,
          "motorway",
          3,
          "local",
          1,
          2
        ]
      }
    },
    {
      id: "bos",
      source: "wm_visdata",
      "source-layer": "natural",
      type: "fill-extrusion",
      filter: ["==", "type", "high"],
      paint: {
        "fill-extrusion-pattern": "forest2",
        "fill-extrusion-height": 4
      }
    },
    {
      id: "building",
      source: "wm_visdata",
      "source-layer": "builtup",
      type: "symbol",
      minzoom: 13,
      filter: ["all", ["==", "type", "building"]],
      layout: {
        "symbol-placement": "line-center",
        "symbol-spacing": 50,
        "icon-image": "house",
        "icon-anchor": "bottom",
        "icon-rotation-alignment": "viewport",
        "icon-pitch-alignment": "viewport",
        "icon-allow-overlap": true,
        "icon-padding": 10,
        "icon-size": ["interpolate", ["linear"], ["zoom"], 13, 0.3, 15, 1]
      },
      paint: {
        "icon-opacity": 1
      }
    },
    {
      id: "church",
      source: "wm_visdata",
      "source-layer": "pois",
      type: "symbol",
      filter: ["in", "subsubtype", "place_of_worship"],
      layout: {
        "icon-rotation-alignment": "viewport",
        "icon-pitch-alignment": "viewport",
        "icon-allow-overlap": true,
        "icon-image": "church",
        "icon-anchor": "bottom",
        "icon-padding": 4,
        "icon-size": [
          "interpolate",
          ["linear"],
          ["zoom"],
          13,
          0.3,
          15,
          1.2,
          16,
          1.5
        ]
      }
    },
    {
      id: "place-labels",
      type: "symbol",
      source: "wm_visdata",
      "source-layer": "labels",
      filter: [
        "all",
        ["==", "type", "place"],
        ["!=", "subtype", "urban_district"]
      ],
      minzoom: 8,
      maxzoom: 16,
      layout: {
        "text-allow-overlap": false,
        "text-padding": 5,
        "text-size": [
          "interpolate",
          ["exponential", 0.9],
          ["get", "hierarchy"],
          1,
          46,
          6,
          23,
          7,
          0
        ],
        "text-font": ["Giraffey"],
        "text-field": ["upcase", ["get", "name"]],
        "text-rotation-alignment": "viewport"
      },
      paint: {
        "text-halo-blur": 0.5,
        "text-color": "#000000",
        "text-halo-width": 2,
        "text-halo-color": "#fff"
      }
    }
  ]
};

// Creating Mapbox map
//---------------------
const map = new mapboxgl.Map({
  container: "map",
  style: style,
  zoom: 8.5,
  center: [4.91095, 52.36698],
  attributionControl: true
});

// DRAW RANDOM POINTS ON MAP BOUND
const drawRandomPoints = function() {
  // get the map bounds
  let bounds = map.getBounds();
  let ne_lng = bounds._ne.lng;
  let ne_lat = bounds._ne.lat;
  let sw_lng = bounds._sw.lng;
  let sw_lat = bounds._sw.lat;
  let points = turf.randomPoint(100, {
    bbox: turf.bbox(
      turf.buffer(turf.bboxPolygon([sw_lng, sw_lat, ne_lng, ne_lat]), -1000, {
        units: "meters"
      })
    )
  });
  return points;
};

// RANDOM HOT AIR BALLOONS!
map.on("load", function(e) {
  map.addLayer({
    id: "points",
    type: "symbol",
    source: {
      type: "geojson",
      data: drawRandomPoints()
    },
    layout: {
      "icon-image": "balloon",
      "icon-allow-overlap": true,
      "icon-anchor": "bottom",
      "icon-offset": [0, -10]
    },
    paint: {}
  });
  // NEW BALLOONS ON MAP MOVE END
  map.on("moveend", function() {
    if (map.getLayer("points")) {
      map.getSource("points").setData(drawRandomPoints());
    }
  });
});



// Increase fonts for bad sighted people
const changeFontSize = function (factor) {
  let stijl = map.getStyle();
  stijl.layers.forEach((layer) => {
    if (layer.type === "symbol" && layer.layout["text-size"]) {
      let currentsize = layer.layout["text-size"];
      console.log(currentsize)
      if (currentsize.length > 4) {
        for (let i = 4; i <= currentsize.length; i += 2) {
          currentsize[i] = currentsize[i] * factor;
        };
        map.setLayoutProperty(layer.id, 'text-size', currentsize);
      }
      else if (typeof currentsize === "number") {
        map.setLayoutProperty(layer.id, 'text-size', currentsize * factor);
      }
      else { console.log("different style for text size") }
    }
  })
}; 


var press = d3.select('body'); 

// Key press
press.on("keypress", function () {
  if (d3.event.key == 'l' ) {
    changeFontSize(1.2)
  } else if (d3.event.key == 's') {
    changeFontSize(0.8)
  }
});
              
            
!
999px

Console