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: 512px;
7
            height: 512px;
8
            border: 1px solid black;
9
        }
10
    </style>
11
    <script src="../lib/OpenLayers.js"></script>
12
    <script type="text/javascript">
13
        <!--
14
        var map, layer, popup;
15
        var markers, feature, marker;
16
        
17
        function init(){
18
            map = new OpenLayers.Map('map');
19
            layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
20
                "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
21
            map.addLayer(layer);
22

    
23
            map.addControl(new OpenLayers.Control.LayerSwitcher());
24
            map.zoomToMaxExtent();
25
        }
26
        
27
        function changer() {
28
            popup.setBackgroundColor("red");
29
            popup.setSize(new OpenLayers.Size(100,600));
30
//            popup.moveTo(new OpenLayers.Pixel(120,120));
31
//            popup.setOpacity(.5);
32
            popup.setBorder("2px solid");    
33
            popup.setContentHTML("High Chickens");            
34
        }
35

    
36
        function add() {
37
            popup = new OpenLayers.Popup("chicken", 
38
                                         new OpenLayers.LonLat(5,40),
39
                                         new OpenLayers.Size(200,200),
40
                                         "example popup");
41
        
42
            map.addPopup(popup);
43
        }        
44

    
45
        function addAnchor() {
46
            popup = new OpenLayers.Popup.Anchored("chicken", 
47
                                         new OpenLayers.LonLat(5,40),
48
                                         new OpenLayers.Size(200,200),
49
                                         "example popup");
50
        
51
            map.addPopup(popup);
52
        }        
53
        
54
        function addMarker() {
55
    
56
            markers = new OpenLayers.Layer.Markers("zibo");
57
            map.addLayer(markers);
58

    
59
            feature = new OpenLayers.Feature(layer, 
60
                                                 new OpenLayers.LonLat(0,0));
61

    
62

    
63
            marker = feature.createMarker();
64
            
65
            markers.addMarker(marker);
66
            marker.events.register("mousedown", marker, mousedown);
67
                                                             
68
        }
69
        
70
        function mousedown(evt) {
71
            if (popup == null) {
72
                popup = feature.createPopup();
73
                popup.setBackgroundColor("yellow");
74
                popup.setOpacity(0.7);
75
                popup.events.register("mousedown", popup, onPopupMouseDown);
76
                markers.map.addPopup(popup);
77
            } else {
78
                markers.map.removePopup(popup);
79
                popup.destroy();
80
                popup = null;
81
            }
82
            Event.stop(evt);
83
        }        
84

    
85
        /**
86
         * @param {Event} evt
87
         */
88
        function onPopupMouseDown(evt) {
89
            markers.map.removePopup(popup);
90
            popup.destroy();
91
            popup = null;
92
            Event.stop(evt);
93
        }
94

    
95

    
96
        function destroy() {
97
            popup.destroy();
98
        }
99

    
100
        function remove() {
101
            markers.removeMarker(marker);
102
        }
103

    
104
        function removelayer() {
105
            layer.destroy();
106
//            map.removeLayer(markers);
107
        }
108

    
109

    
110
        // -->
111
    </script>
112
  </head>
113
  <body onload="init()">
114
    <div id="map"></div>
115
    <div style="background-color:purple" onclick="add()"> click to add Popup to map</div>
116
    <div style="background-color:green" onclick="addMarker()"> click to add a Marker with an AnchoredBubble popup</div>
117
    <div style="background-color:blue" onclick="changer()"> click to modify popup's attributes</div>
118
    <div style="background-color:red" onclick="remove()"> click to remove the popup from map</div>
119
    <div style="background-color:grey" onclick="removelayer()"> click to remove the markers layer</div>
120
    <div style="background-color:orange" onclick="alert(marker.onScreen())"> marker.onscreen()?</div>
121
    <div style="background-color:yellow" onclick="destroy()"> click to destroy the popup from map</div>
122
  </body>
123
</html>
(21-21/35)