-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasicMap.html
124 lines (102 loc) · 5.88 KB
/
basicMap.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
<html><head>
<!-- access Openlayers API (OpenStreetMap) -->
<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>
<!-- access Google Maps Layers -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false"></script>
<script>
function adsbMapInit() {
// ----- define the map projections
projLonlat = new OpenLayers.Projection("EPSG:4326");
projMercator = new OpenLayers.Projection("EPSG:900913");
// ----- define some map properties
centerLonlat = new OpenLayers.LonLat(9.300000, 49.200000).transform(projLonlat, projMercator);
baseLonlat = new OpenLayers.LonLat(9.322003, 48.745153).transform(projLonlat, projMercator);
basePoint = new OpenLayers.Geometry.Point(baseLonlat.lon, baseLonlat.lat);
// ----- define some circles around the base station position (in 10 km steps)
baseCircleA = OpenLayers.Geometry.Polygon.createRegularPolygon(basePoint, 25000, 180, 0);
baseCircleB = OpenLayers.Geometry.Polygon.createRegularPolygon(basePoint, 50000, 180, 0);
baseCircleC = OpenLayers.Geometry.Polygon.createRegularPolygon(basePoint, 75000, 180, 0);
baseCircleD = OpenLayers.Geometry.Polygon.createRegularPolygon(basePoint, 100000, 180, 0);
baseCircleE = OpenLayers.Geometry.Polygon.createRegularPolygon(basePoint, 125000, 180, 0);
baseCircleF = OpenLayers.Geometry.Polygon.createRegularPolygon(basePoint, 150000, 180, 0);
baseCircleG = OpenLayers.Geometry.Polygon.createRegularPolygon(basePoint, 175000, 180, 0);
baseCircleH = OpenLayers.Geometry.Polygon.createRegularPolygon(basePoint, 200000, 180, 0);
zoom = 9;
// ----- create a layer for displaying our own static map features
stationLayer = new OpenLayers.Layer.Vector("ADS-B Base Station");
stationCircleA = new OpenLayers.Feature.Vector(baseCircleA, {}, {fill: false, strokeDashstyle: "dot"});
stationCircleB = new OpenLayers.Feature.Vector(baseCircleB, {}, {fill: false, strokeDashstyle: "dot"});
stationCircleC = new OpenLayers.Feature.Vector(baseCircleC, {}, {fill: false, strokeDashstyle: "dot"});
stationCircleD = new OpenLayers.Feature.Vector(baseCircleD, {}, {fill: false, strokeDashstyle: "dot"});
stationCircleE = new OpenLayers.Feature.Vector(baseCircleE, {}, {fill: false, strokeDashstyle: "dot"});
stationCircleF = new OpenLayers.Feature.Vector(baseCircleF, {}, {fill: false, strokeDashstyle: "dot"});
stationCircleG = new OpenLayers.Feature.Vector(baseCircleG, {}, {fill: false, strokeDashstyle: "dot"});
stationCircleH = new OpenLayers.Feature.Vector(baseCircleH, {}, {fill: false, strokeDashstyle: "dot"});
stationPoint = new OpenLayers.Feature.Vector(basePoint, {}, {externalGraphic: "http://localhost:3333/icons/basestation.png",
graphicWidth: 30,
graphicHeight: 30,
graphicTitle:"ADS-B Base Station Esslingen University"});
// ----- add static features to static layer
stationLayer.addFeatures([stationPoint, stationCircleA, stationCircleB, stationCircleC, stationCircleD, stationCircleE, stationCircleF, stationCircleG, stationCircleH]);
// ----- create the map with a number of controls and a scale
map = new OpenLayers.Map("mapdiv", {
theme: null,
numZoomLevels: 16,
units: 'meters',
controls: [ new OpenLayers.Control.OverviewMap(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.ScaleLine({ topOutUnits : "nmi",
bottomOutUnits: "km",
topInUnits: 'nmi',
bottomInUnits: 'km',
maxWidth: '40' }),
] });
// ----- define a url for fetching kml strings
// ----- must be provided by a web server at this uri
// ----- you will probably have to amend this line, depending on your web server url
kmlUrl = "http://localhost:3333/active.kml";
// ----- create a vector layer for displaying the active airplanes as
// ----- kml from http
actAircraftKml = new OpenLayers.Layer.Vector("Active Aircraft KML", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: kmlUrl,
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true,
maxDepth: 2
})
})
});
// ----- create a number of base layers for different, alternative map
// ----- displays (right hand side corner of the map)
layerOSM = new OpenLayers.Layer.OSM("Open Street Map");
layerGop = new OpenLayers.Layer.Google("Google Physical", {type: google.maps.MapTypeId.TERRAIN});
layerGos = new OpenLayers.Layer.Google("Google Streets", {numZoomLevels: 20});
layerGoh = new OpenLayers.Layer.Google("Google Hybrid", {type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20});
layerGsa = new OpenLayers.Layer.Google("Google Satellite", {type:google.maps.MapTypeId.SATELLITE, numZoomLevels: 22});
// ----- add the various layers to the basic map
map.addLayers([layerOSM, layerGop, layerGos, layerGoh, layerGsa, stationLayer, actAircraftKml]);
// finally, center the map around the base station
map.setCenter(centerLonlat, zoom);
// ----- set the kml aircraft layer to be reloaed from http every second
window.setInterval(UpdateKmlLayer, 500, actAircraftKml);
}
function UpdateKmlLayer(layer) {
// this is the update function called every second by window.setInterval()
layer.loaded = false;
layer.setVisibility(true);
layer.refresh({ force: true, params: { 'key': Math.random()} });
}
</script>
</head><html>
<body onload="adsbMapInit();">
<div id="mapdiv"></div>
<script>
</script>
</body>