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 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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

āš ļø This feature can only be used by logged in users.

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
šŸ•‘ One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console