source: core/trunk/lib/GeoExt/data/LayerRecord.js @ 238

Last change on this file since 238 was 238, checked in by ahocevar, 9 years ago

Added MapPanel, LayerRecord and LayerStore with examples and tests; also contains license.txt file. Big thanks to sbenthall and tcoulter for their original input, to elemoine for the good discussion today about the LayerStoreMixin and his patience despite my angryness, to tschaub for the constructive comments, and finally to everyone who participated in the discussions on the mailing list about what we want this component to be. r=elemoine,tschaub (closes #4)

File size: 2.2 KB
Line 
1/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation ¹
2 * Published under the BSD license.
3 * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
4 * of the license.
5 *
6 * ¹ pending approval */
7
8Ext.namespace("GeoExt.data");
9
10/**
11 * Class: GeoExt.data.LayerRecord
12 * A subclass of {Ext.data.Record} which provides a special record that
13 * represents an {OpenLayers.Layer}. This record will always have at least a
14 * layer and a title field in its data. The id of this record will be the same
15 * as the id of the layer it represents.
16 *
17 * Inherits from
18 * - {Ext.data.Record}
19 */
20GeoExt.data.LayerRecord = Ext.extend(Ext.data.Record, {
21   
22    /**
23     * Constructor: GeoExt.data.LayerRecord
24     * This constructor should not be used directly. Instead, the create method of
25     * this class should be used to create a constructor. The parameters are the
26     * same.
27     *
28     * Parameters:
29     * layer - {OpenLayers.Layer}
30     * data - {Object} additional values, keyed by field name
31     */
32    constructor: function(layer, data) {
33        this.data = Ext.applyIf({
34            title: layer.name,
35            layer: layer
36        }, data);
37        this.id = layer.id;
38    }
39});
40
41/**
42 * APIFunction: GeoExt.data.LayerRecord.create
43 * Creates a constructor for a LayerRecord, optionally with additional
44 * fields.
45 *
46 * Parameters:
47 * fieldDefinition - {Array} Field definition as in {Ext.data.Record.create}.
48 *     Can be omitted if no additional fields are required (records will
49 *     always have a {OpenLayers.Layer} layer and a {String} title field).
50 */
51GeoExt.data.LayerRecord.create = function(fieldDefinition) {
52    var o = [
53        {name: "layer"},
54        {name: "title"}
55    ].concat(fieldDefinition);
56
57    var f = Ext.extend(GeoExt.data.LayerRecord, {});
58    var p = f.prototype;
59    p.fields = new Ext.util.MixedCollection(false, function(field){
60        return field.name;
61    });
62    for(var i = 0, len = o.length; i < len; i++){
63        p.fields.add(new Ext.data.Field(o[i]));
64    }
65    f.getField = function(name){
66        return p.fields.get(name);
67    };
68    return f;
69}
Note: See TracBrowser for help on using the repository browser.