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