view artifacts/src/main/java/org/dive4elements/river/artifacts/model/map/WMSLayerFacet.java @ 9619:63bbd5e45839

#21 WMS Legend
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Thu, 10 Oct 2019 16:08:47 +0200
parents e4606eae8ea5
children
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.artifacts.model.map;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.dive4elements.artifactdatabase.state.DefaultFacet;
import org.dive4elements.artifactdatabase.state.Facet;
import org.dive4elements.artifacts.Artifact;
import org.dive4elements.artifacts.ArtifactNamespaceContext;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
import org.dive4elements.river.utils.GeometryUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.vividsolutions.jts.geom.Envelope;

public class WMSLayerFacet extends DefaultFacet {
    private static final long serialVersionUID = 1L;
    protected ComputeType type;
    protected List<String> layers;
    protected String stateId;
    protected String hash;
    protected String url;
    protected Envelope extent;
    protected Envelope originalExtent;
    protected String srid;
    private String legend;
    private String imagepath;

    private static final Logger log = Logger.getLogger(WMSLayerFacet.class);

    public WMSLayerFacet() {
    }

    public WMSLayerFacet(final int index, final String name, final String description) {
        this(index, name, description, ComputeType.FEED, null, null);
    }

    public WMSLayerFacet(final int index, final String name, final String description, final ComputeType type, final String stateId, final String hash

    ) {
        super(index, name, description);
        this.layers = new ArrayList<>();
        this.type = type;
        this.stateId = stateId;
        this.hash = hash;
    }

    public WMSLayerFacet(final int index, final String name, final String description, final ComputeType type, final String stateId, final String hash,
            final String url) {
        this(index, name, description, type, stateId, hash);
        this.url = url;
    }

    public void addLayer(final String name) {
        if (name != null && name.length() > 0) {
            this.layers.add(name);
        }
    }

    public List<String> getLayers() {
        return this.layers;
    }

    public void removeLayer(final String layer) {
        if (this.layers != null) {
            this.layers.remove(layer);
        }
    }

    public void setExtent(final Envelope extent) {
        if (extent != null) {
            this.extent = extent;
        } else {
            log.debug("setExtent(): extent is null");
        }
    }

    public Envelope getExtent() {
        return this.extent;
    }

    public void setOriginalExtent(final Envelope originalExtent) {
        this.originalExtent = originalExtent;
    }

    public Envelope getOriginalExtent() {
        return this.originalExtent;
    }

    public void setSrid(final String srid) {
        if (srid != null) {
            this.srid = srid;
        }
    }

    public String getSrid() {
        return this.srid;
    }

    @Override
    public Object getData(final Artifact artifact, final CallContext context) {
        return null;
    }

    @Override
    public Node toXML(final Document doc) {
        final ElementCreator ec = new ElementCreator(doc, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX);

        final Element facet = ec.create("facet");
        ec.addAttr(facet, "description", this.description, true);
        ec.addAttr(facet, "index", String.valueOf(this.index), true);
        ec.addAttr(facet, "name", this.name, true);
        ec.addAttr(facet, "url", this.url, true);
        ec.addAttr(facet, "layers", this.layers.get(0), true);
        ec.addAttr(facet, "srid", this.srid != null ? this.srid : "", true);
        ec.addAttr(facet, "extent", this.originalExtent != null ? GeometryUtils.jtsBoundsToOLBounds(this.originalExtent) : "", true);
        ec.addAttr(facet, "queryable", String.valueOf(isQueryable()), true);
        ec.addAttr(facet, "imagepath", this.imagepath, true);
        ec.addAttr(facet, "legend", this.legend, true);

        return facet;
    }

    public void setLegend(final String legend) {
        this.legend = legend;
    }

    /* Code-Kongruenz */
    public String getLegend() {
        return this.legend;
    }

    public boolean isQueryable() {
        return false;
    }

    /** Clone facet-bound data. */
    protected void cloneData(final WMSLayerFacet copy) {
        copy.type = this.type;
        copy.stateId = this.stateId;
        copy.hash = this.hash;

        if (this.layers != null) {
            copy.layers = new ArrayList<>(this.layers);
        } else {
            copy.layers = new ArrayList<>();
        }

        copy.originalExtent = this.originalExtent;
        copy.url = this.url;
        copy.extent = this.extent;
        copy.srid = this.srid;
        
        copy.imagepath = imagepath;
        copy.legend = legend;
    }

    @Override
    public Facet deepCopy() {
        final WMSLayerFacet copy = new WMSLayerFacet();
        copy.set(this);

        cloneData(copy);

        return copy;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org