-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfeatureInput.html
213 lines (185 loc) · 6.36 KB
/
featureInput.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
<!DOCTYPE html>
<html>
<title>Feature input</title>
<link rel="stylesheet" type="text/css" href="examples.css"/>
<script type="text/javascript" src="https://api.giscloud.com/1/api.js"></script>
<script type="text/javascript" src="examples.js"></script>
<script type="text/javascript">
var viewer, marker, $ = giscloud.exposeJQuery();
mapId = 56913;
lineLayerId = 185290;
polygonLayerId = 185292;
apiKey = "0637f5945eeb535a3c83fb91a11b4fd7";
giscloud.ready(function () {
// set api key
giscloud.apiKey(apiKey);
// create a viewer
viewer = new giscloud.Viewer("mapViewer", mapId, { slider: true });
// bind a handler for the selectionChange event
viewer.selectionChange(onSelectionChanged);
// enable feature selection
viewer.loading.done(function () {
viewer.select(true);
});
});
function setGeomType(type) {
geomType = type;
}
function featureLayer() {
if (geomType === 'line') return lineLayerId;
if (geomType === 'polygon') return polygonLayerId;
}
function featureData() {
return {
data: {
title: $("#title").val() || geomType,
name: $("#name").val(),
message: $("#message").val()
},
__layerId: featureLayer()
};
}
function clearFeatureData() {
$("#ex3 input").val("");
}
function onUpdate() {
giscloud.layers.reset(mapId, [featureLayer()]);
ex(5);
}
function onDrawEnd(graphic) {
var data = featureData(),
feature = new giscloud.Feature(data);
feature.geometry = graphic.geometry().toOGC();
ex(4);
feature.update().done(onUpdate);
}
function onDrawCancel() {
ex(7);
}
function startDrawing() {
viewer.graphic.draw(geomType).then(onDrawEnd, onDrawCancel);
}
function ex(nr, param) {
switch (nr) {
case 1:
$("#ex1").hide("slow");
$("#ex2").show("slow");
break;
case 2:
setGeomType(param);
$("#ex2").hide("slow");
$("#ex3").show("slow");
break;
case 3:
startDrawing();
$("#ex3").hide("slow");
$("#ex4").show("slow");
break;
case 4:
clearFeatureData();
$("#ex4").hide("slow");
$("#ex5").show("slow");
break;
case 5:
$("#ex5").hide("slow");
$("#ex6").show("slow");
break;
case 6:
$("#ex6").hide("slow");
$("#ex1").show("slow");
break;
case 7:
$("#ex4").hide("slow");
$("#ex7").show("slow");
break;
case 8:
$("#ex7").hide("slow");
$("#ex1").show("slow");
break;
}
return false;
}
function markerContent (data) {
var cont = "";
if (data.name) {
cont += data.name + " says: ";
if (data.message) {
cont += data.message;
} else {
cont += "well nothing, really."
}
} else if (data.message) {
cont += data.message;
} else {
cont = "Oh, so peaceful and quiet...";
}
return cont;
}
function displayFeatureData(feature) {
console.log(feature.data);
if (marker) {
viewer.removeMarker(marker);
}
marker = new giscloud.FlagMarker(
feature.bounds.center(),
feature.data.title,
markerContent(feature.data),
giscloud.Color.randomHue(70, 50)
);
viewer.addMarker(marker);
}
function onSelectionChanged(evt) {
if (evt.action === "add") {
// get feature data
giscloud.features.byId(evt.feature.layerId, evt.feature.featureId)
.done(displayFeatureData);
}
}
</script>
<style type="text/css">
.ex {
height: 9em;
vertical-align: middle;
line-height: 2;
}
</style>
<body>
<h1>Features!</h1>
<p>
Try adding some features into the Cloud!
</p>
<p id="cont">
<div id="ex1" class="ex">
<a href="#" onclick="return ex(1);">Begin</a>
</div>
<div id="ex2" class="ex" style="display: none">
Choose your weapon:
<a class="radio" href="#" onclick="return ex(2, 'line');">Line</a>
<a class="radio" href="#" onclick="return ex(2, 'polygon');">Polygon</a>
</div>
<div id="ex3" class="ex" style="display: none">
Set value for these attributes if you want.<br/>
Title: <input id="title"></input>
Name: <input id="name"></input><br/>
Message: <input id="message"></input><br/>
<a href="#" onclick="return ex(3);">Go!</a>
</div>
<div id="ex4" class="ex" style="display: none">
Place your feature on the map. Doubleclick to finish drawing a line. Click on the first point to finish a polygon.</br>
Press <b>Esc</b> to cancel.
</div>
<div id="ex5" class="ex" style="display: none">
Saving feature...
</div>
<div id="ex6" class="ex" style="display: none">
Done!
<a href="#" onclick="return ex(6);">Try this again</a>
</div>
<div id="ex7" class="ex" style="display: none">
Cancelled.
<a href="#" onclick="return ex(8);">Start over</a>
</div>
</p>
<div id="mapViewer"></div>
</body>
</html>