1{tikimodule error=$module_params.error title=$tpl_module_title name="map_mode_selector" flip=$module_params.flip decorations=$module_params.decorations nobox=$module_params.nobox notitle=$module_params.notitle}
2	<form class="map-mode-selector" method="post" action="">
3		<select name="modeControl">
4		</select>
5	</form>
6	{jq}
7	$('.map-mode-selector').hide();
8	$(function () {
9		$('.map-mode-selector').removeClass('map-mode-selector').each(function () {
10			var map = $(this).closest('.tab, #appframe, body').find('.map-container:first')[0];
11			var modeControl= $(this.modeControl);
12
13			if (! map) {
14				return;
15			}
16
17			$(this).show();
18
19			modeControl.change(function () {
20				if (map.modeManager) {
21					map.modeManager.switchTo($(this).val());
22				}
23			});
24
25			var refreshModes = function () {
26				modeControl.empty();
27				$.each(map.modeManager.modes, function (k, mode) {
28					modeControl.append($('<option/>')
29						.attr('value', mode.name)
30						.text(mode.name)
31						.attr('selected', mode === map.modeManager.activeMode));
32				});
33			};
34
35			$(map).one('initialized', function () {
36				// Wait for OpenLayers to initialize
37				refreshModes();
38
39				$(map).bind('modechanged', refreshModes);
40			});
41		});
42	});
43	{/jq}
44{/tikimodule}
45