Skip to content

Instantly share code, notes, and snippets.

@andygup
Created February 7, 2017 16:35
Show Gist options
  • Select an option

  • Save andygup/c423665a489bb50018cc773617b54cdf to your computer and use it in GitHub Desktop.

Select an option

Save andygup/c423665a489bb50018cc773617b54cdf to your computer and use it in GitHub Desktop.
Create an ArcGIS JS API 4.x widget using a simple template
function createMapWidgets() {
var is2d = viewIs2D();
// Home
homeWidget = new Home({view: view});
view.ui.add(homeWidget, "top-left");
// Zoom
zoomWidget = new Zoom({view: view});
view.ui.add(zoomWidget, "top-left");
// Compass
compassWidget = new Compass({view: view});
view.ui.add(compassWidget, "top-left");
// Attribution
attributionWidget = new Attribution({view: view});
view.ui.add(attributionWidget, {position: "manual"});
// 2D/3D widget
var icon;
if (is2d) {
icon = "class='esri-icon esri-icon-globe'";
} else {
icon = "class='esri-icon esri-icon-maps'";
}
var fragment = document.createDocumentFragment();
var widget2d3d = domConstruct.place("<div role='button' class='esri-home esri-widget-button esri-widget esri-component' id='esri2d3dWidget'>" +
"<span aria-hidden='true' " + icon + " title='2D/3D Map'></span>" +
"<span class='esri-icon-font-fallback-text'>3D</span>" +
"</div>", fragment);
view.ui.add(widget2d3d, "top-left");
// Show other view and restart
query(widget2d3d).on("click", function(){
play(false);
createMap(!is2d);
createMapWidgets();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment