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

              
                
   <div id="viewDiv"></div>


   <!-- Copied and customized from esri legend widget -->
   <div class="esri-component esri-legend esri-widget esri-widget--panel" style="display: none;">

      <div>
         <div class="esri-legend__service">
            <h3 class="esri-widget__heading esri-legend__service-label">Protests 2020</h3>
            <div class="esri-legend__layer">
               <div class="esri-legend__layer-table esri-legend__layer-table--size-ramp">
                  <div class="esri-legend__layer-caption">No. of Attendees</div>
                  <div class="esri-legend__layer-body">
                     <div class="esri-legend__layer-row">
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--symbols esri-legend__size-ramp">
                           <div class="esri-legend__symbol">
                              <div style="opacity: 1;"><svg xmlns="http://www.w3.org/2000/svg" width="40" height="40">
                                    <defs></defs>
                                    <g
                                       transform="matrix(0.9836065769195557,0,0,0.9836065769195557,0.32786884903907776,0.32786884903907776)">
                                       <circle fill-rule="evenodd" fill="rgba(255, 255, 255, 0)"
                                          stroke="rgba(255, 255, 255, 1)" stroke-width="0.6666666666666666"
                                          stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="none"
                                          stroke-miterlimit="4" cx="20" cy="20" r="20"></circle>
                                    </g>
                                 </svg></div>
                           </div>
                        </div>
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--info">&gt; 100,000</div>
                     </div>
                     <div class="esri-legend__layer-row">
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--symbols esri-legend__size-ramp">
                           <div class="esri-legend__symbol">
                              <div style="opacity: 1;"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14">
                                    <defs></defs>
                                    <g transform="matrix(1,0,0,1,0.3333333432674408,0.3333333432674408)">
                                       <circle fill-rule="evenodd" fill="rgba(255, 255, 255, 0)"
                                          stroke="rgba(255, 255, 255, 1)" stroke-width="0.6666666666666666"
                                          stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="none"
                                          stroke-miterlimit="4" cx="6.666666666666667" cy="6.666666666666667"
                                          r="6.666666666666667"></circle>
                                    </g>
                                 </svg></div>
                           </div>
                        </div>
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--info">500</div>
                     </div>
                     <div class="esri-legend__layer-row">
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--symbols esri-legend__size-ramp">
                           <div class="esri-legend__symbol">
                              <div style="opacity: 1;"><svg xmlns="http://www.w3.org/2000/svg" width="4" height="4">
                                    <defs></defs>
                                    <g
                                       transform="matrix(0.8571428656578064,0,0,0.8571428656578064,0.2857142984867096,0.2857142984867096)">
                                       <circle fill-rule="evenodd" fill="rgba(255, 255, 255, 0)"
                                          stroke="rgba(255, 255, 255, 1)" stroke-width="0.6666666666666666"
                                          stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="none"
                                          stroke-miterlimit="4" cx="2" cy="2" r="2"></circle>
                                    </g>
                                 </svg></div>
                           </div>
                        </div>
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--info">&lt; 1 or No Data</div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>

      <div>
         <div class="esri-legend__service protest-subject">
            <h3 class="esri-widget__heading esri-legend__service-label">&nbsp;</h3>
            <div class="esri-legend__layer">
               <div class="esri-legend__layer-table esri-legend__layer-table--size-ramp">
                  <div class="esri-legend__layer-caption">Description Mentions:</div>
                  <div class="esri-legend__layer-body">
                     <div class="esri-legend__layer-row protest-subject">
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--symbols esri-legend__size-ramp">
                           <div class="esri-legend__symbol">
                              <div style="opacity: 1;"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14">
                                    <defs></defs>
                                    <g transform="matrix(1,0,0,1,0.3333333432674408,0.3333333432674408)">
                                       <circle fill-rule="evenodd" fill="rgba(153, 51, 51, 0.5)"
                                          stroke="rgba(153, 51, 51, 1)" stroke-width="0.6666666666666666"
                                          stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="none"
                                          stroke-miterlimit="4" cx="6.666666666666667" cy="6.666666666666667"
                                          r="6.666666666666667"></circle>
                                    </g>
                                 </svg></div>
                           </div>
                        </div>
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--info">"Racial" or "Police"</div>
                     </div>
                     <div class="esri-legend__layer-row  protest-subject">
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--symbols esri-legend__size-ramp">
                           <div class="esri-legend__symbol">
                              <div style="opacity: 1;"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14">
                                    <defs></defs>
                                    <g transform="matrix(1,0,0,1,0.3333333432674408,0.3333333432674408)">
                                       <circle fill-rule="evenodd" fill="rgba(255, 102, 0, 0.5)"
                                          stroke="rgba(255, 102, 0, 1)" stroke-width="0.6666666666666666"
                                          stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="none"
                                          stroke-miterlimit="4" cx="6.666666666666667" cy="6.666666666666667"
                                          r="6.666666666666667"></circle>
                                    </g>
                                 </svg></div>
                           </div>
                        </div>
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--info">"Coronavirus"</div>
                     </div>
                     <div class="esri-legend__layer-row  protest-subject">
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--symbols esri-legend__size-ramp">
                           <div class="esri-legend__symbol">
                              <div style="opacity: 1;"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14">
                                    <defs></defs>
                                    <g transform="matrix(1,0,0,1,0.3333333432674408,0.3333333432674408)">
                                       <circle fill-rule="evenodd" fill="rgba(124,185,232, 0.5)"
                                          stroke="rgba(124,185,232, 1)" stroke-width="0.6666666666666666"
                                          stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="none"
                                          stroke-miterlimit="4" cx="6.666666666666667" cy="6.666666666666667"
                                          r="6.666666666666667"></circle>
                                    </g>
                                 </svg></div>
                           </div>
                        </div>
                        <div class="esri-legend__layer-cell esri-legend__layer-cell--info">Other</div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>

   </div>


              
            
