forked from playsign/fidemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
346 lines (308 loc) · 8.98 KB
/
Copy pathmain.js
File metadata and controls
346 lines (308 loc) · 8.98 KB
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// Init WebTundra
// note: WebTundra ships with three r62 but it picks up the later included r69 from vizi.js!
try
{
var client = tundra.createWebTundraClient({
container : "#webtundra-container",
renderSystem : ThreeJsRenderer,
asset : {
localStoragePath : "build/webtundra"
},
taskbar : false,
console : false
});
var freecamera = undefined;
var demoapp = undefined;
// Free camera application
$.getScript("build/webtundra/application/freecamera.js")
.done(function(script, textStatus) {
freecamera = new FreeCameraApplication();
})
.fail(function(jqxhr, settings, exception) {
console.error(exception);
}
);
// Fiware demo application
$.getScript("js/client/tundra-client.js")
.done(function(script, textStatus) {
demoapp = new FiwareDemo();
})
.fail(function(jqxhr, settings, exception) {
console.error(exception);
}
);
}
catch(e)
{
console.error("WebTundra initialization failed");
console.error(e.stack);
}
//Three.JS Scene & Renderer to be passed to Vizi
//this way nothing shows - just WT's empty scene, not sure why yet
/*threejs = {
scene: TundraSDK.framework.renderer.scene,
renderer: TundraSDK.framework.renderer.renderer
}*/
//creating the scene here - that's perhaps nicest anyway, can pass it to WT then too
function createScene() {
var scene = new THREE.Scene();
// TODO: Fog distance should be an option
//scene.fog = new THREE.Fog(self.options.fogColour, 1, 15000);
// TODO: Make this more customisable, perhaps as a "day/night" option
// - I'm sure people would want to add their own lighting too
// TODO: Should this even be in here?
var directionalLight = new THREE.DirectionalLight( 0x999999 );
directionalLight.intesity = 0.1;
directionalLight.position.x = 1;
directionalLight.position.y = 1;
directionalLight.position.z = 1;
scene.add(directionalLight);
var directionalLight2 = new THREE.DirectionalLight( 0x999999 );
directionalLight2.intesity = 0.1;
directionalLight2.position.x = -1;
directionalLight2.position.y = 1;
directionalLight2.position.z = -1;
scene.add(directionalLight2);
return scene;
}
function createRenderer(viewport, scene) {
var renderer;
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
//renderer.setClearColor(scene.fog.color, 1);
// Gamma settings make things look 'nicer' for some reason
renderer.gammaInput = true;
renderer.gammaOutput = true;
viewport.appendChild(renderer.domElement);
return renderer;
}
var viewport = document.querySelector("#vizicities-viewport");
var scene = createScene();
var renderer = createRenderer(viewport, scene);
threejs = {
scene: scene,
renderer: renderer
}
var world = new VIZI.World({
viewport: viewport,
// center: new VIZI.LatLon(40.01000594412381, -105.2727379358738) // Collada
// center: new VIZI.LatLon(65.0164696, 25.479259499999998) // Oulu
// center: new VIZI.LatLon(43.47195, -3.79909) // Santander
// center: new VIZI.LatLon(43.462051, -3.800011) // Santander2
center: new VIZI.LatLon(60.17096119799872, 24.94066956044796), // Helsinki
threejs: threejs
});
var controls = new VIZI.ControlsMap(world.camera);
var mapConfig = {
input: {
type: "BlueprintInputMapTiles",
options: {
// tilePath: "https://a.tiles.mapbox.com/v3/examples.map-i86l3621/{z}/{x}/{y}@2x.png" // default
tilePath: "https://a.tiles.mapbox.com/v4/tapanij.kai3hkpp/{z}/{x}/{y}@2x.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6IlhHVkZmaW8ifQ.hAMX5hSW-QnTeRCMAy9A8Q&update=i2x0h" // tapanij custom
}
},
output: {
type: "BlueprintOutputImageTiles",
options: {
grids: [{
zoom: 19,
tilesPerDirection: 3,
cullZoom: 17
}, {
zoom: 18,
tilesPerDirection: 3,
cullZoom: 16
}, {
zoom: 17,
tilesPerDirection: 3,
cullZoom: 15
}, {
zoom: 16,
tilesPerDirection: 3,
cullZoom: 14
}, {
zoom: 15,
tilesPerDirection: 3,
cullZoom: 13
}, {
zoom: 14,
tilesPerDirection: 3,
cullZoom: 12
}, {
zoom: 13,
tilesPerDirection: 5,
cullZoom: 11
}]
}
},
triggers: [{
triggerObject: "output",
triggerName: "initialised",
triggerArguments: ["tiles"],
actionObject: "input",
actionName: "requestTiles",
actionArguments: ["tiles"],
actionOutput: {
tiles: "tiles" // actionArg: triggerArg
}
}, {
triggerObject: "output",
triggerName: "gridUpdated",
triggerArguments: ["tiles"],
actionObject: "input",
actionName: "requestTiles",
actionArguments: ["tiles"],
actionOutput: {
tiles: "tiles" // actionArg: triggerArg
}
}, {
triggerObject: "input",
triggerName: "tileReceived",
triggerArguments: ["image", "tile"],
actionObject: "output",
actionName: "outputImageTile",
actionArguments: ["image", "tile"],
actionOutput: {
image: "image", // actionArg: triggerArg
tile: "tile"
}
}]
};
var switchboardMap = new VIZI.BlueprintSwitchboard(mapConfig);
switchboardMap.addToWorld(world);
var buildingsConfig = {
input: {
type: "BlueprintInputGeoJSON",
options: {
tilePath: "http://vector.mapzen.com/osm/buildings/{z}/{x}/{y}.json"
}
},
output: {
type: "BlueprintOutputBuildingTiles",
options: {
grids: [{
zoom: 15,
tilesPerDirection: 1,
cullZoom: 13
}],
workerURL: "build/vizicities/vizi-worker.min.js"
}
},
triggers: [{
triggerObject: "output",
triggerName: "initialised",
triggerArguments: ["tiles"],
actionObject: "input",
actionName: "requestTiles",
actionArguments: ["tiles"],
actionOutput: {
tiles: "tiles" // actionArg: triggerArg
}
}, {
triggerObject: "output",
triggerName: "gridUpdated",
triggerArguments: ["tiles"],
actionObject: "input",
actionName: "requestTiles",
actionArguments: ["tiles"],
actionOutput: {
tiles: "tiles" // actionArg: triggerArg
}
}, {
triggerObject: "input",
triggerName: "tileReceived",
triggerArguments: ["geoJSON", "tile"],
actionObject: "output",
actionName: "outputBuildingTile",
actionArguments: ["buildings", "tile"],
actionOutput: {
buildings: {
process: "map",
itemsObject: "geoJSON",
itemsProperties: "features",
transformation: {
outline: "geometry.coordinates",
height: "properties.height"
}
},
tile: "tile"
}
}]
};
var switchboardBuildings = new VIZI.BlueprintSwitchboard(buildingsConfig);
switchboardBuildings.addToWorld(world);
var choroplethConfig = {
input: {
type: "BlueprintInputGeoJSON",
options: {
path: "./data/sample.geojson"
}
},
output: {
type: "BlueprintOutputChoropleth",
options: {
colourRange: ["#ffffe5","#f7fcb9","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#006837","#004529"],
layer: 100
}
},
triggers: [{
triggerObject: "output",
triggerName: "initialised",
triggerArguments: [],
actionObject: "input",
actionName: "requestData",
actionArguments: [],
actionOutput: {}
}, {
triggerObject: "input",
triggerName: "dataReceived",
triggerArguments: ["geoJSON"],
actionObject: "output",
actionName: "outputChoropleth",
actionArguments: ["data"],
actionOutput: {
data: {
// Loop through each item in trigger.geoJSON and return a new array of processed values (a map)
process: "map",
itemsObject: "geoJSON",
itemsProperties: "features",
// Return a new object for each item with the given properties
transformation: {
outline: "geometry.coordinates[0]",
value: "properties.POPDEN"
}
}
}
}]
};
var switchboardChoropleth = new VIZI.BlueprintSwitchboard(choroplethConfig);
switchboardChoropleth.addToWorld(world);
debugObject(60.17096119799872, 24.94066956044796); //Helsinki start center
debugObject(60.170040, 24.936350); //Lasipalatsinaukion tötsä
debugObject(60.171680, 24.943881); //Rautatientorin patsas
//lights
function addLights(scene) {
var directionalLight = new THREE.DirectionalLight( 0x999999 );
directionalLight.intesity = 0.1;
directionalLight.position.x = 1;
directionalLight.position.y = 1;
directionalLight.position.z = 1;
scene.add(directionalLight);
var directionalLight2 = new THREE.DirectionalLight( 0x999999 );
directionalLight2.intesity = 0.1;
directionalLight2.position.x = -1;
directionalLight2.position.y = 1;
directionalLight2.position.z = -1;
scene.add(directionalLight2);
}
addLights(world.scene.scene);
var clock = new VIZI.Clock();
var update = function() {
var delta = clock.getDelta();
world.onTick(delta);
world.render();
window.requestAnimationFrame(update);
};
update();