Project

General

Profile

1 3032 perry
<html xmlns="http://www.w3.org/1999/xhtml">
2
  <head>
3
    <meta http-equiv="imagetoolbar" content="no"> <!--ie image gizmo OFF!-->
4
    <style type="text/css">
5
        #map {
6
            width: 100%;
7
            height: 512px;
8
            border: 1px solid black;
9
            background-color: red;
10
        }
11
    </style>
12
13
    <!-- this gmaps key generated for http://openlayers.org/dev/ -->
14
    <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA9XNhd8q0UdwNC7YSO4YZghSPUCi5aRYVveCcVYxzezM4iaj_gxQ9t-UajFL70jfcpquH5l1IJ-Zyyw'></script>
15
    <!-- Localhost key -->
16
    <!-- <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTS6gjckBmeABOGXIUiOiZObZESPg'></script>-->
17
    <script src="../lib/OpenLayers.js"></script>
18
    <script type="text/javascript">
19
        <!--
20
        var lon = 5;
21
        var lat = 40;
22
        var zoom = 5;
23
        var map, layer;
24
25
        function init(){
26
            map = new OpenLayers.Map( $('map') ,
27
            { controls: [new OpenLayers.Control.MouseDefaults()] });
28
29
            var normal = new OpenLayers.Layer.Google( "Google", // );
30
             { minZoomLevel: 3, maxZoomLevel: 8  });
31
            var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: G_SATELLITE_MAP });
32
            var hybrid = new OpenLayers.Layer.Google( "Google Hybrid" , {type: G_HYBRID_MAP });
33
34
35
            map.addLayers([satellite, normal, hybrid]);
36
37
            markers = new OpenLayers.Layer.Markers("markers");
38
            map.addLayer(markers);
39
40
            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
41
            map.addControl( new OpenLayers.Control.LayerSwitcher() );
42
            map.addControl( new OpenLayers.Control.PanZoomBar() );
43
44
        }
45
46
        function add() {
47
48
            var url = 'http://boston.openguides.org/markers/AQUA.png';
49
            var sz = new OpenLayers.Size(10, 17);
50
            var calculateOffset = function(size) {
51
                                return new OpenLayers.Pixel(-(size.w/2), -size.h);
52
                             };
53
            var icon = new OpenLayers.Icon(url, sz, null, calculateOffset);
54
            var barcelona = new OpenLayers.LonLat(2.13134765625,
55
                                                  41.37062534198901);
56
            marker = new OpenLayers.Marker(barcelona, icon);
57
            markers.addMarker(marker);
58
        }
59
60
        function remove() {
61
            markers.removeMarker(marker);
62
        }
63
64
    // -->
65
66
    </script>
67
  </head>
68
  <body onload="init()">
69
    <h1>OpenLayers With Google Layer Example</h1>
70
    <div id="map"></div>
71
    <div style="background-color:green" onclick="add()"> click to add a marker to the map</div>
72
    <div style="background-color:red" onclick="remove()"> click to remove the marker from the map</div>
73
  </body>
74
</html>