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. 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


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.


                <!DOCTYPE html>

  <meta charset="utf-8" />
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  <title>try/catch OGCFeatureLayer 4.16</title>
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;

    #infoDiv {
      position: absolute;
      top: 15px;
      left: 60px;

    #infoDiv input {
      border: none;
      box-shadow: rgba(0, 0, 0, 0.7) 1px 2px 3px;
      background-color: rgba(218, 204, 255, 1);
      width: 80px;
      height: 65px;
      font-size: 42px;
      color: rgba(76, 76, 76, 1);

  <link rel="stylesheet" href="" />
  <script src=""></script>

    ], function(
    ) {
      // Create the OGCFeatureLayer
      const countries = new OGCFeatureLayer({
        url: "", // url to the OGC service
        collectionId: "ne:countries50m", // unique id of the collection
        objectIdField: "NE_ID", // numeric object id
        title: "Countries", // give the layer a shorter title
        copyright: "",
        // add labeling with each country's name
        labelingInfo: [{
          labelExpressionInfo: {
            expression: "$feature.NAME"
          symbol: {
            type: "text", // autocasts as new TextSymbol()
            color: [76, 76, 76, 1],
            haloSize: 1,
            haloColor: [218, 204, 255, 1],
            font: {
              family: "Amarante",
              style: "normal",
              weight: "normal",
              size: 13
        // define rendering
        renderer: {
          type: "simple",
          symbol: {
            type: "simple-fill",
            style: "diagonal-cross",
            outline: {
              color: "white",
              width: "0.2px"
      // create map with custom basemap
      const map = new Map({
        basemap: new Basemap({
          baseLayers: [
            new VectorTileLayer({
              portalItem: {
                id: "95dc3d376d1a4ffb91f183814d4a820d"
        layers: [countries] // add OGCFeatureLayer
      // app configuration for switching between 2d and 3d
      var switchButton = document.getElementById("switch-btn");
      var appConfig = {
        mapView: null,
        sceneView: null,
        activeView: null,
        container: "viewDiv" // use same container for views
      // set parameters for MapView or SceneView
      var initialViewParams = {
        zoom: 4,
        center: [2, 48],
        container: appConfig.container,
        map: map,
        popup: {
          defaultPopupTemplateEnabled: true
      // create 2D view and and set active
      appConfig.mapView = createView(initialViewParams, "2d");
      appConfig.activeView = appConfig.mapView;
      // create 3D view, won't initialize until container is set
      initialViewParams.container = null;
      appConfig.sceneView = createView(initialViewParams, "3d");
      // switch the view between 2D and 3D each time the button is clicked
      switchButton.addEventListener("click", function() {
      // Switches the view from 2D to 3D and vice versa
      function switchView() {
        var is3D = appConfig.activeView.type === "3d";
        var activeViewpoint = appConfig.activeView.viewpoint.clone();
        // remove the reference to the container for the previous view
        appConfig.activeView.container = null;
        if (is3D) {
          // if the input view is a SceneView, set the viewpoint on the
          // mapView instance. Set the container on the mapView and flag
          // it as the active view
          try {
            console.log("Switching to 2D");
            appConfig.mapView.viewpoint = appConfig.container;
            appConfig.mapView.container = appConfig.mapView;
            appConfig.activeView = activeViewpoint;
            switchButton.value = "3D";
          } catch {
            console.log("Problem switching to 2D. Remaining in 3D.");
            appConfig.sceneView.viewpoint = activeViewpoint;
            appConfig.sceneView.container = appConfig.container;
            appConfig.activeView = appConfig.sceneView;
            switchButton.value = "2D";
        } else {
          try {
            console.log("Switching to 3D");
            appConfig.sceneView.viewpoint = activeViewpoint;
            appConfig.sceneView.container = appConfig.container;
            appConfig.activeView = appConfig.sceneView;
            switchButton.value = "2D";
          } catch {
            console.log("Problem switching to 3D. Remaining in 2D.");
            appConfig.mapView.viewpoint = activeViewpoint;
            appConfig.mapView.container = appConfig.container;
            appConfig.activeView = appConfig.mapView;
            switchButton.value = "3D";
      // convenience function for creating a 2D or 3D view
      function createView(params, type) {
        var view;
        var is2D = type === "2d";
        if (is2D) {
          view = new MapView(params);
          return view;
        } else {
          view = new SceneView(params);
        return view;

  <div id="viewDiv"></div>
  <div id="infoDiv">
    <input class="esri-component esri-widget--button esri-widget esri-interactive" type="button" id="switch-btn" value="3D" />