1 | define([ |
---|
2 | "dojo/_base/declare", |
---|
3 | "dojo/_base/connect", |
---|
4 | "dojo/dom-style", |
---|
5 | "dojox/gfx", |
---|
6 | "dojox/gfx/matrix", |
---|
7 | "./Feature", |
---|
8 | "./Layer" |
---|
9 | ], function(declare, connect, style, gfx, matrix, Feature, Layer){ |
---|
10 | |
---|
11 | return declare("dojox.geo.openlayers.GfxLayer", Layer, { |
---|
12 | // summary: |
---|
13 | // A layer dedicated to render dojox.geo.openlayers.GeometryFeature |
---|
14 | // description: |
---|
15 | // A layer class for rendering geometries as dojox.gfx.Shape objects. |
---|
16 | // This layer class accepts Features which encapsulates graphic objects to be added to the map. |
---|
17 | // All objects should be added to this group. |
---|
18 | // tags: |
---|
19 | // private |
---|
20 | _viewport: null, |
---|
21 | |
---|
22 | constructor: function(name, options){ |
---|
23 | // summary: |
---|
24 | // Constructs a new GFX layer. |
---|
25 | var s = gfx.createSurface(this.olLayer.div, 100, 100); |
---|
26 | this._surface = s; |
---|
27 | var vp; |
---|
28 | if(options && options.viewport){ |
---|
29 | vp = options.viewport; |
---|
30 | }else{ |
---|
31 | vp = s.createGroup(); |
---|
32 | } |
---|
33 | this.setViewport(vp); |
---|
34 | connect.connect(this.olLayer, "onMapResize", this, "onMapResize"); |
---|
35 | this.olLayer.getDataExtent = this.getDataExtent; |
---|
36 | }, |
---|
37 | |
---|
38 | getViewport: function(){ |
---|
39 | // summary: |
---|
40 | // Gets the viewport |
---|
41 | // tags: |
---|
42 | // internal |
---|
43 | return this._viewport; |
---|
44 | }, |
---|
45 | |
---|
46 | setViewport: function(g){ |
---|
47 | // summary: |
---|
48 | // Sets the viewport |
---|
49 | // g: dojox.gfx.Group |
---|
50 | // tags: |
---|
51 | // internal |
---|
52 | if(this._viewport){ |
---|
53 | this._viewport.removeShape(); |
---|
54 | } |
---|
55 | this._viewport = g; |
---|
56 | this._surface.add(g); |
---|
57 | }, |
---|
58 | |
---|
59 | onMapResize: function(){ |
---|
60 | // summary: |
---|
61 | // Called when map is resized. |
---|
62 | // tags: |
---|
63 | // protected |
---|
64 | this._surfaceSize(); |
---|
65 | }, |
---|
66 | |
---|
67 | setMap: function(map){ |
---|
68 | // summary: |
---|
69 | // Sets the map for this layer. |
---|
70 | // tags: |
---|
71 | // protected |
---|
72 | this.inherited(arguments); |
---|
73 | this._surfaceSize(); |
---|
74 | }, |
---|
75 | |
---|
76 | getDataExtent: function(){ |
---|
77 | // summary: |
---|
78 | // Get data extent |
---|
79 | // tags: |
---|
80 | // private |
---|
81 | var ret = this._surface.getDimensions(); |
---|
82 | return ret; |
---|
83 | }, |
---|
84 | |
---|
85 | getSurface: function(){ |
---|
86 | // summary: |
---|
87 | // Get the underlying dojox.gfx.Surface |
---|
88 | // returns: |
---|
89 | // The dojox.gfx.Surface this layer uses to draw its GFX rendering. |
---|
90 | return this._surface; // dojox.gfx.Surface |
---|
91 | }, |
---|
92 | |
---|
93 | _surfaceSize: function(){ |
---|
94 | // summary: |
---|
95 | // Recomputes the surface size when being resized. |
---|
96 | // tags: |
---|
97 | // private |
---|
98 | var s = this.olLayer.map.getSize(); |
---|
99 | this._surface.setDimensions(s.w, s.h); |
---|
100 | }, |
---|
101 | |
---|
102 | moveTo: function(event){ |
---|
103 | // summary: |
---|
104 | // Called when this layer is moved or zoomed. |
---|
105 | // event: |
---|
106 | // The event |
---|
107 | var s = style.get(this.olLayer.map.layerContainerDiv); |
---|
108 | var left = parseInt(s.left); |
---|
109 | var top = parseInt(s.top); |
---|
110 | |
---|
111 | if(event.zoomChanged || left || top){ |
---|
112 | var d = this.olLayer.div; |
---|
113 | |
---|
114 | style.set(d, { |
---|
115 | left: -left + "px", |
---|
116 | top: -top + "px" |
---|
117 | }); |
---|
118 | |
---|
119 | if(this._features == null){ |
---|
120 | return; |
---|
121 | } |
---|
122 | var vp = this.getViewport(); |
---|
123 | |
---|
124 | vp.setTransform(matrix.translate(left, top)); |
---|
125 | |
---|
126 | this.inherited(arguments); |
---|
127 | |
---|
128 | } |
---|
129 | }, |
---|
130 | |
---|
131 | added: function(){ |
---|
132 | // summary: |
---|
133 | // Called when added to a map. |
---|
134 | this.inherited(arguments); |
---|
135 | this._surfaceSize(); |
---|
136 | } |
---|
137 | |
---|
138 | }); |
---|
139 | }); |
---|