source:
trunk/workshop-routing-foss4g/web/GeoExt/examples/zoom-chooser.js
@
79
Revision 76, 1.9 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[zoom-chooser] |
10 | * Scale Chooser |
11 | * ------------- |
12 | * Use a ComboBox to display available map scales. |
13 | */ |
14 | |
15 | var mapPanel; |
16 | |
17 | Ext.onReady(function() { |
18 | var map = new OpenLayers.Map(); |
19 | var layer = new OpenLayers.Layer.WMS( |
20 | "Global Imagery", |
21 | "http://maps.opengeo.org/geowebcache/service/wms", |
22 | {layers: "bluemarble"} |
23 | ); |
24 | map.addLayer(layer); |
25 | |
26 | var scaleStore = new GeoExt.data.ScaleStore({map: map}); |
27 | var zoomSelector = new Ext.form.ComboBox({ |
28 | store: scaleStore, |
29 | emptyText: "Zoom Level", |
30 | tpl: '<tpl for="."><div class="x-combo-list-item">1 : {[parseInt(values.scale)]}</div></tpl>', |
31 | editable: false, |
32 | triggerAction: 'all', // needed so that the combo box doesn't filter by its current content |
33 | mode: 'local' // keep the combo box from forcing a lot of unneeded data refreshes |
34 | }); |
35 | |
36 | zoomSelector.on('select', |
37 | function(combo, record, index) { |
38 | map.zoomTo(record.data.level); |
39 | }, |
40 | this |
41 | ); |
42 | |
43 | map.events.register('zoomend', this, function() { |
44 | var scale = scaleStore.queryBy(function(record){ |
45 | return this.map.getZoom() == record.data.level; |
46 | }); |
47 | |
48 | if (scale.length > 0) { |
49 | scale = scale.items[0]; |
50 | zoomSelector.setValue("1 : " + parseInt(scale.data.scale)); |
51 | } else { |
52 | if (!zoomSelector.rendered) return; |
53 | zoomSelector.clearValue(); |
54 | } |
55 | }); |
56 | |
57 | mapPanel = new GeoExt.MapPanel({ |
58 | title: "GeoExt MapPanel", |
59 | renderTo: "mappanel", |
60 | height: 400, |
61 | width: 600, |
62 | map: map, |
63 | center: new OpenLayers.LonLat(5, 45), |
64 | zoom: 4, |
65 | bbar: [zoomSelector] |
66 | }); |
67 | }); |
68 |
Note: See TracBrowser
for help on using the repository browser.