source:
trunk/workshop-routing-foss4g/web/GeoExt/examples/popup.js
@
80
Revision 76, 2.3 KB checked in by djay, 13 years ago (diff) | |
---|---|
|
Line | |
---|---|
1 | /** |
2 | * Copyright (c) 2008-2010 The Open Source Geospatial Foundation |
3 | * |
4 | * Published under the BSD license. |
5 | * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text |
6 | * of the license. |
7 | */ |
8 | |
9 | /** api: example[popup] |
10 | * Feature Popup |
11 | * ------------- |
12 | * Display a popup with feature information. |
13 | */ |
14 | |
15 | var mapPanel, popup; |
16 | |
17 | Ext.onReady(function() { |
18 | |
19 | // create a vector layer, add a feature into it |
20 | var vectorLayer = new OpenLayers.Layer.Vector("vector"); |
21 | vectorLayer.addFeatures( |
22 | new OpenLayers.Feature.Vector( |
23 | new OpenLayers.Geometry.Point(-45, 5) |
24 | ) |
25 | ); |
26 | |
27 | // create select feature control |
28 | var selectCtrl = new OpenLayers.Control.SelectFeature(vectorLayer); |
29 | |
30 | // define "createPopup" function |
31 | var bogusMarkup = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."; |
32 | function createPopup(feature) { |
33 | popup = new GeoExt.Popup({ |
34 | title: 'My Popup', |
35 | location: feature, |
36 | width:200, |
37 | html: bogusMarkup, |
38 | maximizable: true, |
39 | collapsible: true |
40 | }); |
41 | // unselect feature when the popup |
42 | // is closed |
43 | popup.on({ |
44 | close: function() { |
45 | if(OpenLayers.Util.indexOf(vectorLayer.selectedFeatures, |
46 | this.feature) > -1) { |
47 | selectCtrl.unselect(this.feature); |
48 | } |
49 | } |
50 | }); |
51 | popup.show(); |
52 | } |
53 | |
54 | // create popup on "featureselected" |
55 | vectorLayer.events.on({ |
56 | featureselected: function(e) { |
57 | createPopup(e.feature); |
58 | } |
59 | }); |
60 | |
61 | // create Ext window including a map panel |
62 | var mapwin = new Ext.Window({ |
63 | layout: "fit", |
64 | title: "Map", |
65 | closeAction: "hide", |
66 | width: 650, |
67 | height: 356, |
68 | x: 50, |
69 | y: 100, |
70 | items: { |
71 | xtype: "gx_mappanel", |
72 | region: "center", |
73 | layers: [ |
74 | new OpenLayers.Layer.WMS( |
75 | "OpenLayers WMS", |
76 | "http://vmap0.tiles.osgeo.org/wms/vmap0", |
77 | {layers: 'basic'} ), |
78 | vectorLayer |
79 | ] |
80 | } |
81 | }); |
82 | mapwin.show(); |
83 | |
84 | mapPanel = mapwin.items.get(0); |
85 | mapPanel.map.addControl(selectCtrl); |
86 | selectCtrl.activate(); |
87 | }); |
Note: See TracBrowser
for help on using the repository browser.