Added Layer offset manager

This commit is contained in:
Francesco Mangiacrapa 2021-11-12 14:48:12 +01:00
parent 6197d40fae
commit db9ff853bc
2 changed files with 77 additions and 9 deletions

View File

@ -0,0 +1,51 @@
package org.gcube.portlets.user.geoportaldataviewer.client.gis;
import java.util.HashMap;
/**
* The Class LayerOrder.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 12, 2021
*/
public class LayerOrder {
/**
* The Enum LAYER_TYPE.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 12, 2021
*/
public static enum LAYER_TYPE {
BASE_MAP, BASE_WMS, WMS_DETAIL, VECTOR
}
public static final HashMap<LAYER_TYPE, Integer> LAYER_OFFSET = new HashMap<LAYER_TYPE, Integer>(5);
static {
LAYER_OFFSET.put(LAYER_TYPE.BASE_MAP, 0);
LAYER_OFFSET.put(LAYER_TYPE.BASE_WMS, 70);
LAYER_OFFSET.put(LAYER_TYPE.WMS_DETAIL, 140);
LAYER_OFFSET.put(LAYER_TYPE.VECTOR, 210);
}
/**
* Instantiates a new layer order.
*/
public LayerOrder() {
}
/**
* Gets the offset.
*
* @param layerType the layer type
* @return the offset
*/
public Integer getOffset(LAYER_TYPE layerType) {
return LAYER_OFFSET.get(layerType);
}
}

View File

@ -141,7 +141,9 @@ public abstract class OpenLayerOSM {
private LinkedHashMap<String, Image> wmsLayerMap; private LinkedHashMap<String, Image> wmsLayerMap;
private Layer baseLayerTile; private Layer baseLayerTile;
private LayerOrder layerOrder = new LayerOrder();
/** /**
* Instantiates a new open layer OSM. * Instantiates a new open layer OSM.
@ -219,7 +221,8 @@ public abstract class OpenLayerOSM {
//osmSource.setAttributions(baseLayer.getAttribution()); //osmSource.setAttributions(baseLayer.getAttribution());
LayerOptions layerOptions = OLFactory.createOptions(); LayerOptions layerOptions = OLFactory.createOptions();
layerOptions.setSource(osmSource); layerOptions.setSource(osmSource);
layerOptions.setZIndex(0); int zIndex = layerOrder.getOffset(LayerOrder.LAYER_TYPE.BASE_MAP)+1;
layerOptions.setZIndex(zIndex);
baseLayerTile = new Tile(layerOptions); baseLayerTile = new Tile(layerOptions);
break; break;
@ -234,11 +237,13 @@ public abstract class OpenLayerOSM {
LayerOptions layerOptions2 = OLFactory.createOptions(); LayerOptions layerOptions2 = OLFactory.createOptions();
layerOptions2.setSource(xyz); layerOptions2.setSource(xyz);
layerOptions2.setZIndex(0); zIndex = layerOrder.getOffset(LayerOrder.LAYER_TYPE.BASE_MAP)+1;
layerOptions2.setZIndex(zIndex);
baseLayerTile = new Tile(layerOptions2); baseLayerTile = new Tile(layerOptions2);
break; break;
} }
// map == null at init time // map == null at init time
@ -405,6 +410,8 @@ public abstract class OpenLayerOSM {
LayerOptions layerOptions = OLFactory.createOptions(); LayerOptions layerOptions = OLFactory.createOptions();
layerOptions.setSource(imageWMSSource); layerOptions.setSource(imageWMSSource);
// Settings MIN and MAX Resolution // Settings MIN and MAX Resolution
if (layerItem.getMinResolution() != null) { if (layerItem.getMinResolution() != null) {
@ -415,7 +422,8 @@ public abstract class OpenLayerOSM {
} }
Image wmsLayer = new Image(layerOptions); Image wmsLayer = new Image(layerOptions);
int zIndex = layerOrder.getOffset(LayerOrder.LAYER_TYPE.BASE_WMS)+wmsLayerMap.size()+1;
wmsLayer.setZIndex(zIndex);
// visibleLayerItems // visibleLayerItems
map.addLayer(wmsLayer); map.addLayer(wmsLayer);
@ -457,6 +465,9 @@ public abstract class OpenLayerOSM {
LayerOptions layerOptions = OLFactory.createOptions(); LayerOptions layerOptions = OLFactory.createOptions();
layerOptions.setSource(imageWMSSource); layerOptions.setSource(imageWMSSource);
// Settings MIN and MAX Resolution // Settings MIN and MAX Resolution
if (layerItem.getMinResolution() != null) { if (layerItem.getMinResolution() != null) {
layerOptions.setMinResolution(layerItem.getMinResolution()); layerOptions.setMinResolution(layerItem.getMinResolution());
@ -466,7 +477,8 @@ public abstract class OpenLayerOSM {
} }
Image wmsLayer = new Image(layerOptions); Image wmsLayer = new Image(layerOptions);
wmsLayer.setZIndex(wmsDetailsLayerMap.size() + 1); int zIndex = layerOrder.getOffset(LayerOrder.LAYER_TYPE.WMS_DETAIL)+wmsDetailsLayerMap.size() + 1;
wmsLayer.setZIndex(zIndex);
map.addLayer(wmsLayer); map.addLayer(wmsLayer);
wmsDetailsLayerMap.put(key, wmsLayer); wmsDetailsLayerMap.put(key, wmsLayer);
@ -523,9 +535,12 @@ public abstract class OpenLayerOSM {
Vector vectorSource = OLFactory.createVectorSource(); Vector vectorSource = OLFactory.createVectorSource();
vectorSource.addFeature(feature); vectorSource.addFeature(feature);
vectorLayerOptions.setSource(vectorSource); vectorLayerOptions.setSource(vectorSource);
ol.layer.Vector vector = OLFactory.createVector(vectorLayerOptions); ol.layer.Vector vector = OLFactory.createVector(vectorLayerOptions);
int zIndex = layerOrder.getOffset(LayerOrder.LAYER_TYPE.VECTOR)+1;
vector.setZIndex(zIndex);
map.addLayer(vector); map.addLayer(vector);
} }
@ -875,9 +890,11 @@ public abstract class OpenLayerOSM {
Image layer1 = wmsDetailsLayerMap.get(layerSource); Image layer1 = wmsDetailsLayerMap.get(layerSource);
Image layer2 = wmsDetailsLayerMap.get(layerTarget); Image layer2 = wmsDetailsLayerMap.get(layerTarget);
int zIndexS = swapLSource.getPosition() + 1; int zIndexOffset = layerOrder.getOffset(LayerOrder.LAYER_TYPE.WMS_DETAIL);
int zIndexT = swapLTarget.getPosition() + 1; int zIndexS = swapLSource.getPosition() + zIndexOffset + 1;
int zIndexT = swapLTarget.getPosition() + zIndexOffset + 1;
GWT.log("new zindex source: " + zIndexS + ", new zTarget: " + zIndexT); GWT.log("new zindex source: " + zIndexS + ", new zTarget: " + zIndexT);
layer1.setZIndex(zIndexT); layer1.setZIndex(zIndexT);
layer2.setZIndex(zIndexS); layer2.setZIndex(zIndexS);