/
POI_08_PivotPoint.html
203 lines (170 loc) · 7.29 KB
/
POI_08_PivotPoint.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
<!DOCTYPE html>
<!--
/*******************************************************************************
# ____ __ __ _ _____ _ _ #
# / __ \ \ \ / / | | / ____| | | | #
# | | | |_ __ ___ _ __ \ /\ / /__| |__ | | __| | ___ | |__ ___ #
# | | | | '_ \ / _ \ '_ \ \/ \/ / _ \ '_ \| | |_ | |/ _ \| '_ \ / _ \ #
# | |__| | |_) | __/ | | \ /\ / __/ |_) | |__| | | (_) | |_) | __/ #
# \____/| .__/ \___|_| |_|\/ \/ \___|_.__/ \_____|_|\___/|_.__/ \___| #
# | | #
# |_| _____ _____ _ __ #
# / ____| __ \| |/ / #
# | (___ | | | | ' / #
# \___ \| | | | < #
# ____) | |__| | . \ #
# |_____/|_____/|_|\_\ #
# #
# (c) 2010-2011 by #
# University of Applied Sciences Northwestern Switzerland #
# Institute of Geomatics Engineering #
# martin.christen@fhnw.ch #
********************************************************************************
* Licensed under MIT License. Read the file LICENSE for more information *
*******************************************************************************/
TUTORIAL 4.8: Setting Pivot Point
*******************************************************************************/
-->
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../../../external/closure-library/closure/goog/base.js"></script>
<script type="text/javascript" src="../../../compiled/deps.js"></script>
<script type="text/javascript">goog.require('owg.OpenWebGlobe');</script>
<script type="text/javascript">
//------------------------------------------------------------------------------
var bycicleLayer;
//------------------------------------------------------------------------------
// Render-Event: called every frame:
function OnRender(context)
{
ogSetTextColor(context, 0,1,0);
ogDrawText(context, "Click middle mouse button to add a POI", 0, 80);
ogDrawText(context, "Press '1' to hide the new POIs",0,50);
ogDrawText(context, "Press '2' to show the hidden POIs",0,20);
}
//------------------------------------------------------------------------------
// Mouse-Down-Event: Called when a mouse button is pressed
function OnMouseDown(context, button, mx, my)
{
// retrieve the scene attached to context:
var scene = ogGetScene(context);
// call the pickglobe function, this gives the result in lng, lat, elv
var result = ogPickGlobe(scene, mx, my);
if (button == 1 && result[0])
{
// place poi:
var NewPoiDefinition =
{
icon : "http://www.openwebglobe.org/data/media/cycling.png",
text : "Position: (" + result[1].toFixed(3) + ", " + result[2].toFixed(3) + ", " + result[3].toFixed(0) + ")",
position : [result[1], result[2], result[3]+2000],
size : 20,
flagpole : true,
centerOnIcon : true,
pivotPoint : [1,0,0]
};
var poi = ogCreatePOI(bycicleLayer,NewPoiDefinition);
}
}
//------------------------------------------------------------------------------
// Key down callback function.
function OnKeyDown(ctx, keycode)
{
if ( keycode == 49) // '1' was pressed
{
//hide the bycicle poi layer
ogHidePOILayer(bycicleLayer);
}
if ( keycode == 50) // '2' was pressed
{
//show the bycicle poi layer
ogShowPOILayer(bycicleLayer);
}
}
//------------------------------------------------------------------------------
function main()
{
// (0) Set location of Artwork directory. Because of CORS this can't be local
// if you want to open this using file://...
ogSetArtworkDirectory("http://www.openwebglobe.org/art/");
// (1) create an OpenWebGlobe context using canvas
// first parameter is canvas-id and second is "fullscreen"
var ctx = ogCreateContextFromCanvas("canvas", true);
// (2) Create a virtual globe
var globe = ogCreateGlobe(ctx);
// (3) Add an image and an elevation layer
var imgBlueMarble500 =
{
url : ["http://www.openwebglobe.org/data/img"],
layer : "World500",
service : "i3d"
};
var elvSRTM_CH =
{
url : ["http://www.openwebglobe.org/data/elv"],
layer : "SRTM",
service : "i3d"
};
ogAddImageLayer(globe, imgBlueMarble500);
ogAddElevationLayer(globe, elvSRTM_CH);
// (4) Set the "Render-Callback" function.
// The callback function will be called everytime a frame is drawn.
ogSetRenderFunction(ctx, OnRender);
// (5) Set the mouse down function. We need this for picking!
ogSetMouseDownFunction(ctx, OnMouseDown);
// (6) Set the key down callback function
ogSetKeyDownFunction(ctx, OnKeyDown);
// (7) Set the background color
ogSetBackgroundColor(ctx, 0.2,0.2,0.7,1);
// (8) Create a POI-Layer
// first, we need to retrieve the scene and the world:
var scene = ogGetScene(ctx);
var world = ogGetWorld(scene);
// Create the poi layer
var poilayer = ogCreatePOILayer(world,"misc");
// (8.1) let's define a poi with text:
var PoiDefinition =
{
text : "Hello World! 世界你好",
position : [7.66, 46.13, 6000],
size : 50,
flagpole : true,
pivotPoint : [0,2,0] // Hover a 1x the text width above the pole
};
// (8.2) then create the POI and add to the scene:
var poi = ogCreatePOI(poilayer, PoiDefinition);
// (8.3) let's create a poi with text and and icon. (text is optional)
var PoiDefinitionWithIcon =
{
text : "Airport",
icon : "http://www.openwebglobe.org/data/media/airport.png",
position : [7.72, 46.71, 2000],
size : 80,
flagpole : true,
pivotPoint : [-1,1,0] // Entire POI to the left of the pole
};
// (8.4) then create and add it to the scene
ogCreatePOI(poilayer, PoiDefinitionWithIcon);
// (8.5) let's create a poi with icon-only. (text is optional)
var PoiDefinitionWithIcon =
{
icon : "http://www.openwebglobe.org/data/media/airport.png",
position : [7.52, 46.71, 2000],
size : 80,
flagpole : true,
pivotPoint : [1,1,0] // Entire POI to the right of the pole
};
// (8.6) then create and add it to the scene
ogCreatePOI(poilayer, PoiDefinitionWithIcon);
// Create another poi layer to place poi's interactive
bycicleLayer = ogCreatePOILayer(world,"byciclelayer");
}
//------------------------------------------------------------------------------
</script>
</head>
<body onload="main()" style="padding:0px; margin:0px; overflow:hidden;">
<div style="text-align: center">
<canvas id="canvas"></canvas>
</div>
</body>
</html>