]> dev.renevier.net Git - syp.git/blob - openlayers/examples/popups.html
initial commit
[syp.git] / openlayers / examples / popups.html
1 <html xmlns="http://www.w3.org/1999/xhtml">
2   <head>
3     <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
4     <link rel="stylesheet" href="style.css" type="text/css" />
5     <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
6     <script src="../lib/OpenLayers.js"></script>
7     <script type="text/javascript">
8         var map, layer, popup;
9         var markers, feature, marker;
10         
11         function init(){
12             map = new OpenLayers.Map('map');
13             layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
14                 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
15             map.addLayer(layer);
16             layer = new OpenLayers.Layer.Google( "Google" );
17             map.addLayer(layer);
18
19             map.addControl(new OpenLayers.Control.LayerSwitcher());
20             map.zoomToMaxExtent();
21             
22         }
23
24         function changer() {
25             popup.setBackgroundColor("red");
26             popup.setSize(new OpenLayers.Size(100,600));
27 //            popup.moveTo(new OpenLayers.Pixel(120,120));
28 //            popup.setOpacity(.5);
29             popup.setBorder("2px solid");    
30             popup.setContentHTML("High Chickens");            
31         }
32
33         function add() {
34             popup = new OpenLayers.Popup("chicken", 
35                                          new OpenLayers.LonLat(5,40),
36                                          new OpenLayers.Size(200,200),
37                                          "example popup",
38                                          true);
39             popup.closeOnMove = true;
40         
41             map.addPopup(popup);
42         }        
43
44         function addAnchor() {
45             popup = new OpenLayers.Popup.Anchored("chicken", 
46                                          new OpenLayers.LonLat(5,40),
47                                          new OpenLayers.Size(200,200),
48                                          "example popup", true);
49         
50             map.addPopup(popup);
51         }        
52         
53         function addMarker() {
54     
55             markers = new OpenLayers.Layer.Markers("zibo");
56             map.addLayer(markers);
57
58             feature = new OpenLayers.Feature(layer, 
59                                                  new OpenLayers.LonLat(0,0));
60
61
62             marker = feature.createMarker();
63             
64             markers.addMarker(marker);
65             marker.events.register("mousedown", marker, mousedown);
66                                                              
67         }
68         
69         function mousedown(evt) {
70             if (popup == null) {
71                 popup = feature.createPopup(true);
72                 popup.setContentHTML("<div style='background-color:red; width:150;height:100'><a href='http://www.somethingconstructive.net' target='_blank'>click me</a></div>");
73                 popup.setBackgroundColor("yellow");
74                 popup.setOpacity(0.7);
75                 markers.map.addPopup(popup);
76             } else {
77                 popup.toggle();
78                }
79             OpenLayers.Event.stop(evt);
80         }        
81
82         /**
83          * @param {Event} evt
84          */
85         function onPopupMouseDown(evt) {
86             markers.map.removePopup(popup);
87             popup.destroy();
88             popup = null;
89             OpenLayers.Event.stop(evt);
90         }
91
92
93         function destroy() {
94             popup.destroy();
95         }
96
97         function remove() {
98             markers.removeMarker(marker);
99         }
100
101         function removelayer() {
102             layer.destroy();
103 //            map.removeLayer(markers);
104         }
105     </script>
106   </head>
107   <body onload="init()">
108   <h1 id="title">Popup Mayhem</h1>
109
110   <div id="tags">
111   </div>
112   <p id="shortdesc">
113       All kinds of ways to create and interact with Popups.
114   </p>
115
116   <div id="map" class="smallmap"></div>
117     <p>If you open an anchoredbubble and switch to google, it shouldn't crash. If it does, don't release OpenLayers.</p>  
118     <div style="background-color:purple" onclick="add()"> click to add Popup to map</div>
119     <div style="background-color:green" onclick="addMarker()"> click to add a Marker with an AnchoredBubble popup</div>
120     <div style="background-color:blue" onclick="changer()"> click to modify popup's attributes</div>
121     <div style="background-color:red" onclick="remove()"> click to remove the popup from map</div>
122     <div style="background-color:grey" onclick="removelayer()"> click to remove the markers layer</div>
123     <div style="background-color:orange" onclick="alert(marker.onScreen())"> marker.onscreen()?</div>
124     <div style="background-color:yellow" onclick="destroy()"> click to destroy the popup from map</div> 
125     <div id="docs">
126       Detailed description of this example needs to be written.
127    </div>
128   </body>
129 </html>