All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.flow.component.map.configuration.source.VectorSource Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2000-2024 Vaadin Ltd.
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See {@literal } for the full
 * license.
 */
package com.vaadin.flow.component.map.configuration.source;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.vaadin.flow.component.map.configuration.Constants;
import com.vaadin.flow.component.map.configuration.Feature;

public class VectorSource extends Source {
    private final List features = new ArrayList<>();

    public VectorSource() {
        this(new Options());
    }

    public VectorSource(Options options) {
        super(options);
    }

    @Override
    public String getType() {
        return Constants.OL_SOURCE_VECTOR;
    }

    @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
    @JsonIdentityReference(alwaysAsId = true)
    public List getFeatures() {
        return Collections.unmodifiableList(features);
    }

    public void addFeature(Feature feature) {
        Objects.requireNonNull(feature);

        features.add(feature);
        addChild(feature);
    }

    public void removeFeature(Feature feature) {
        Objects.requireNonNull(feature);

        features.remove(feature);
        removeChild(feature);
    }

    public void removeAllFeatures() {
        for (Feature feature : getFeatures().toArray(Feature[]::new)) {
            removeFeature(feature);
        }
    }

    public static class Options extends Source.Options {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy