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.



Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO


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.


Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:


Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO



  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  ArcGIS API for JavaScript,
  For more information about the views-switch-2d-3d sample, read the original sample description at
<title>Switch view from 2D to 3D - 4.8</title>

  #viewDiv {
    padding: 0;
    margin: 0;
    height: 100%;
    width: 100%;

    position: absolute;
    top: 15px;
    left: 60px;

  #infoDiv input {
    border: none;
    box-shadow:  rgba(0, 0, 0, 0.3) 0px 1px 2px;

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

    ], function (MapView, SceneView, WebMap, WebScene, Map, FeatureLayer, Collection, Graphic, on) {
      var switchButton = document.getElementById("switch-btn");

      var appConfig = {
        mapView: null,
        sceneView: null,
        activeView: null,
        container: "viewDiv"  // use same container for views
      var map = new Map({
        basemap: 'streets',
        ground: 'world-elevation'

      var initialViewParams = {
        zoom: 4,
        center: [-100.43759993450347, 40.772798684981126],
        container: appConfig.container
      var webmap = new WebMap({
        map: map
      var scene = new WebScene({
        map: map
      var graphics = new Collection();
      var polyline = {
        type: "polyline",  // autocasts as new Polyline()
          paths: [
            [-111.30, 52.68],
            [-98, 49.5],
            [-93.94, 29.89]
      var polylineSymbol = {
        type: "simple-line",  // autocasts as SimpleLineSymbol()
        color: [226, 119, 40],
        width: 4
      var polylineAtt = {
        Name: "Keystone Pipeline",
        Owner: "TransCanada"
      var polylineGraphic = new Graphic({
        geometry: polyline,
        symbol: polylineSymbol,
        attributes: polylineAtt
      // Create an in-memory Feature Layer
      var fl = new FeatureLayer({
        id: 'test',
        source: graphics,
        fields: [
            name: "ObjectID",
            alias: "ObjectID",
            type: "oid"
            name: "Owner",
            alias: "Owner",
            type: "string"
            name: "Name",
            alias: "Name",
            type: "string"
        objectIdField: 'ObjectID',
        geometryType: 'polyline',
        spatialReference: { wkid: 4326 }
      // Add the Feature Layer to the map
      // create 2D view and and set active
      appConfig.mapView = createView(initialViewParams, "2d"); = map;
      appConfig.activeView = appConfig.mapView;

      // create 3D view, won't initialize until container is set
      initialViewParams.container = null; = map;
      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";

        // 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
          appConfig.mapView.viewpoint = appConfig.activeView.viewpoint.clone();
          appConfig.mapView.container = appConfig.container;
          appConfig.activeView = appConfig.mapView;
          switchButton.value = "3D";
          // When we go back into 2D, re-add the Feature Layer again
          console.log('mapp add');
        } else {
          // Switching to 3D, so we will remove that FeatureLayer, listen for the
          // layerview-destroy event before switching, this way we know it has been
          // removed from the map

          appConfig.sceneView.viewpoint = appConfig.activeView.viewpoint.clone();
          appConfig.sceneView.container = appConfig.container;
          appConfig.activeView = appConfig.sceneView;
          switchButton.value = "2D";
          console.log('setup handler');
          on.once(fl, 'layerview-create', function() {

      // convenience function for creating a 2D or 3D view
      function createView(params, type){
        var view;
        var is2D = type === "2d";
          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">




There are 10 kinds of people, those who understand binary and those who don’t.