source: Dev/branches/rest-dojo-ui/client/dojox/geo/openlayers/Layer.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 4.2 KB
Line 
1define(["dojo/_base/kernel", "dojo/_base/declare", "dojo/_base/lang", "dojo/_base/array", "dojo/_base/sniff"],
2        function(dojo, declare, lang, array, sniff){
3
4                return declare("dojox.geo.openlayers.Layer", null, {
5                        //      summary:
6                        //              Base layer class for dojox.geo.openlayers.Map specific layers extending OpenLayers.Layer class.
7                        //              This layer class accepts Features which encapsulates graphic objects to be added to the map.
8                        //              This layer class encapsulates an OpenLayers.Layer.
9                        //              This class provides Feature management such as add, remove and feature access.
10                        constructor : function(name, options){
11                                //      summary:
12                                //              Constructs a new Layer.
13                                //      name: String
14                                //              The name of the layer.
15                                //      options: Object
16                                //              Options passed to the underlying OpenLayers.Layer object.
17
18                                var ol = options ? options.olLayer : null;
19
20                                if (!ol)
21                                        ol = lang.delegate(new OpenLayers.Layer(name, options));
22
23                                this.olLayer = ol;
24                                this._features = null;
25                                this.olLayer.events.register("moveend", this, lang.hitch(this, this.moveTo));
26                        },
27
28                        renderFeature : function(/* Feature */f){
29                                //      summary:
30                                //              Called when rendering a feature is necessary.
31                                //      f : Feature
32                                //              The feature to draw.
33                                f.render();
34                        },
35
36                        getDojoMap : function(){
37                                return this.dojoMap;
38                        },
39
40                        addFeature : function(/* Feature | Array */f){
41                                //      summary:
42                                //              Add a feature or an array of features to the layer.
43                                //      f : Feature or Array
44                                //              The Feature or array of features to add.
45                                if (lang.isArray(f)) {
46                                        array.forEach(f, function(item){
47                                                this.addFeature(item);
48                                        }, this);
49                                        return;
50                                }
51                                if (this._features == null)
52                                        this._features = [];
53                                this._features.push(f);
54                                f._setLayer(this);
55                        },
56
57                        removeFeature : function(/* Feature | Array */f){
58                                //      summary :
59                                //              Removes a feature or an array of features from the layer.
60                                //      f : Feature or Array
61                                //              The Feature or array of features to remove.
62                                var ft = this._features;
63                                if (ft == null)
64                                        return;
65                                if (f instanceof Array) {
66                                        f = f.slice(0);
67                                        array.forEach(f, function(item){
68                                                this.removeFeature(item);
69                                        }, this);
70                                        return;
71                                }
72                                var i = array.indexOf(ft, f);
73                                if (i != -1)
74                                        ft.splice(i, 1);
75                                f._setLayer(null);
76                                f.remove();
77                        },
78
79                        removeFeatureAt : function(index){
80                                //      summary:
81                                //              Remove the feature at the specified index.
82                                //      description:
83                                //              Remove the feature at the specified index.
84                                //      index: Number
85                                //              The index of the feature to remove.
86                                var ft = this._features;
87                                var f = ft[index];
88                                if (!f)
89                                        return;
90                                ft.splice(index, 1);
91                                f._setLayer(null);
92                                f.remove();
93                        },
94
95                        getFeatures : function(){
96                                //      summary:
97                                //              Retrieves the feature hold by this layer.
98                                //      returns: Array
99                                //              The untouched array of features hold by this layer.
100                                return this._features;
101                        },
102
103                        getFeatureAt : function(i){
104                                //      summary:
105                                //              Returns the i-th feature of this layer.
106                                //      i : int
107                                //              The index of the feature to return.
108                                //      returns : ibm_maps.maps.Layer
109                                //              The i-th feature of this layer.
110                                if (this._features == null)
111                                        return undefined;
112                                return this._features[i];
113                        },
114
115                        getFeatureCount : function(){
116                                //      summary:
117                                //              Returns the number of the features contained by this layer.
118                                //      returns: int
119                                //              The number of the features contained by this layer.
120                                if (this._features == null)
121                                        return 0;
122                                return this._features.length;
123                        },
124
125                        clear : function(){
126                                //      summary:
127                                //              Removes all the features from this layer.
128                                var fa = this.getFeatures();
129                                this.removeFeature(fa);
130                        },
131
132                        moveTo : function(event){
133                                //      summary:
134                                //              Called when the layer is panned or zoomed.
135                                //      event: Object
136                                //              The event
137                                if (event.zoomChanged) {
138                                        if (this._features == null)
139                                                return;
140                                        array.forEach(this._features, function(f){
141                                                this.renderFeature(f);
142                                        }, this);
143                                }
144                        },
145
146                        redraw : function(){
147                                //      summary:
148                                //              Redraws this layer
149                                if (sniff.isIE)
150                                        setTimeout(lang.hitch(this, function(){
151                                                this.olLayer.redraw();
152                                        }, 0));
153                                else
154                                        this.olLayer.redraw();
155                        },
156
157                        added : function(){
158                        //      summary:
159                        //              Called when the layer is added to the map
160                        }
161
162                });
163        });
Note: See TracBrowser for help on using the repository browser.