<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Create a Map</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="http://js.arcgis.com/3.10/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">
<style>
html,
body,
#mapDiv {
padding: 0;
margin: 0;
height: 100%;
}
button {
display: block;
}
</style>
<script src="http://js.arcgis.com/3.10/"></script>
<script>
var map, tb;
require([
"esri/map", "esri/toolbars/draw",
"esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol",
"esri/symbols/PictureFillSymbol", "esri/symbols/CartographicLineSymbol",
"esri/graphic", "esri/Color", "dojo/dom", "dojo/on", "dojo/parser",
"dijit/form/Button", "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/form/ComboBox",
"dijit/layout/TabContainer", "dijit/form/NumberSpinner", "dijit/form/TextBox", "dijit/ColorPalette",
"dojo/domReady!"
], function (
Map, Draw,
SimpleMarkerSymbol, SimpleLineSymbol,
PictureFillSymbol, CartographicLineSymbol,
Graphic,
Color, dom, on, parser
) {
parser.parse();
map = new Map("mapDiv", {
basemap: "streets",
center: [-25.312, 34.307],
zoom: 3
});
map.on("load", initToolbar);
map.on("resize", resizeMap);
function initToolbar() {
tb = new Draw(map);
tb.on("draw-end", addToMap);
// event delegation so a click handler is not
// needed for each individual button
on(dom.byId("info"), "click", function(evt) {
if ( evt.target.id === "info" ) {
return;
}
var tool = evt.target.id.toLowerCase();
if(tool == "clear"){
map.graphics.clear();
map.enableMapNavigation();
}else{
map.disableMapNavigation();
tb.activate(tool);
}
});
}
function addToMap(evt) {
//deactivate the toolbar and clear existing graphics
tb.deactivate();
map.enableMapNavigation();
switch (evt.geometry.type) {
case "point":
var font = new esri.symbol.Font();
font.setSize(parseInt(dojo.byId("tsSize").value));
font.setWeight(esri.symbol.Font[dojo.byId("tsWeight").value]);
var symbol = new esri.symbol.TextSymbol();
symbol.setText(dojo.byId("tsText").value);
symbol.setColor(new dojo.Color(dijit.byId("tsColor").value));
symbol.setFont(font);
symbol.setAngle(parseInt(dojo.byId("tsAngle").value));
break;
case "polyline":
var symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1);
break;
case "polygon":
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
break;
case "extent":
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
break;
case "multipoint":
var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND, 20, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0]), 1), new dojo.Color([255, 255, 0, 0.5]));
break;
}
map.graphics.add(new Graphic(evt.geometry, symbol));
}
//Handle resize of browser
function resizeMap() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function () {
map.resize();
map.reposition();
}, 800);
}
});
</script>
</head>
<body class="claro">
<div id="mainWindow" dojotype="dijit.layout.BorderContainer" design="sidebar" gutters="false" style="width:100%; height:100%;">
<div id="mapDiv" dojotype="dijit.layout.ContentPane" region="center" style="margin:5px;">
</div>
<div dojoType="dijit.layout.TabContainer" region="right" style="width:25%;margin:5px;">
<div dojoType="dijit.layout.ContentPane" selected="true" title="Symbol Properties">
<div id="info">
<div>Select a shape then draw on map to add graphic</div>
<button id="Point">Text</button>
<button id="Multipoint">Multipoint</button>
<button id="Line">Line</button>
<button id="Polyline">Polyline</button>
<button id="FreehandPolyline">Freehand Polyline</button>
<button id="Triangle">Triangle</button>
<button id="Extent">Rectangle</button>
<button id="Circle">Circle</button>
<button id="Ellipse">Ellipse</button>
<button id="Polygon">Polygon</button>
<button id="FreehandPolygon">Freehand Polygon</button>
<button id="Clear">Clear Graphics</button>
</div>
<br/>
Enter Text:
<input dojotype="dijit.form.TextBox" value="Text" id="tsText" />
<br />
<br />Color :
<br />
<div dojoType="dijit.ColorPalette" id="tsColor"></div>
<br />
<br />
<br />Angle :
<br />
<input dojoType="dijit.form.NumberSpinner" value="0" constraints="{min:-360,max:360}" id="tsAngle" />
<br>Weight :
<br />
<select id="tsWeight" dojoType="dijit.form.ComboBox" autocomplete="false" value="WEIGHT_NORMAL">
<option selected="selected">WEIGHT_NORMAL</option>
<option>WEIGHT_BOLD</option>
<option>WEIGHT_BOLDER</option>
<option>WEIGHT_LIGHTER</option>
</select>
<br />Size :
<br />
<select id="tsSize" dojoType="dijit.form.ComboBox" autocomplete="false" value="14pt">
<option>10pt</option>
<option>12pt</option>
<option selected="selected">14pt</option>
<option>16pt</option>
<option>18pt</option>
<option>20pt</option>
<option>22pt</option>
<option>24pt</option>
<option>26pt</option>
<option>28pt</option>
<option>30pt</option>
</select>
</div>
</div>
</body>
</html>