| 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 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
_viewport: null, |
| 21 |
|
| 22 |
constructor: function(name, options){ |
| 23 |
|
| 24 |
|
| 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 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
return this._viewport; |
| 44 |
}, |
| 45 |
|
| 46 |
setViewport: function(g){ |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
if(this._viewport){ |
| 53 |
this._viewport.removeShape(); |
| 54 |
} |
| 55 |
this._viewport = g; |
| 56 |
this._surface.add(g); |
| 57 |
}, |
| 58 |
|
| 59 |
onMapResize: function(){ |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
this._surfaceSize(); |
| 65 |
}, |
| 66 |
|
| 67 |
setMap: function(map){ |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
this.inherited(arguments); |
| 73 |
this._surfaceSize(); |
| 74 |
}, |
| 75 |
|
| 76 |
getDataExtent: function(){ |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
var ret = this._surface.getDimensions(); |
| 82 |
return ret; |
| 83 |
}, |
| 84 |
|
| 85 |
getSurface: function(){ |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
return this._surface; |
| 91 |
}, |
| 92 |
|
| 93 |
_surfaceSize: function(){ |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
var s = this.olLayer.map.getSize(); |
| 99 |
this._surface.setDimensions(s.w, s.h); |
| 100 |
}, |
| 101 |
|
| 102 |
moveTo: function(event){ |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 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 |
|
| 133 |
|
| 134 |
this.inherited(arguments); |
| 135 |
this._surfaceSize(); |
| 136 |
} |
| 137 |
|
| 138 |
}); |
| 139 |
}); |