-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
background_selector_3.7.js
62 lines (54 loc) · 2.5 KB
/
background_selector_3.7.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
lizMap.events.on({
'uicreated':function(evt){
/**
* diff 3.6 -> 3.7 : replace #switcher-baselayer-select by lizmap-base-layers select
* and change lizMap.mainLizmap.state (see below)
*/
function addBaselayerImageSelector(){
var activebl = $('#switcher-baselayer lizmap-base-layers select').val();
var html = '<div id="baselayer-image-selector" class="'+activebl+'" title="Changer le fond de carte">';
html+= ' ';
html+= '</div>';
//$('#map-content').append(html);
if($('#baselayer-image-selector').length == 0){
$('#map-content').append(html);
$('#baselayer-image-selector').tooltip({placement: 'bottom'});
$('#baselayer-image-selector').click(function(){
// Get next baselayer
var nextbl = $('lizmap-base-layers select option:selected').next('option');
if(nextbl.length == 0)
nextbl = $('lizmap-base-layers select option:first');
var nextbl_val = nextbl.attr('value');
// Change baselayer
$('lizmap-base-layers select').val(nextbl_val).change();
//!!!Important Set baselayer in lizMap config
lizMap.mainLizmap.state.baseLayers.selectedBaseLayerName = nextbl_val
// Change background image of next possible
getNextBaselayerImage();
})
getNextBaselayerImage();
}
}
function getNextBaselayerImage(){
var nextbl = $('lizmap-base-layers select option:selected').next('option');
if(nextbl.length == 0)
nextbl = $('lizmap-base-layers select option:first');
var nextbl_text = nextbl.text();
var nextbl_val = nextbl.attr('value');
var cur_image_url = $('#baselayer-image-selector').css('background-image');
var cur_image_spl = cur_image_url.split('/');
cur_image_spl.pop();
var nextbl_image = cur_image_spl.join('/') + '/' + nextbl_val + '.png';
$('#baselayer-image-selector')
.css(
'background-image',
nextbl_image
)
.attr('title', nextbl_text)
.tooltip('fixTitle')
;
}
// Add baselayer image selector
addBaselayerImageSelector();
}
});