Project

General

Profile

1
<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: blue;
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='http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js'></script>
18
    <script src="../lib/OpenLayers.js"></script>
19
    <script type="text/javascript">
20
        <!--
21
        var lon = 5;
22
        var lat = 40;
23
        var zoom = 5;
24
        var map, markers;
25
        var barcelona = new OpenLayers.LonLat(2.13134765625,
26
                                              41.37062534198901);
27
        var madrid = new OpenLayers.LonLat(-3.6968994140625,
28
                                              40.428314208984375);
29

    
30
        function init(){
31
            map = new OpenLayers.Map( $('map') );
32

    
33
            var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
34
                      "http://labs.metacarta.com/wms/vmap0", 
35
                      {layers: 'basic'} );
36
            var google = new OpenLayers.Layer.Google( "Google Hybrid" , {type: G_HYBRID_MAP });
37
            var ve = new OpenLayers.Layer.VirtualEarth( "VE"); 
38
            
39

    
40
            map.addLayers([wms, google, ve]);
41

    
42
            markers = new OpenLayers.Layer.Markers("markers");
43
            map.addLayer(markers);
44

    
45
            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
46
            map.addControl( new OpenLayers.Control.LayerSwitcher() );
47

    
48
        }
49
        
50
        function add() {
51
            var url = 'http://boston.openguides.org/markers/AQUA.png';
52
            var sz = new OpenLayers.Size(10, 17);
53
            var calculateOffset = function(size) {
54
                                return new OpenLayers.Pixel(-(size.w/2), -size.h);
55
                             };           
56
            var icon = new OpenLayers.Icon(url, sz, null, calculateOffset);
57
            marker = new OpenLayers.Marker(barcelona, icon);
58
            markers.addMarker(marker);
59

    
60
            marker = new OpenLayers.Marker(madrid, icon.clone());
61
            markers.addMarker(marker);
62

    
63
        }
64

    
65
        function remove() {
66
            markers.removeMarker(marker);
67
        }
68
                
69
    // -->
70

    
71
    </script>
72
  </head>
73
  <body onload="init()">
74
    <h1>OpenLayers With WMS, Google, VE Example</h1>
75
    <div id="map"></div>
76
    <div style="background-color:green" onclick="add()"> click to add a marker to the map</div>
77
    <div style="background-color:red" onclick="remove()"> click to remove the marker from the map</div>
78
  </body>
79
</html>
(1-1/35)