| 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="http://openlayers.org/api/OpenLayers.js" ></script>
|
|---|
| 15 |
|
|---|
| 16 | <script>
|
|---|
| 17 | var map;
|
|---|
| 18 | var markers;
|
|---|
| 19 | var marker;
|
|---|
| 20 | var icon;
|
|---|
| 21 | var fromProjection;
|
|---|
| 22 | var toProjection;
|
|---|
| 23 |
|
|---|
| 24 | function initialize(lat, lon) {
|
|---|
| 25 | map = new OpenLayers.Map("basicMap",
|
|---|
| 26 | {controls:[
|
|---|
| 27 | new OpenLayers.Control.Navigation(),
|
|---|
| 28 | new OpenLayers.Control.PanZoomBar()]});
|
|---|
| 29 | fromProjection = new OpenLayers.Projection("EPSG:4326"); // WGS 1984
|
|---|
| 30 | toProjection = new OpenLayers.Projection("EPSG:900913"); // Spherical Mercator
|
|---|
| 31 |
|
|---|
| 32 | var mapnik = new OpenLayers.Layer.OSM();
|
|---|
| 33 | var position = new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection);
|
|---|
| 34 | var zoom = 15;
|
|---|
| 35 |
|
|---|
| 36 | map.addLayer(mapnik);
|
|---|
| 37 |
|
|---|
| 38 | var size = new OpenLayers.Size(40,40);
|
|---|
| 39 | var offset = new OpenLayers.Pixel(-size.w/2, -size.h/2);
|
|---|
| 40 |
|
|---|
| 41 | icon = new OpenLayers.Icon("qrc:///map/crosshair.png", size, offset);
|
|---|
| 42 | markers = new OpenLayers.Layer.Markers("Markers");
|
|---|
| 43 | marker = new OpenLayers.Marker(position, icon);
|
|---|
| 44 | markers.addMarker(marker);
|
|---|
| 45 |
|
|---|
| 46 | map.addLayer(markers);
|
|---|
| 47 |
|
|---|
| 48 | map.setCenter(position, zoom);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | function gotoLocation(lat, lon) {
|
|---|
| 52 | var position = new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection);
|
|---|
| 53 | map.setCenter(position);
|
|---|
| 54 | markers.removeMarker(marker);
|
|---|
| 55 | marker = new OpenLayers.Marker(position, icon);
|
|---|
| 56 | markers.addMarker(marker);
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | </script>
|
|---|
| 60 |
|
|---|
| 61 | </head>
|
|---|
| 62 |
|
|---|
| 63 | <body>
|
|---|
| 64 | <div id="basicMap"></div>
|
|---|
| 65 | </body>
|
|---|
| 66 |
|
|---|
| 67 | </html>
|
|---|