-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdraw.html
194 lines (166 loc) · 9.02 KB
/
draw.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
<meta name="viewport" content="width=device-width,user-scalable=no">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Maps Toolbar</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.7/js/dojo/dijit/themes/nihilo/nihilo.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.7/js/esri/css/esri.css">
<style>
html, body, #mainWindow {
font-family: sans-serif;
height: 100%;
width: 100%;
}
html, body {
margin: 0;
padding: 0;
}
#header {
height: 40px;
overflow: auto;
padding: 0.5em;
}
</style>
<script src="tween.js"></script>
<script>
var dojoConfig = {
paths: { Extension: location.pathname.replace(/\/[^/]+$/, "") + "/Extension" }
};
</script>
<script src="http://js.arcgis.com/3.7/"></script>
<script>
var map, toolbar, symbol, geomTask;
require([
"esri/map", "Extension/DrawEx", "Extension/EditEx", "esri/graphic", "dojo/_base/Color",
"esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",
"dojo/parser", "dijit/registry", "dijit/Menu", "dijit/MenuItem", "dijit/MenuSeparator",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/form/Button", "dojo/domReady!"
], function (
Map, Draw, Edit, Graphic, Color, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, parser, registry, Menu, MenuItem, MenuSeparator
)
{
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.activate(Draw[tool]);
map.hideZoomSlider();
}
function createToolbar(themap)
{
toolbar = new Draw(map);
toolbar.on("draw-end", addToMap);
editToolbar = new Edit(map, null, toolbar);
map.on("click", function (evt)
{
editToolbar.deactivate();
});
createGraphicsMenu();
map.enableSnapping({snapPointSymbol: new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CROSS, 35, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 7), new Color([0, 255, 0, 0.25]))});
}
function addToMap(evt)
{
var symbol;
toolbar.deactivate();
map.showZoomSlider();
switch (evt.geometry.type)
{
case "point":
case "multipoint":
symbol = new SimpleMarkerSymbol();
break;
case "polyline":
symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 116, 217]), 15);
break;
default:
symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol().setWidth(4), new Color([0, 116, 217, 0.41]));
break;
}
var graphic = new Graphic(evt.geometry, symbol);
map.graphics.add(graphic);
}
function createGraphicsMenu()
{
// Creates right-click context menu for GRAPHICS
ctxMenuForGraphics = new Menu({});
ctxMenuForGraphics.addChild(new MenuItem({
label: "编辑节点",
onClick: function ()
{
if (selected.geometry.type !== "point")
{
editToolbar.activate(Edit.EDIT_VERTICES, selected);
}
else
{
alert("Not implemented");
}
}
}));
ctxMenuForGraphics.addChild(new MenuItem({
label: "编辑控制点",
onClick: function ()
{
editToolbar.activate(Edit.MOVE | Edit.ROTATE | Edit.SCALE, selected);
}
}));
ctxMenuForGraphics.addChild(new MenuSeparator());
ctxMenuForGraphics.addChild(new MenuItem({
label: "删除",
onClick: function ()
{
map.graphics.remove(selected);
}
}));
ctxMenuForGraphics.startup();
map.graphics.on("mouse-over", function (evt)
{
// We'll use this "selected" graphic to enable editing tools
// on this graphic when the user click on one of the tools
// listed in the menu.
selected = evt.graphic;
// Let's bind to the graphic underneath the mouse cursor
ctxMenuForGraphics.bindDomNode(evt.graphic.getDojoShape().getNode());
});
map.graphics.on("mouse-out", function (evt)
{
ctxMenuForGraphics.unBindDomNode(evt.graphic.getDojoShape().getNode());
});
}
});
</script>
</head>
<body class="nihilo">
<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'">
<button data-dojo-type="dijit/form/Button">CURVE</button>
<button data-dojo-type="dijit/form/Button">BEZIER CURVE</button>
<button data-dojo-type="dijit/form/Button">BEZIER POLYGON</button>
<button data-dojo-type="dijit/form/Button">FREEHAND ARROW</button>
</div>
<div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"></div>
</div>
</body>
</html>