1 | <!DOCTYPE HTML>
|
---|
2 | <html>
|
---|
3 |
|
---|
4 | <head>
|
---|
5 | <title>BNC OpenStreetMap View</title>
|
---|
6 | <style type="text/css">
|
---|
7 | html, body, #basicMap {
|
---|
8 | width: 100%;
|
---|
9 | height: 100%;
|
---|
10 | margin: 0;
|
---|
11 | }
|
---|
12 | </style>
|
---|
13 |
|
---|
14 | <script src="https://openlayers.org/api/OpenLayers.js" ></script>
|
---|
15 |
|
---|
16 | <script>
|
---|
17 | var map;
|
---|
18 | var markers;
|
---|
19 | var marker;
|
---|
20 | var icon;
|
---|
21 | var traceIcon;
|
---|
22 | var fromProjection;
|
---|
23 | var toProjection;
|
---|
24 | var dotSize;
|
---|
25 | var dotColor;
|
---|
26 | var zoom;
|
---|
27 |
|
---|
28 | function initialize(lat, lon, mapWinDotSize, mapWinDotColor) {
|
---|
29 | dotSize = mapWinDotSize;
|
---|
30 | dotColor = mapWinDotColor;
|
---|
31 |
|
---|
32 | if (dotSize > 10) dotSize = 10;
|
---|
33 |
|
---|
34 | map = new OpenLayers.Map("basicMap",
|
---|
35 | {controls:[
|
---|
36 | new OpenLayers.Control.Navigation(),
|
---|
37 | new OpenLayers.Control.PanZoomBar()]});
|
---|
38 | fromProjection = new OpenLayers.Projection("EPSG:4326"); // WGS 1984
|
---|
39 | toProjection = new OpenLayers.Projection("EPSG:900913"); // Spherical Mercator
|
---|
40 | zoom = 0;
|
---|
41 |
|
---|
42 | map.addLayer(new OpenLayers.Layer.OSM("OpenStreetMap",
|
---|
43 | // Official OSM tileset as forced HTTPS URLs
|
---|
44 | [ 'https://a.tile.openstreetmap.de/${z}/${x}/${y}.png',
|
---|
45 | 'https://b.tile.openstreetmap.de/${z}/${x}/${y}.png',
|
---|
46 | 'https://c.tile.openstreetmap.de/${z}/${x}/${y}.png'
|
---|
47 | ],{tileOptions : {crossOriginKeyword: null}}));
|
---|
48 | var position = new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection);
|
---|
49 |
|
---|
50 | var size = new OpenLayers.Size(40,40);
|
---|
51 | var offset = new OpenLayers.Pixel(-size.w/2, -size.h/2);
|
---|
52 | icon = new OpenLayers.Icon("qrc:///map/crosshair.png", size, offset);
|
---|
53 |
|
---|
54 | var sizeT = new OpenLayers.Size(dotSize,dotSize);
|
---|
55 | var offsetT = new OpenLayers.Pixel(-sizeT.w/2, -13);
|
---|
56 | if (dotColor == 1) {
|
---|
57 | traceIcon = new OpenLayers.Icon("qrc:///map/reddot.png", sizeT, offsetT);
|
---|
58 | }
|
---|
59 | if (dotColor == 2) {
|
---|
60 | traceIcon = new OpenLayers.Icon("qrc:///map/yellowdot.png", sizeT, offsetT);
|
---|
61 | }
|
---|
62 |
|
---|
63 | markers = new OpenLayers.Layer.Markers("Markers");
|
---|
64 | marker = new OpenLayers.Marker(position, icon);
|
---|
65 | markers.addMarker(marker);
|
---|
66 |
|
---|
67 | map.addLayer(markers);
|
---|
68 |
|
---|
69 | map.setCenter(position, 3);
|
---|
70 | }
|
---|
71 |
|
---|
72 | function gotoLocation(lat, lon) {
|
---|
73 | var position = new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection);
|
---|
74 | if (zoom == 0) {
|
---|
75 | zoom = 15;
|
---|
76 | map.setCenter(position, zoom);
|
---|
77 | }
|
---|
78 | else {
|
---|
79 | map.setCenter(position);
|
---|
80 | }
|
---|
81 | markers.removeMarker(marker);
|
---|
82 | marker = new OpenLayers.Marker(position, icon);
|
---|
83 | markers.addMarker(marker);
|
---|
84 | if (dotSize > 0) {
|
---|
85 | var trace = new OpenLayers.Marker(position, traceIcon.clone());
|
---|
86 | markers.addMarker(trace);
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | </script>
|
---|
91 |
|
---|
92 | </head>
|
---|
93 |
|
---|
94 | <body>
|
---|
95 | <div id="basicMap"></div>
|
---|
96 | </body>
|
---|
97 |
|
---|
98 | </html>
|
---|