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.



  <meta charset="utf-8" />
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
  <title>ArcGIS JSAPI ESM Template</title>

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

  <div id="viewDiv">



body {
	height: 100%;
	width: 100%;
	margin: 0;
	padding: 0;

#viewDiv {
	height: 100%;
	width: 100%;



                import ArcGISMap from "";
import MapView from "";
import FeatureLayer from "";
import { whenFalseOnce } from "";
import * as colorRendererCreator from "";
import Legend from ""

const btn = document.getElementById("btnStart");

const cityLayer = new FeatureLayer({
	portalItem: {
		id: "e39d04981238498792eb33ea26ba1c09"

const frsLayer = new FeatureLayer({
	portalItem: {
		id: "cdff193a3e3743a5bc770e2743f215b3"

const map = new ArcGISMap({
	basemap: "dark-gray-vector",
	layers: [cityLayer, frsLayer]

const view = new MapView({
	container: "viewDiv",
	center: [-117.98, 33.96],
	zoom: 12

const legend = new Legend({ view });
view.ui.add(legend, "top-right");

view.when(async () => {
	// todo bad stuff
	const [ cityLayerView, frsLayerView ] = await Promise.all([
	await whenFalseOnce(view, "updating");
	const query = {
		returnGeometry: true
	const cityResults = await cityLayerView.queryFeatures(query);
	const frsResults = await frsLayerView.queryFeatures(query);
	const features = [];
	let temp = [...frsResults.features];
	let temp2 = [];
	for (let feat of cityResults.features) {
		const graphic = feat.clone();
		graphic.attributes.count = 0;
		temp2 = [...temp];
		for (let i = 0; i < temp2.length; i++) {
			const x = temp[i];
			if ((x && graphic.geometry && x.geometry) && graphic.geometry.contains(x.geometry)) {
				temp.splice(i, 1);
	map.removeMany([cityLayer, frsLayer]);
	const joinLayer = await createLayer(cityLayer, features, [{
		name: "count",
		alist: "Count",
		type: "integer"
	const { renderer } = await colorRendererCreator.createContinuousRenderer({
		layer: joinLayer,
		field: "count",
		them: "above-and-below"
	joinLayer.renderer = renderer;

async function createLayer(layer, source, extraFields) {
	await layer.load();

	// create a Map to hold field info
	const fieldInfosMap = new Map();

	for (const field of [...layer.fields]) {
		fieldInfosMap.set(, {
			label: field.alias ||

	const fieldInfos = [ Set(fieldInfosMap.values())];

	const featLayer = new FeatureLayer({
		title: "Spatial Join Layer",
		objectIdField: layer.objectIdField,
		fields: [ Set([...layer.fields, ...extraFields])],
		geometryType: layer.geometryType,
		// if schema of two layers is different,
		// popup will have empty fields shown
		popupTemplate: {
			title: "Copy Layer",
			content: [
					type: "fields",
					fieldInfos: [...fieldInfos.values()]
	return featLayer;