!

CSS

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

.esri-ui-bottom-right{
  width: 100%;
}
.esri-time-slider {
  width: 50%;
  max-width: 500px;
}

.esri-ui-corner .esri-component.esri-widget--panel {
  width: auto;
}

.esri-legend__layer-row.protest-subject {
  display: block;
  margin-bottom: 10px;
}
.esri-legend__service.protest-subject {
  width: 200px;
}

.esri-legend__service.protest-subject .esri-legend__layer-caption {
  margin-bottom: 10px;
}

.esri-legend__service.protest-subject .esri-legend__layer-cell.esri-legend__layer-cell--info {
  width: auto;
  max-width: auto;
}
              
            
!

JS

              
                require([
	'esri/Map',
	'esri/views/MapView',
	'esri/layers/FeatureLayer',
	'esri/layers/TileLayer',
	'esri/widgets/TimeSlider',
	'esri/smartMapping/renderers/heatmap',
], function (
	Map,
	MapView,
	FeatureLayer,
	TileLayer,
	TimeSlider,
	heatmapRendererCreator
) {
	var fireflyLayer = new TileLayer({
		url:
			'https://fly.maptiles.arcgis.com/arcgis/rest/services/World_Imagery_Firefly/MapServer',
	});

	var referenceLayer = new TileLayer({
		url:
			'https://services.arcgisonline.com/arcgis/rest/services/Canvas/World_Dark_Gray_Reference/MapServer',
	});

	var covidLayer = new FeatureLayer({
		url:
			'https://services8.arcgis.com/bc1qjUYAgNrEBXVh/arcgis/rest/services/COVID19_Time_Series_Combined/FeatureServer',
		outFields: ['*'],
		renderer: {
			type: 'heatmap',
			field: 'Confirmed',
			colorStops: [
				{ ratio: 0, color: 'rgba(255, 255, 255, 0)' },
				{ ratio: 0.06, color: 'rgba(255, 255, 255, 1)' },
				{ ratio: 0.15, color: 'rgba(255, 255, 0, 1)' },
				{ ratio: 0.25, color: 'rgba(255, 140, 0, 1)' },
				{ ratio: 0.55, color: 'rgba(255, 0, 0, 1)' },
			],
			minPixelIntensity: 1,
			maxPixelIntensity: 150000000,
			blurRadius: 12,
		},
	});

	// define map and view
	var map = new Map({
		layers: [fireflyLayer, covidLayer, referenceLayer],
	});

	var view = new MapView({
		container: 'viewDiv',
		center: [20, 0],
		zoom: 2,
		map: map,
		highlightOptions: {
			fillOpacity: 0,
			color: [50, 50, 50],
		},
	});

	var timeSlider = new TimeSlider({
		container: 'timeSliderDiv',
		view: view,
		mode: 'time-window',
		fullTimeExtent: {
			start: new Date(2020, 1, 1),
			end: new Date(2020, 11, 1),
		},
		playRate: 3000,
		stops: {
			interval: {
				value: 1,
				unit: 'months',
			},
		},
		tickConfigs: [
			{
				mode: 'count',
				values:
					new Date(2020, 11, 31) > new Date()
						? new Date().getMonth() + 1
						: 12,
				labelsVisible: true,
				labelFormatFunction: (value) => {
					const date = new Date(value);
					return date.toLocaleString('default', { month: 'short' });
				},
			},
		],
	});
	updateDefintionExpression(timeSlider.timeExtent);

	view.ui.add(timeSlider, 'bottom-right');

	timeSlider.watch('timeExtent', function (value) {
		updateDefintionExpression(value);

		// const params = {
		//    layer: covidLayer,
		//    view,
		//    field: "Confirmed",
		//    fadeToTransparent: true,
		//    minRatio: 0.05
		// }

		// heatmapRendererCreator.createRenderer(params)
		// .then(result => {
		//    covidLayer.renderer = result.renderer
		//    console.log(result.renderer)
		// })
	});

	function updateDefintionExpression(timeExtent) {
		const start = toDateString(timeExtent.start);
		const end = toDateString(timeExtent.end);
		covidLayer.definitionExpression = `Date >= DATE '${start}' AND Date <= DATE '${end}'`;
	}

	function toDateString(date) {
		const y = `${date.getUTCFullYear()}`;
		const m = `${date.getUTCMonth()}`.padStart(2, '0');
		const d = `${date.getUTCDate()}`.padStart(2, '0');
		const h = `${date.getUTCHours()}`.padStart(2, '0');
		const mm = `${date.getUTCMinutes()}`.padStart(2, '0');
		const s = `${date.getUTCSeconds()}`.padStart(2, '0');
		return `${y}-${m}-${d} ${h}:${mm}:${s}`;
	}

	// const params = {
	//    layer: covidLayer,
	//    view,
	//    field: "Confirmed",
	//    fadeToTransparent: true,
	//    minRatio: 0.05
	// }

	// heatmapRendererCreator.createRenderer(params)
	// .then(result => {
	//    covidLayer.renderer = result.renderer
	//    console.log(result.renderer)
	// })
});

              
            
!
999px

Console