﻿
GbgMap.API.ActiveLayer = function () { }

GbgMap.API.ActiveLayerWFS = function (options) {

    this.id = options.id;
    this.featureNS = options.featureNS;
    this.url = options.url;
    this.name = options.name;
    this.iconUrl = options.iconUrl;
    this.filter = options.filter;
    this.fields = options.fields;
    this.idField = options.idField;
    this.ingressField = options.ingressField;
    this.headerField = options.headerField;
    this.bodyField = options.bodyField;
    this.linkField = options.linkField;

    this.searchFields = options.searchFields;

    var features = new Array();

    this.addFeatures = function (featuresToAdd) {

        var olFeaturesToAdd = new Array();

        var layerToAdd = map.getLayersByName(this.name)[0];

        if (layerToAdd != null) {

            for (var i = 0; i < featuresToAdd.length; i++) {

                var point = new OpenLayers.Geometry.Point(featuresToAdd[i].x, featuresToAdd[i].y);
                var pointFeature = new OpenLayers.Feature.Vector(point, null, null);

                pointFeature.attributes = featuresToAdd[i];

                olFeaturesToAdd.push(pointFeature);

                features.push(featuresToAdd[i]);
            }

            layerToAdd.addFeatures(olFeaturesToAdd);
        }
    }

    this.getFeatures = function () {
        return features;
    }

    this.getFeatureById = function (featureId) {
        for (var i = 0; i < features.length; i++) {
            if (features[i].featureId == featureId) {
                return features[i];
            }
        }
    }
}

//Inherit from GbgMap.API.ActiveLayer
GbgMap.API.ActiveLayerWFS.prototype = new GbgMap.API.ActiveLayer();
