Leser: 14
1
2
3
4
5
6
7
8
9
10
11
12
13
<div id="tree" class="span2">
<fieldset id="layerA">
<label class="radio" for="bild-switch_1">
<input id="bild-switch_1" class="bild-switch_1a" type="radio" name="bilder" value="bild1" onchange="checkedRadioBtn()" checked />Bild1
</label>
<label class="radio" for="bild-switch_2">
<input id="bild-switch_2" class="bild-switch_1a" type="radio" name="bilder" value="Bild2" onchange="checkedRadioBtn()" />Bild2
</label>
<label class="radio" for="bild-switch_3">
<input id="bild-switch_3" class="bild-switch_1a" type="radio" name="bilder" value="Bild3" onchange="checkedRadioBtn()" />Bild3
</label>
</fieldset>
</div>
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
function checkedRadioBtn(){
var newL;
if(document.getElementById("bild-switch_1").checked){
newL = new ol.layer.Image({
source: new ol.source.ImageStatic({
url: 'Bild1.png',
imageSize: [122, 44],
projection: proj,
imageExtent: proj.getExtent()
})
});
}else if(document.getElementById("bild-switch_2").checked){
newL = new ol.layer.Image({
source: new ol.source.ImageStatic({
url: 'Bild2.png',
imageSize: [722, 154],
projection: proj,
imageExtent: proj.getExtent()
})
});
...
map.removeLayer(baseLayer);
map.addLayer(newL);
};
map.getLayersByName(layerName)
map.removeLayer(layer)
1 2 3
var allLayers = map.getLayersByName(layerName); // layerName = Name des gesuchten layers var layer = allLayers[0]; map.removeLayer(layer);
1
2
3
var allLayers = map.getLayersByName(layerName); // layerName = Name des gesuchten layers
var layer = allLayers[0];
map.removeLayer(layer);
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
/************ // Bild : { Objektdaten } "bild-2" : { url: 'Bild2.png', imageSize: [722, 154], projection: proj, imageExtent: proj.getExtent() } *************/ var bilder_switched = { "bild-switch_2" : { url: 'Bild2.png', imageSize: [722, 154], projection: proj, imageExtent: proj.getExtent() }, "bild-switch_1" : { url: 'Bild1.png', imageSize: [122, 44], projection: proj, imageExtent: proj.getExtent() } }; function switchChecked { for key in (bilder_switched) { if(document.getElementById(key).checked){ newL = new ol.layer.Image(bilder_switched[key]); map.removeLayer(baseLayer); map.addLayer(newL); } } }
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
var bilder_switched = {
"bild-switch_2" : {
url: 'Bild2.png',
imageSize: [722, 154],
projection: proj,
imageExtent: proj.getExtent()
},
"bild-switch_1" : {
url: 'Bild1.png',
imageSize: [122, 44],
projection: proj,
imageExtent: proj.getExtent()
},
...//weitere Bilder wurden eingefügt
};
function checkedRadioBtn{
var allLayers = map.getLayers().getArray()[0];
map.removeLayer(allLayers);
for key in (bilder_switched) {
if(document.getElementById(key).checked){
newL = new ol.layer.Image({source: new ol.source.ImageStatic(bilder_switched[key])});
map.addLayer(newL);
}
}
};
1
2
3
<label class="radio" for="bild-switch_1">
<input id="bild-switch_1" class="bild-switch_1a" type="radio" name="bilder" value="bild1" onchange="checkedRadioBtn()" checked />Bild1
</label>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function checkedRadioBtn(){
for(var key in bilder_switched) {
if(document.getElementById(key).checked){
newL = new ol.layer.Image({source: new ol.source.ImageStatic(bilder_switched[key])});
//remove image from map
map.removeLayer(baseLayer);
//get layers and remove marker
var allLayers = map.getLayers().getArray()[0];
map.removeLayer(allLayers);
for(var i = 0; i<icons.length; i++){
map.removeLayer(icons[i]);
}
map.addLayer(newL);
}
}
};
1
2
3
<label class="radio">
<input class="bild-switch_1a" type="radio" name="bilder" value="Bild1" data-image="Bild1.png" onchange="RadioButton('Bild1.png', [733, 152])" checked/>Bild 1
</label>...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function RadioButton(url, size){
newL = new ol.layer.Image({
source: new ol.source.ImageStatic({
url: url,
imageSize: size,
projection: proj,
imageExtent: proj.getExtent()
})
});
map.removeLayer(layer);
var allLayers = map.getLayers().getArray()[0];
map.removeLayer(allLayers);
for(var i = 0; i<icons.length; i++){
map.removeLayer(icons[i]);
}
map.addLayer(newL);
map.updateSize();
};