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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <link rel="stylesheet" href="https://js.arcgis.com/4.24/esri/themes/light/main.css" />
<div id="viewDiv"></div>
              
            
!

CSS

              
                html,
body,
#viewDiv {
  padding: 0;
  margin: 0;
  height: 100%;
  width: 100%;
}

              
            
!

JS

              
                import MapView from "https://js.arcgis.com/4.24/@arcgis/core/views/MapView.js";
import FeatureLayer from "https://js.arcgis.com/4.24/@arcgis/core/layers/FeatureLayer.js";
// import SceneView from "https://js.arcgis.com/4.24/@arcgis/core/views/SceneView.js";
// Note: Only use ES modules from ArcGIS CDN for testing: https://arcg.is/1ii1Gb0

// Note the "interact" function (from the interactjs library, https://interactjs.io/)
// ... is loaded via script tag - see Codepen Settings > JS > External Scripts

const featureLayer = new FeatureLayer({
  url:
    "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0",
  popupEnabled: true,
  popupTemplate: {
    title: "{areaname}, {st}",
    content: "Population (2000): {pop2000}"
  }
});

const viewOptions = {
  container: "viewDiv",
  map: {
    basemap: "streets-vector",
    layers: [featureLayer]
  },
  center: [-101.17, 35],
  zoom: 3
};

// 3D:
// const view = new SceneView(viewOptions);
// 2D:
const view = new MapView(viewOptions);

const popupTargetSelectionString = ".esri-component.esri-popup";

const setupInteractJs = () => {
  // popup opened - first delete the old listener if applicable:
  // https://github.com/taye/interact.js/blob/main/docs/faq.md#remove--destroy--release
  if (interact.isSet(popupTargetSelectionString)) {
    interact(popupTargetSelectionString).unset();
  }

  // setup the new listener:
  const position = { x: 0, y: 0 };
  interact(popupTargetSelectionString).draggable({
    listeners: {
      // start (event) {
      //   console.log(event.type, event.target)
      // },
      move(event) {
        // hide the popup pointer:
        const elements = document.querySelectorAll(".esri-popup__pointer");
        elements[0].style.display = "none";

        // calculate the position and update:
        position.x += event.dx;
        position.y += event.dy;

        event.target.style.transform = `translate(${position.x}px, ${position.y}px)`;
      }
    }
  });
};

view.when(() => {
  view.popup.watch("features", (features) => {
    if (features.length === 0) {
      // popup closed - reset the transform css so that it doesn't move next time the popup opens
      const elements = document.querySelectorAll(popupTargetSelectionString);
      if (elements && elements.length > 0) {
        elements[0].style.transform = `translate(0px, 0px)`;
      }
    } else {
      setupInteractJs();
    }
  });
});

              
            
!
999px

Console