cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline'">
  <div id="header" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'">
    <span>Draw:<br /></span>
    <button data-dojo-type="dijit/form/Button">Point</button>
    <button data-dojo-type="dijit/form/Button">Multi Point</button>
    <button data-dojo-type="dijit/form/Button">Line</button>
    <button data-dojo-type="dijit/form/Button">Polyline</button>
    <button data-dojo-type="dijit/form/Button">Polygon</button>
    <button data-dojo-type="dijit/form/Button">Free Polyline</button>
    <button data-dojo-type="dijit/form/Button">Free Polygon</button>
    <!--The Arrow,Triangle,Circle and Ellipse types all draw with the polygon symbol-->
    <button data-dojo-type="dijit/form/Button">Arrow</button>
    <button data-dojo-type="dijit/form/Button">Triangle</button>
    <button data-dojo-type="dijit/form/Button">Circle</button>
    <button data-dojo-type="dijit/form/Button">Ellipse</button>
  </div>
  <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"></div>
</div>
            
          
!
            
              html,
body,
#mainWindow {
  font-family: sans-serif;
  height: 100%;
  width: 100%;
}

html,
body {
  margin: 0;
  padding: 0;
}

#header {
  height: 80px;
  overflow: auto;
  padding: 0.5em;
}
            
          
!
            
              var map, toolbar, symbol, geomTask, onDrawBegin;

require([
  "esri/map",
  "esri/toolbars/draw",
  "esri/graphic",
  "esri/Color",

  "esri/symbols/SimpleMarkerSymbol",
  "esri/symbols/SimpleLineSymbol",
  "esri/symbols/SimpleFillSymbol",

  "dojo/parser", "dijit/registry", "dojo/on", "dojo/_base/array",

  "dijit/layout/BorderContainer", "dijit/layout/ContentPane",
  "dijit/form/Button", "dijit/WidgetSet", "dojo/domReady!"
], function(
  Map, Draw, Graphic, esriColor,
  SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,
  parser, registry, dojoOn, arrayUtils
) {
  parser.parse();

  map = new Map("map", {
    basemap: "streets",
    center: [-15.469, 36.428],
    zoom: 3
  });

  map.on("load", createToolbar);

  // loop through all dijits, connect onClick event
  // listeners for buttons to activate drawing tools
  registry.forEach(function(d) {
    // d is a reference to a dijit
    // could be a layout container or a button
    if (d.declaredClass === "dijit.form.Button") {
      d.on("click", activateTool);
    }
  });

  function activateTool() {
    var tool = this.label.toUpperCase().replace(/ /g, "_");
    toolbar.deactivate();
    toolbar.activate(Draw[tool]);
    map.hideZoomSlider();
  }

  function createToolbar(themap) {
    toolbar = new Draw(map);
    toolbar.on("draw-begin", function() {
      try {
        arrayUtils.forEach(map.graphics.graphics, function(graphic) {
          if (graphic.symbol != null) {
            graphic.symbol.setColor(new esriColor([parseInt(Math.random() * 255, 10), parseInt(Math.random() * 255, 10), parseInt(Math.random() * 255, 10), 0.5]));
            console.log(graphic);
          }
        });
        map.graphics.refresh();
      } catch (err) {
        console.log(err);
      }
    });
    toolbar.on("draw-end", addToMap);

    // set up event listener to trigger the "draw-begin" event
    onDrawBegin = dojoOn.pausable(map, "mouse-down", function() {
      toolbar.emit("draw-begin");
      // test if you can pause the onDrawBegin after the event is called.
      if (onDrawBegin && typeof onDrawBegin.pause === "function") {
        onDrawBegin.pause();
      }
    });
    // pause it for now
    onDrawBegin.pause();

    // set up the draw-end event to reactivate onDrawBegin
    toolbar.on("draw-end, activate", function(evt) {
      // resume the onDrawBegin when you touch the map to draw again.
      onDrawBegin.resume();
    });

    /*toolbar.on("activate", function (evt) {
			  // resume the onDrawBegin when you touch the map to draw again.
			  onDrawBegin.resume();
		  });*/

    toolbar.on("deactivate", function(evt) {
      // pause draw event if the draw toolbar is deactivated
      onDrawBegin.pause();
    });
  }

  function addToMap(evt) {
    var symbol;
    map.showZoomSlider();
    switch (evt.geometry.type) {
      case "point":
      case "multipoint":
        symbol = new SimpleMarkerSymbol();
        break;
      case "polyline":
        symbol = new SimpleLineSymbol();
        break;
      default:
        symbol = new SimpleFillSymbol();
        break;
    }
    var graphic = new Graphic(evt.geometry, symbol);
    console.log("Symbol:", symbol);
    console.log("Graphic:", graphic);
    map.graphics.add(graphic);
  }
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console