Skip to content

Commit c01e74a

Browse files
author
David
committed
new sea level example
1 parent 05dd775 commit c01e74a

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

geodata-sea-level/demo.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
var browser = null;
2+
var renderer = null;
3+
var map = null;
4+
var geodata = null;
5+
var seaLevelInput = null;
6+
7+
(function startDemo() {
8+
9+
var params = vtsParseUrlParams();
10+
11+
params['map'] = 'https://cdn.melown.com/mario/store/melown2015/map-config/melown/VTS-Tutorial-map/mapConfig.json';
12+
13+
if(!params['pos']) {
14+
params['position'] = [ 'obj', 13.744257, 45.568033, 'fix', 45.63, 97.36, -37.21, 0.00, 4212.83, 55.00 ];
15+
}
16+
17+
params['positionInUrl'] = true;
18+
//params['mapLoadMode'] = 'fit',
19+
20+
// mapDefaultFont : '../fonts/full-plain/basic.fnt'
21+
// mapDefaultFont : '../fonts/tibet/basic.fnt'
22+
23+
browser = vts.browser('map-div', params);
24+
25+
//check whether browser is supported
26+
if (!browser) {
27+
console.log('Your web browser does not support WebGL');
28+
return;
29+
}
30+
31+
//create new UI panel
32+
//html contetnt is in the form of string
33+
//you can style html elements as usual
34+
var panel = browser.ui.addControl('sealevel-panel',
35+
'<div id="sealevel-div" class="sealevel-div">' +
36+
'<label><b>Sea Level</b></label><br/>' +
37+
'<input id="seaLevelInput" type="number" min="0" max="300" step="5" value="5" size="4">' +
38+
'</div>');
39+
40+
//get destinations-div element
41+
//do not use document.getElementById,
42+
//because element ids are changed to unique ids
43+
seaLevelInput = panel.getElement('seaLevelInput');
44+
45+
//create event listener
46+
//once button state is changed then
47+
//onFlyToNewDestination function is called
48+
seaLevelInput.on('change', onSeaLevelChange);
49+
50+
//callback once is map config loaded
51+
browser.on('map-loaded', onMapLoaded);
52+
})();
53+
54+
55+
//String.prototype.reverse=function(){return this.split("").reverse().join("");}
56+
57+
function onSeaLevelChange() {
58+
59+
var seaLevel = parseInt(seaLevelInput.element.value) + 40
60+
61+
//create geodata object
62+
geodata = map.createGeodata();
63+
64+
geodata.addPolygon3([
65+
66+
[13.5377268, 45.8938275, seaLevel],
67+
[14.0196080, 45.5820852, seaLevel],
68+
[13.6601861, 45.4587160, seaLevel],
69+
[13.3186252, 45.7281240, seaLevel]
70+
],
71+
72+
[],
73+
74+
null,
75+
76+
'fix', { 'radius' : 20 }, 'rip', null, {"tesselate" : { "by-length": 100 } });
77+
78+
geodata.processHeights('node-by-lod', 20, onHeightProcessed);
79+
80+
}
81+
82+
function onMapLoaded() {
83+
map = browser.map;
84+
85+
onSeaLevelChange();
86+
}
87+
88+
function onHeightProcessed() {
89+
var style = {
90+
91+
"layers" : {
92+
"poly" : {
93+
"filter" : ["==", "#type", "polygon"],
94+
95+
"polygon": true,
96+
"polygon-color" : [0,255,255,155],
97+
//"polygon-style": "flatshade",
98+
99+
//"line": true,
100+
//"line-width" : 4,
101+
//"line-color": [255,0,255,255],
102+
103+
//"zbuffer-offset" : [-0.01,0,0]
104+
}
105+
106+
}
107+
};
108+
109+
//make free layer
110+
var freeLayer = geodata.makeFreeLayer(style);
111+
112+
//add free layer to the map
113+
map.removeFreeLayer('sealevel', freeLayer);
114+
map.addFreeLayer('sealevel', freeLayer);
115+
116+
//add free layer to the list of free layers
117+
//which will be rendered on the map
118+
var view = map.getView();
119+
view.freeLayers.sealevel = {};
120+
map.setView(view);
121+
122+
}

geodata-sea-level/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<html>
2+
<head>
3+
<title>VTS Browser - Geodata Basic</title>
4+
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
5+
<link rel="stylesheet" type="text/css" href="../../build/vts-browser.css" />
6+
<script type="text/javascript" src="../../build/vts-browser.js"></script>
7+
<script src="//cdn.melown.com/libs/vtsjs/support/v2/start-browser.js"></script>
8+
</head>
9+
10+
<style>
11+
.sealevel-div {
12+
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
13+
position: absolute;
14+
right: 30px;
15+
bottom: 30px;
16+
background-color: #eee;
17+
padding: 10px 20px;
18+
border-radius: 5px;
19+
border: solid 1px #000;
20+
}
21+
</style>
22+
23+
<body style = "padding: 0; margin: 0;">
24+
<div id="map-div" style="width:100%; height:100%;">
25+
</div>
26+
27+
<script type="text/javascript" src="demo.js"></script>
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)