Skip to content

Commit

Permalink
Remove legacy OL2 baselayers code (#3812)
Browse files Browse the repository at this point in the history
Keep OL2 baselayer but hide it as there are still dependencies elsewhere in code
  • Loading branch information
nboisteault authored Jul 28, 2023
1 parent 68ab410 commit 1886fc3
Show file tree
Hide file tree
Showing 4 changed files with 599 additions and 50 deletions.
46 changes: 3 additions & 43 deletions assets/src/legacy/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1819,26 +1819,16 @@ window.lizMap = function() {

// get the baselayer select content
// and adding baselayers to the map
var select = [];
baselayers.reverse();
for (var i=0,len=baselayers.length; i<len; i++) {
var baselayer = baselayers[i]
for (const baselayer of baselayers) {
baselayer.units = projection.proj.units;
// Update singleTile layers
if( removeSingleTile && (baselayer instanceof OpenLayers.Layer.WMS) && baselayer.singleTile ) {
baselayer.addOptions({singleTile:false, tileSize: replaceSingleTileSize});
}
try{ // because google maps layer can be created but not added
map.addLayer(baselayer);
var qgisName = baselayer.name;
if ( baselayer.name in cleanNameMap )
qgisName = getLayerNameByCleanName(baselayer.name);
var blConfig = config.layers[qgisName];
if (blConfig)
select += '<option value="'+baselayer.name+'">'+blConfig.title+'</option>';
else
select += '<option value="'+baselayer.name+'">'+baselayer.name+'</option>';

map.baseLayer.setVisibility(false);
} catch(e) {
var qgisName = baselayer.name;
if ( baselayer.name in cleanNameMap )
Expand All @@ -1847,37 +1837,7 @@ window.lizMap = function() {
}
}

if (baselayers.length!=0) {
// active the select element for baselayers
$('#switcher-baselayer-select').append(select);
$('#switcher-baselayer-select')
.change(function() {
var val = $(this).val();
var blName = map.getLayersByName(val)[0];
map.setBaseLayer( blName );

// Trigger event
lizMap.events.triggerEvent("lizmapbaselayerchanged",
{ 'layer': blName}
);

$(this).blur();
});
// Hide switcher-baselayer if only one base layer inside
if (baselayers.length==1){
$('#switcher-baselayer').hide();
}
else if ( 'startupBaselayer' in config.options ) {
var startupBaselayer = config.options['startupBaselayer'];
if ( startupBaselayer in startupBaselayersReplacement )
startupBaselayer = startupBaselayersReplacement[startupBaselayer];
else if ( startupBaselayer in config.layers )
startupBaselayer = cleanName(startupBaselayer);

if ( $('#switcher-baselayer-select option[value="'+startupBaselayer+'"]').length != 0)
$('#switcher-baselayer-select').val(startupBaselayer).change();
}
} else {
if (baselayers.length === 0) {
// hide elements for baselayers
map.addLayer(new OpenLayers.Layer.Vector('baselayer',{
maxExtent:map.maxExtent
Expand Down
2 changes: 1 addition & 1 deletion tests/end2end/playwright/base-layers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.describe('Base layers', () => {
});

test('Base layers list', async ({ page }) => {
await expect(page.locator('lizmap-base-layers select option')).toHaveCount(11);
await expect(page.locator('lizmap-base-layers select option')).toHaveCount(12);
await expect(page.locator('lizmap-base-layers select')).toHaveValue('osm-mapnik');
await page.locator('lizmap-base-layers select').selectOption('empty');
await expect(page.locator('lizmap-base-layers select')).toHaveValue('empty');
Expand Down
Loading

0 comments on commit 1886fc3

Please sign in to comment.