summaryrefslogtreecommitdiff
path: root/js/dojo-1.7.2/dojox/geo/openlayers/GfxLayer.js
blob: 49faa5e880fdc70fdb9efbc38ac6f1a198cf381e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//>>built
define("dojox/geo/openlayers/GfxLayer", ["dojo/_base/kernel",
				"dojo/_base/declare",
				"dojo/_base/connect",
				"dojo/_base/html",
				"dojox/gfx",
				"dojox/gfx/_base",
				"dojox/gfx/shape",
				"dojox/gfx/path",
				"dojox/gfx/matrix",
				"dojox/geo/openlayers/Feature",
				"dojox/geo/openlayers/Layer"], function(dojo, declare, connect, html, gfx, gbase, shape,
																								path, matrix, Feature, Layer){
	/*===== 
	var Layer = dojox.geo.openlayers.Layer; 
	=====*/
	return declare("dojox.geo.openlayers.GfxLayer", Layer, {
		//	summary: 
		//		A layer dedicated to render dojox.geo.openlayers.GeometryFeature
		//	description:
		//		A layer class for rendering geometries as dojox.gfx.Shape objects.
		//		This layer class accepts Features which encapsulates graphic objects to be added to the map.
		//	All objects should be added to this group.
		//	tags:
		//		private
		_viewport : null,

		constructor : function(name, options){
			//	summary:
			//		Constructs a new GFX layer.
			var s = dojox.gfx.createSurface(this.olLayer.div, 100, 100);
			this._surface = s;
			var vp;
			if (options && options.viewport)
				vp = options.viewport;
			else
				vp = s.createGroup();
			this.setViewport(vp);
			dojo.connect(this.olLayer, "onMapResize", this, "onMapResize");
			this.olLayer.getDataExtent = this.getDataExtent;
		},

		getViewport : function(){
			//	summary:
			//		Gets the viewport
			//	tags:
			//		internal
			return this._viewport;
		},

		setViewport : function(g){
			//	summary:
			//		Sets the viewport
			//	g: dojox.gfx.Group
			//	tags:
			//		internal
			if (this._viewport)
				this._viewport.removeShape();
			this._viewport = g;
			this._surface.add(g);
		},

		onMapResize : function(){
			//	summary:
			//		Called when map is resized.
			//	tag:
			//	protected
			this._surfaceSize();
		},

		setMap : function(map){
			//	summary:
			//		Sets the map for this layer.
			//	tag:
			//		protected
			this.inherited(arguments);
			this._surfaceSize();
		},

		getDataExtent : function(){
			//	summary:
			//		Get data extent
			//	tags:
			//		private
			var ret = this._surface.getDimensions();
			return ret;
		},

		getSurface : function(){
			//	summary:
			//		Get the underlying dojox.gfx.Surface
			//	returns: dojox.gfx.Surface 
			//		The dojox.gfx.Surface this layer uses to draw its GFX rendering.
			return this._surface;
		},

		_surfaceSize : function(){
			//	summary:
			//		Recomputes the surface size when being resized.
			//	tags:
			//		private
			var s = this.olLayer.map.getSize();
			this._surface.setDimensions(s.w, s.h);
		},

		moveTo : function(event){
			// summary:
			//   Called when this layer is moved or zoommed.
			//	event:
			//		The event
			var s = dojo.style(this.olLayer.map.layerContainerDiv);
			var left = parseInt(s.left);
			var top = parseInt(s.top);

			if (event.zoomChanged || left || top) {
				var d = this.olLayer.div;

				dojo.style(d, {
					left : -left + "px",
					top : -top + "px"
				});

				if (this._features == null)
					return;
				var vp = this.getViewport();

				vp.setTransform(matrix.translate(left, top));

				this.inherited(arguments);

			}
		},

		added : function(){
			//	summary:
			//		Called when added to a map.
			this.inherited(arguments);
			this._surfaceSize();
		}

	});
});