-
Notifications
You must be signed in to change notification settings - Fork 1
/
distance2.html
248 lines (222 loc) · 9 KB
/
distance2.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
Calculate Distance 2
</title>
<link rel="stylesheet"
href="css/style.css"
type="text/css">
<link rel="stylesheet"
href="css/style2.css"
type="text/css">
<script type="text/javascript"
src="js/jquery-2.0.3.js">
</script>
<script src="js/OpenLayers.js">
</script>
<script src="js/geodesic.js"
type="text/javascript">
</script>
<script src="js/utils.js"
type="text/javascript">
</script>
<script src="http://maps.google.com/maps/api/js?v=3&sensor=false"></script>
<style>
.smallmap {
width: 1024px;
height: 512px;
border: 1px solid #ccc;
}
</style>
<script type="text/javascript">
var map;
var def_zoom = 15;
var def_lat = 48.76148;
var def_lon = 2.3031;
//var def_lat = 48.72698;
//var def_lon = 2.370448;
//var def_zoom = 12;
var curr_marker = null;
var markerslayer = null;
var markersList = [];
var lineList = [];
// some test images
var images = new Array( "NDB-95x95.gif", "VOR-95x83.gif", "VOR-DME-95x83.gif", "VORTAC-97x85.gif",
"OM.png", "MM.png", "IM.png" );
//var images = new Array( "NDB-95x95.png", "VOR-95x83.png", "VOR-DME-95x83.png", "VORTAC-97x85.png" );
//var images = new Array( "NDB-95x95.png", "NDB-95x95.png", "VOR-DME-95x83.png", "VORTAC-97x85.png" );
var next_image = 0;
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // geographic - WGS-84 (World Geodetic System)
var toProjection = new OpenLayers.Projection("EPSG:3857"); // identical to EPSG:900913? - meters?
var llwsg84;
var got_marker = false;
var total_dist = 0;
var lineLayer;
function init(lat,lon,zoom) {
// map = new OpenLayers.Map('map');
map = new OpenLayers.Map("map", {
projection: new OpenLayers.Projection("EPSG:3857"),
// this sets wgs84/4326 as default for display coords
displayProjection: new OpenLayers.Projection("EPSG:4326")
});
var proj4326 = new OpenLayers.Projection("EPSG:4326");
var projmerc = new OpenLayers.Projection("EPSG:900913");
var layerOSM = new OpenLayers.Layer.OSM(
"OpenStreetMap",
{numZoomLevels: 20} );
var layerGS = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20} );
var layerGH = new OpenLayers.Layer.Google(
"Google Hybrid",
{type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20} );
var layerGSAT = new OpenLayers.Layer.Google(
"Google Satellite",
{type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22} );
//map.addLayers([layerOSM,layerGS,layerGH,layerGSAT]);
map.addLayers([layerGS,layerGH,layerGSAT]);
markerslayer = new OpenLayers.Layer.Markers( "Marker Layer" );
map.addLayer(markerslayer);
// to add line drawing
lineLayer = new OpenLayers.Layer.Vector("Line Layer");
map.addLayer(lineLayer);
// map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.ScaleLine());
map.addControl(new OpenLayers.Control.Permalink('permalink'));
map.addControl(new OpenLayers.Control.LayerSwitcher());
var pos = new OpenLayers.LonLat(lon,lat).transform( proj4326, projmerc );
map.setCenter( pos, zoom );
map.events.register("mousemove", map, function(e) {
var position = this.events.getMousePosition(e);
OpenLayers.Util.getElement("coords").innerHTML = 'MOUSE POSITION '+position;
var lonlat = map.getLonLatFromPixel( this.events.getMousePosition(e) );
// OpenLayers.Util.getElement("lonlatTG").innerHTML = 'lonlat => '+lonlat;
var lonlatTransf = lonlat.transform(map.getProjectionObject(), proj4326);
// OpenLayers.Util.getElement("lonlatTrans").innerHTML = 'lonlatTransf => '+lonlatTransf;
OpenLayers.Util.getElement("lonlatDouble").innerHTML = 'lonlat => '+lonlat;
if (got_marker) {
var dist = getDistance(lonlatTransf.lat, lonlatTransf.lon, llwsg84.lat, llwsg84.lon );
OpenLayers.Util.getElement("distance").innerHTML =
'dist => '+dist+' total => '+(total_dist + dist);
}
});
map.events.register("click", map, function(e) {
var position = this.events.getMousePosition(e);
// var icon = new OpenLayers.Icon('http://maps.google.com/mapfiles/ms/icons/red-pushpin.png');
var img = images[next_image];
// next_image++;
if (next_image >= images.length) next_image = 0;
var icon = new OpenLayers.Icon('img/'+img);
var lonlat = map.getLonLatFromPixel(position);
var lonlatTransf = lonlat.transform(map.getProjectionObject(), proj4326);
// alert ('lonlatTrans=> lat='+lonlatTransf.lat+' lon='+lonlatTransf.lon+'\nlonlat=>'+lonlat+'\nposition=>'+position);
var mlonlat = lonlatTransf.transform(proj4326, map.getProjectionObject());
curr_marker = new OpenLayers.Marker(mlonlat, icon);
markerslayer.addMarker(curr_marker);
markersList.push(curr_marker);
var nxtwsg84 = mlonlat.transform( toProjection, fromProjection );
if (got_marker) {
var lat1 = llwsg84.lat;
var lon1 = llwsg84.lon;
var lat2 = nxtwsg84.lat;
var lon2 = nxtwsg84.lon;
var dist = getDistance( lat1, lon1, lat2, lon2 );
var feat = putBlueLine( lat1, lon1, lat2, lon2 );
lineList.push(feat);
total_dist += dist;
OpenLayers.Util.getElement("distance2").innerHTML = 'dist => '+dist+', total '+total_dist;
}
llwsg84 = nxtwsg84;
OpenLayers.Util.getElement("markerpos").innerHTML = 'markerpos => '+llwsg84;
got_marker = true;
});
}
function paintLine( lat1, lon1, lat2, lon2, style ) {
var points = new Array(
new OpenLayers.Geometry.Point(lon1,lat1).transform( fromProjection, toProjection ),
new OpenLayers.Geometry.Point(lon2,lat2).transform( fromProjection, toProjection )
);
var line = new OpenLayers.Geometry.LineString(points);
var lineFeature = new OpenLayers.Feature.Vector(line, null, style);
lineLayer.addFeatures([lineFeature]);
return lineFeature;
}
function putBlueLine( lat1, lon1, lat2, lon2 ) {
var blue_style = {
strokeColor: '#000080',
strokeOpacity: 0.5,
strokeWidth: 2,
fill: false
};
return paintLine( lat1, lon1, lat2, lon2, blue_style );
}
function deleteAll() {
var i, feat, max;
max = markersList.length;
for (i = 0; i < max; i++) {
feat = markersList[i];
markerslayer.removeMarker(feat);
}
lineLayer.removeAllFeatures();
markersList = [];
lineList = [];
got_marker = false;
total_dist = 0;
// clear the messages
$("#distance2").html("");
$("#markerpos").html("");
$("#coords").html("");
$("#lonlatTG").html("");
$("#lonlatTrans").html("");
$("#lonlatDouble").html("");
$("#distance").html("");
}
</script>
</head>
<body>
<h1 id="title">
Calculate Distance
</h1>
<!-- <div id="tags">coordinate</div> -->
<p>
Click on map to create markers <input type="button"
onclick="javascript:deleteAll();"
value="Delete All!">
</p>
<div id="map"
class="smallmap">
</div>
<div id="markerpos">
</div>
<div id="distance2">
</div>
<div id="coords">
</div>
<div id="lonlatTG">
</div>
<div id="lonlatTrans">
</div>
<div id="lonlatDouble">
</div>
<div id="distance">
</div>
<script type="text/javascript"
defer="defer">
function gup2( name, def ) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return def;
return results[1];
}
var ulat = gup2('lat',def_lat);
var ulon = gup2('lon',def_lon);
var uzoom = gup2('zoom',def_zoom);
init(ulat,ulon,uzoom);
</script>
</body>
</html>