Good morning,
I want to add a layer selector to my map with openlayers. the selector logo appears correctly but nothing happens when I click on it. I’m looking but I can’t find it, thank you for your help, here is the code:
var map; // Declare the map variable globally to access it in other functions
var vectorSource;
var control;
var orthoLyr;
var planLyr;
var markers;
function initializeMap() {
var osmLyr = new ol.layer.Tile({
source: new ol.source.OSM()
});
orthoLyr = new ol.layer.GeoportalWMTS({
layer: "ORTHOIMAGERY.ORTHOPHOTOS",
olParams: {
opacity: 0.7
}
});
planLyr = new ol.layer.GeoportalWMTS({
layer: "GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2"
});
map = new ol.Map({
target: 'map',
//renderer: 'canvas',
layers: [ planLyr, orthoLyr,osmLyr],
view: new ol.View({
//center: ol.proj.transform([ 2.35 , 48.85], 'EPSG:4326', 'EPSG:3857'),
center: ol.proj.fromLonLat([2.2945, 48.8584]),
zoom: 6
})
});
vectorSource = new ol.source.Vector({format: new ol.format.WKT});
markers = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 1],
src: '#APP_FILES#marker3030.png'
})
})
});
map.addLayer(markers);
control = new ol.control.LayerSwitcher();
map.addControl(control);
}
function styleFunction(feature) {
return [
new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 1],
src: '#APP_FILES#marker3030.png'
}),
text: new ol.style.Text({
font: '30px Calibri',
text: feature.get('name'),
placement: 'line',
fill: new ol.style.Fill({
color: '#000'
}),
stroke: new ol.style.Stroke({
color: '#fff',
width: 3
})
}),
})
];
}
Gp.Services.getConfig({
apiKey: "essentiels",
onSuccess: initializeMap
});
var infoDiv = document.getElementById("info");
infoDiv.innerHTML = "<p> Extension OL version " + Gp.olExtVersion + " (" + Gp.olExtDate + ")</p>";
I want to be able to add the layer selector to modify the transparency, delete/display a layer….