source: Dev/trunk/src/client/dojox/geo/openlayers/Layer.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

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