This is an automated email from the ASF dual-hosted git repository.
jsorel pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new 962eba9 Portrayal : add MapLayer.opacity property and
MapItem.getEnvelope method
962eba9 is described below
commit 962eba91d27db7794011bf78a3ddc1c48d3dad43
Author: jsorel <[email protected]>
AuthorDate: Tue Jan 19 11:12:53 2021 +0100
Portrayal : add MapLayer.opacity property and MapItem.getEnvelope method
---
.../java/org/apache/sis/portrayal/MapItem.java | 22 ++++++-
.../java/org/apache/sis/portrayal/MapLayer.java | 73 ++++++++++++++++++++--
.../java/org/apache/sis/portrayal/MapLayers.java | 35 +++++++++++
3 files changed, 122 insertions(+), 8 deletions(-)
diff --git
a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapItem.java
b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapItem.java
index c233ab9..c39dbd6 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapItem.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapItem.java
@@ -16,10 +16,13 @@
*/
package org.apache.sis.portrayal;
-import java.util.Map;
+import java.beans.PropertyChangeListener;
import java.util.HashMap;
+import java.util.Map;
import java.util.Objects;
-import java.beans.PropertyChangeListener;
+import java.util.Optional;
+import org.apache.sis.storage.DataStoreException;
+import org.opengis.geometry.Envelope;
import org.opengis.util.InternationalString;
@@ -245,7 +248,7 @@ public abstract class MapItem extends Observable {
* If the given value is different than the previous value, then a change
event
* is sent to all listeners registered for the {@value #VISIBLE_PROPERTY}
property.
*
- * <p>If this item is a {@code MapGroup}, then hiding this group should
hide all components in this group,
+ * <p>If this item is a {@code MapLayers}, then hiding this group should
hide all components in this group,
* but without changing the individual {@value #VISIBLE_PROPERTY} property
of those components.
* Consequently making the group visible again restore each component to
the visibility state
* it has before the group was hidden (assuming those states have not been
changed in other ways).</p>
@@ -261,6 +264,19 @@ public abstract class MapItem extends Observable {
}
/**
+ * Returns the envelope of this {@code MapItem}.
+ * If this instance is a {@code MapLayers} the envelope is the
concatenation of all it's components,
+ * in case of multiple CRS for each MapLayer, the resulting envelope CRS
is unpredictable.
+ * If this instance is a {@code MapLayer} the envelope is the resource
data envelope.
+ *
+ * @return the spatiotemporal extent. May be absent if none or too costly
to compute.
+ * @throws DataStoreException if an error occurred while reading or
computing the envelope.
+ */
+ public Optional<Envelope> getEnvelope() throws DataStoreException {
+ return Optional.empty();
+ }
+
+ /**
* Returns a modifiable map of user properties.
* The content of this map is left to users; Apache SIS does not use it in
any way.
* This map is not thread-safe; synchronization if desired is user
responsibility.
diff --git
a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayer.java
b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayer.java
index a615814..e243e10 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayer.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayer.java
@@ -17,13 +17,17 @@
package org.apache.sis.portrayal;
import java.util.Objects;
-import org.opengis.style.Style;
-import org.opengis.feature.Feature;
-import org.opengis.coverage.Coverage;
+import java.util.Optional;
+import org.apache.sis.storage.Aggregate;
+import org.apache.sis.storage.DataSet;
+import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.Query;
import org.apache.sis.storage.Resource;
-import org.apache.sis.storage.DataSet;
-import org.apache.sis.storage.Aggregate;
+import org.apache.sis.util.ArgumentChecks;
+import org.opengis.coverage.Coverage;
+import org.opengis.feature.Feature;
+import org.opengis.geometry.Envelope;
+import org.opengis.style.Style;
/**
@@ -74,6 +78,15 @@ public class MapLayer extends MapItem {
public static final String STYLE_PROPERTY = "style";
/**
+ * The {@value} property name, used for notifications about changes in map
layer opacity.
+ * The opacity specifies the gloabal opacity of the data to be rendered.
+ *
+ * @see #getOpacity()
+ * @see #setOpacity(double)
+ */
+ public static final String OPACITY_PROPERTY = "opacity";
+
+ /**
* Data to be rendered, or {@code null} if unavailable.
*
* @see #DATA_PROPERTY
@@ -98,6 +111,14 @@ public class MapLayer extends MapItem {
private Style style;
/**
+ * Visual transparency of data, or {@code null} if none.
+ *
+ * @see #OPACITY_PROPERTY
+ * @see #getOpacity()
+ */
+ private double opacity;
+
+ /**
* Constructs an initially empty map layer.
*
* @todo Expect {@code Resource} and {@code Style} in argument, for
discouraging
@@ -198,4 +219,46 @@ public class MapLayer extends MapItem {
firePropertyChange(STYLE_PROPERTY, oldValue, newValue);
}
}
+
+ /**
+ * Returns the global opacity of this layer.
+ * Based on the rendering context this property may be impossible to
implement,
+ * it is therefor recommended to modify the style symbolizer opacity
properties.
+ *
+ * @return opacity between 0.0 and 1.0
+ */
+ public double getOpacity() {
+ return opacity;
+ }
+
+ /**
+ * Sets the global rendering opacity of this layer.
+ *
+ * @param opacity must be betwen 0.0 and 1.0
+ */
+ public void setOpacity(double opacity) {
+ ArgumentChecks.ensureBetween(OPACITY_PROPERTY, 0.0, 1.0, opacity);
+ if (this.opacity != opacity) {
+ double old = this.opacity;
+ this.opacity = opacity;
+ firePropertyChange(OPACITY_PROPERTY, old, opacity);
+ }
+ }
+
+ /**
+ * Returns the envelope of this {@code MapLayer}.
+ * The envelope is the resource data envelope.
+ *
+ * @return the spatiotemporal extent. May be absent if none or too costly
to compute.
+ * @throws DataStoreException if an error occurred while reading or
computing the envelope.
+ */
+ @Override
+ public Optional<Envelope> getEnvelope() throws DataStoreException {
+ Resource data = getData();
+ if (data instanceof DataSet) {
+ return ((DataSet) data).getEnvelope();
+ }
+ return Optional.empty();
+ }
+
}
diff --git
a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayers.java
b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayers.java
index d58303c..09970ba 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayers.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/MapLayers.java
@@ -16,15 +16,20 @@
*/
package org.apache.sis.portrayal;
+import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
+import org.apache.sis.geometry.Envelopes;
import org.apache.sis.geometry.ImmutableEnvelope;
import org.apache.sis.internal.map.ListChangeEvent;
import org.apache.sis.internal.map.NotifiedList;
import org.apache.sis.measure.NumberRange;
import org.apache.sis.storage.DataSet;
+import org.apache.sis.storage.DataStoreException;
import org.opengis.geometry.Envelope;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.TransformException;
/**
@@ -156,4 +161,34 @@ public class MapLayers extends MapItem {
firePropertyChange(AREA_OF_INTEREST_PROPERTY, oldValue, imenv);
}
}
+
+ /**
+ * Returns the envelope of this {@code MapItem}.
+ * If this instance is a {@code MapLayers} the envelope is the
concatenation of all it's components,
+ * in case of multiple CRS for each MapLayer, the resulting envelope CRS
is unpredictable.
+ * If this instance is a {@code MapLayer} the envelope is the resource
data envelope.
+ *
+ * @return the spatiotemporal extent. May be absent if none or too costly
to compute.
+ * @throws DataStoreException if an error occurred while reading or
computing the envelope.
+ */
+ @Override
+ public Optional<Envelope> getEnvelope() throws DataStoreException {
+ List<Envelope> envelopes = new ArrayList<>();
+ for (MapItem i : components) {
+ i.getEnvelope().ifPresent(envelopes::add);
+ }
+
+ switch (envelopes.size()) {
+ case 0 : return Optional.empty();
+ case 1 : return Optional.of(envelopes.get(0));
+ default : {
+ try {
+ return
Optional.ofNullable(Envelopes.union(envelopes.toArray(new
Envelope[envelopes.size()])));
+ } catch (TransformException ex) {
+ throw new DataStoreException(ex.getMessage(), ex);
+ }
+ }
+ }
+ }
+
}