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

              
                <html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Hello!</title>
    <link rel="stylesheet" href="https://js.arcgis.com/next/esri/themes/dark/main.css">
  </head>  
  <body>
    <div id="viewDiv"></div>
    <button id="toggle">Start Editing</button>
    <button id="edit">Apply Edits</button>
  </body>
</html>

              
            
!

CSS

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

.editing {
	background: red;
	color: white;
}

.hide {
	display: none;
}
              
            
!

JS

              
                import ArcGISMap from "https://js.arcgis.com/next/@arcgis/core/Map.js";
import MapView from "https://js.arcgis.com/next/@arcgis/core/views/MapView.js";
import FeatureLayer from "https://js.arcgis.com/next/@arcgis/core/layers/FeatureLayer.js";
import Editor from "https://js.arcgis.com/next/@arcgis/core/widgets/Editor.js";
import { whenFalse } from "https://js.arcgis.com/next/@arcgis/core/core/watchUtils.js";

const toggle = document.getElementById("toggle");
const edit = document.getElementById("edit");

const layer = new FeatureLayer({
	url:
		"https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/IncidentsReport/FeatureServer/0",
	outFields: ["*"],
	popupEnabled: false,
	id: "incidentsLayer"
});

const map = new ArcGISMap({
	basemap: "dark-gray-vector",
	layers: [layer]
});

const view = new MapView({
	container: "viewDiv",
	map,
	zoom: 12,
	center: [-117.18, 34.06]
});

view.ui.add([toggle, edit], "top-right");

function copyLayer(lyr, title) {
	const tempLayer = new FeatureLayer({
		title,
		fields: lyr.fields.map(x => x.clone()),
		geometryType: lyr.geometryType,
		renderer: lyr.renderer.clone(),
		spatialReference: lyr.spatialReference.clone(),
		source: [],
		visible: false
	});
	return tempLayer;
}

view.when(async () => {
	const layerView = await view.whenLayerView(layer);

	const clientLayer = copyLayer(layer, "Client Layer");
	const editLayer = copyLayer(layer, "Edit Layer");
	
	const editor = new Editor({
		view,
		layerInfos: [{
			view,
			layer: editLayer,
			addEnabled: true,
			updateEnabled: false
		}, {
			view,
			layer: clientLayer,
			enabled: false
		}, {
			view,
			layer: layer,
			enabled: false
		}]
	});
	
	map.add(clientLayer);
	map.add(editLayer);
	whenFalse(layerView, "updating", async () => {
		const { features } = await layerView.queryFeatures();
		const oids = await clientLayer.queryObjectIds();
		const result = await clientLayer.applyEdits({
			addFeatures: features,
			deleteFeatures: oids.map(x => ({ objectId: x }))
		});
		const count = await clientLayer.queryFeatureCount();
	});
	
	toggle.addEventListener("click", async () => {
		layer.visible = !layer.visible;
		clientLayer.visible = !layer.visible;
		editLayer.visible = true
		toggle.classList.toggle("editing");
		edit.classList.toggle("hide");
		if (toggle.innerHTML === "Start Editing") {
			toggle.innerHTML = "Stop Editing";
			view.ui.add(editor, "top-right");
		}
		else {
			toggle.innerHTML = "Start Editing";
			view.ui.remove(editor);
		}
	});
	
	// client layer - static copy
	// edit layer - edits are done
	// source layer - edits applied
	
	edit.addEventListener("click", async () => {
		const { features } = await editLayer.queryFeatures();
		const result = await layer.applyEdits({
			addFeatures: features
		})
		.catch(err => console.log(error));
		layer.refresh();
		editLayer.refresh();
		editLayer.visible = true;
		
		const oids = features.map((a) =>  a.attributes.OBJECTID);
		await editLayer.applyEdits({
			deleteFeatures: oids
		});
	});
});


              
            
!
999px

Console