-
Notifications
You must be signed in to change notification settings - Fork 0
/
testColor.html
248 lines (210 loc) · 7.75 KB
/
testColor.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Symbol Styler Sample</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.16/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.16/esri/css/esri.css">
</head>
<body class="claro">
<style>
html, body, #map {
background-color: #ccc;
margin: 0;
height: 100%;
}
.options-panel {
font: 14px helvetica, sans-serif;
background-color: #fff;
position: absolute;
right: 292px;
top: 10px;
padding: 10px;
border: 1px solid #544F4F;
z-index: 10000;
}
.options-panel input[type=button] {
background-color: #048bf4;
color: #fff;
font-size: 14px;
border-radius: 2px;
border: 1px solid #048bf4;
box-shadow: #666 1px 1px 1px 1px;
cursor: pointer;
}
.options-panel input[type=button]:active {
background-color: #0494ff;
}
#styler {
position: absolute;
right: 10px;
top: 10px;
border: 1px solid #544F4F;
box-shadow: 2px 2px 4px 1px #5D5858;
}
.esriSimpleSlider {
left: 30px;
}
</style>
<script src="https://js.arcgis.com/3.16/"></script>
<script>
var map;
var styler;
var sampleGraphic;
require([
"dojo/dom",
"dojo/on",
"esri/Color",
"esri/graphic",
"esri/map",
"esri/dijit/SymbolStyler",
"esri/geometry/Extent",
"esri/geometry/Polygon",
"esri/geometry/Polyline",
"esri/styles/basic",
"esri/styles/size",
"esri/styles/type",
"esri/symbols/SimpleFillSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleMarkerSymbol",
"dojo/domReady!"
],
function(
dom, on,
Color, Graphic, Map,
SymbolStyler,
Extent, Polygon, Polyline,
basic, size, type,
SimpleFillSymbol, SimpleLineSymbol, SimpleMarkerSymbol
) {
map = new Map("map", {
basemap: "topo",
center: [-80.7,35.25],
zoom: 10
});
sampleGraphic = new Graphic();
on.once(map, "load", function() {
this.graphics.add(sampleGraphic);
});
//Create instance of SymbolStyler and pass in the domNode
styler = new SymbolStyler({}, "styler");
//Must call startup
styler.startup();
//listen for the dom events
on(dom.byId("symbolTypeSelect"), "change", editSelectedSymbol);
on(dom.byId("applySymbolButton"), "click", applySymbolToGraphic);
on(dom.byId("basemapSelect"), "change", changeBasemap);
editSymbol('simplemarker');
function editSelectedSymbol() {
editSymbol(this.value);
}
function applySymbolToGraphic() {
var geom;
var style = styler.getStyle();
var symbol = style.symbol;
if (symbol.type.indexOf("markersymbol") > -1) {
geom = map.extent.getCenter();
}
if (symbol.type.indexOf("fillsymbol") > -1) {
geom = Polygon.fromExtent(map.extent);
}
if (symbol.type.indexOf("linesymbol") > -1) {
geom = new Polyline({
paths: Polygon.fromExtent(map.extent).rings,
spatialReference: map.spatialReference
});
}
//storeColors is required
styler.storeColors();
sampleGraphic.setGeometry(geom);
sampleGraphic.setSymbol(symbol);
sampleGraphic.draw();
}
function changeBasemap() {
map.setBasemap(this.value);
}
function editSymbol(symbolType) {
var symbol = createSymbol(symbolType);
styler.edit(symbol, getStylerOptions(symbol));
}
function getStylerOptions(symbol) {
var basemap = dom.byId("basemapSelect").value;
var style = dom.byId("style").value;
var styleModule = style === "size" ? size :
style === "type" ? type :
basic;
return {
schemes: styleModule.getSchemes({
theme: "default",
basemap: basemap,
geometryType: getGeometryType(symbol)
})
}
}
function createSymbol(type) {
var SFS = SimpleFillSymbol,
SLS = SimpleLineSymbol,
SMS = SimpleMarkerSymbol;
if (type === "simplefill") {
return new SFS("solid", createSymbol("simpleline"), randomColor());
}
if (type === "simpleline") {
return new SLS("solid", randomColor(), randomNum(50));
}
return new SMS("circle", randomNum(200), createSymbol("simpleline"), randomColor());
}
function getGeometryType(symbol) {
var type = symbol.type;
return type === "picturefillsymbol" || type === "simplefillsymbol" ? "polygon" :
type === "cartographiclinesymbol" || type === "simplelinesymbol" ? "line" :
"point";
}
function randomColor() {
return new Color([
randomNum(255),
randomNum(255),
randomNum(255),
randomNum(1)
]);
}
function randomNum(max) {
var num = Math.random() * max;
return max > 1 ? Math.ceil(num) : num;
}
});
</script>
<div id="map"></div>
<div id="editor">
<div id="styler"></div>
</div>
<div class="options-panel">
<h5>Symbol Type</h5>
<select id="symbolTypeSelect">
<option value="simplemarker" selected>Simple Marker</option>
<option value="simpleline">Simple Line</option>
<option value="simplefill">Simple Fill</option>
</select>
<h5>Basemap</h5>
<select id="basemapSelect">
<option value="topo" selected>Topo</option>
<option value="gray">Gray</option>
<option value="dark-gray">Dark Gray</option>
<option value="oceans">Oceans</option>
<option value="national-geographic">NatGeo</option>
<option value="streets">Streets</option>
<option value="satellite">Satellite</option>
<option value="hybrid">Hybrid</option>
<option value="terrain">Terrain</option>
</select>
<h5>Style</h5>
<select id="style">
<option value="basic" selected>Basic</option>
<option value="size">Size</option>
<option value="type">Type</option>
</select>
<br/>
<br/>
<input id="applySymbolButton" type="button" value="Apply symbol">
</div>
</body>
</html>