-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsimplifier.html
189 lines (161 loc) · 6.15 KB
/
simplifier.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
<!DOCTYPE html>
<html>
<head>
<title>Edit Simplification Factor</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
</head>
<body>
<div class="container-fluid">
<div class="row"><div class="form-group col-md-12">
<label>Hello. This form will let you update the simplification factor of a layer registered in RCS. Some fun facts:</label>
<ul>
<li>Simplification is only relevant to ESRI Feature Layers</li>
<li>Simplification is only relevant to layers with Line and Polygon geometry types</li>
<li>The factor means that any two verticies that are closer than the factor, they will be simplified into one vertice</li>
<li>The unit of the factor is the unit of the spatial reference. It is usually meters.</li>
<li>A factor of 0 will turn off any simplification.</li>
</ul>
</div></div>
<div class="row">
<div class="form-group col-md-4">
<label>Client ID</label>
<input class="form-control" type="text" id="clientId" value="jstest" />
</div>
<div class="form-group col-md-4">
<label>API Key</label>
<input class="form-control" type="text" id="apiKey" value="test_-k" />
</div>
</div>
<div class="row"><div class="form-group col-md-12">
</div></div>
<div class="row">
<div class="form-group col-md-4">
<label>Small Key / URL Argument</label>
<input class="form-control" type="text" id="smallkey" value="0" />
</div>
<div class="form-group col-md-4">
<label>Simplification Factor</label>
<input class="form-control" type="text" id="factor" value="0" />
</div>
<div class="form-group col-md-4">
<label>Submit Simplification</label>
<br/>
<button class="btn btn-default" id='simplifier'>Push Me To Destroy Verticies!</button>
</div>
</div>
<div class="row"><div class="form-group col-md-12">
<textarea id="data" rows=7 class="form-control"></textarea>
</div></div>
<div class="row"><div id="log" class="form-group col-md-12">
</div></div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="cryptojs/rollups/hmac-sha256.js"></script>
<script src="cryptojs/components/core-min.js"></script>
<script src="cryptojs/components/enc-base64-min.js"></script>
<script>
function testsig() {
var dt = '2007-01-25T12:00:00Z';
var psk = 'test';
var cid = '1';
var rqpath = '/register/22';
var rqbody = '{"a":1}';
var sig = sign( psk, rqpath, cid, dt, rqbody );
console.log( sig );
}
function sign( key, path, id, isodate, body ) {
var msg = path + id + isodate + body;
log_info( 'msg: '+msg );
log_info( 'key: '+key );
var words = CryptoJS.HmacSHA256(msg,key);
var sig = CryptoJS.enc.Base64.stringify(words)
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '');
log_info( 'HMAC_SHA256(msg,key): '+sig );
return sig;
}
function log_info(s) {
console.log(s);
$('#log').prepend('<p class="bg-info"><em class="text-muted">'+(new Date()).toISOString()+'</em> '+s+'</p>');
}
function log_err(s) {
console.log(s);
$('#log').prepend('<p class="bg-danger"><em class="text-muted">'+(new Date()).toISOString()+'</em> '+s+'</p>');
}
function get_reg_url(ver) {
return '/' + $('[name=ver]:checked').val() + '/register/' + $('#smallkey').val();
}
function get_update_url(ver) {
return '/' + $('[name=ver]:checked').val() + '/update/' + $('#smallkey').val();
}
//generate a payload for simplification
function make_payload() {
return '{"user": "' + $('#clientId').val() + '", "factor": ' + $('#factor').val() + '}';
/*
var ret = {};
ret.user = $('#clientId').val();
ret.factor = $('#factor').val();
return ret;
*/
}
//bundle up the parameters to be encrypted in the signature
function get_sig_params( urlType ) {
var ret = {};
if ( $('#autodate').prop('checked') ) {
$('#dtrefresh').click();
}
ret.isodate = (new Date()).toISOString();
ret.path = '/v1/simplification/' + $('#smallkey').val();
ret.target = '..' + ret.path;
ret.id = $('#clientId').val();
ret.body = make_payload();
ret.key = $('#apiKey').val();
return ret;
}
//generate headers for the request
function make_headers(sig_params,sig) {
return {
Sender: sig_params.id,
TimeStamp: sig_params.isodate,
Authorization: sig
};
}
function make_curl_header_opts( headers ) {
return Object.keys(headers).map( function(v,k) { return '-H "'+v+': '+headers[v]+'"'; } ).join(' ');
}
function get_abs_path( path ) {
var link = document.createElement("a");
link.href = path;
return link.protocol + '//' + link.host + link.pathname;
}
$(document).ready(function () {
//$('#data').val(JSON.stringify(sampleFeature));
//launch the updater
$('#simplifier').click( function() {
var s = get_sig_params(),
sig = sign( s.key, s.path, s.id, s.isodate, s.body ),
h = make_headers(s,sig);
console.log(h);
$.ajax({
type: "PUT",
contentType: "application/json; charset=utf-8",
url: s.path,
data: s.body,
dataType: "text",
headers: h,
}).done(function (data, status, xhr) {
log_info('put done '+xhr.status);
log_info(data);
}).fail(function (err) {
log_err('put failed '+err.status);
log_err(err.responseText);
console.log(err);
});
});
$('#logclear').click( function() { $('#log').html(''); } );
});
</script>
</body>
</html>