| 1 |
define([ |
| 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 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
constructor: function(name, options){ |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 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(f){ |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
f.render(); |
| 40 |
}, |
| 41 |
|
| 42 |
getDojoMap: function(){ |
| 43 |
return this.dojoMap; |
| 44 |
}, |
| 45 |
|
| 46 |
addFeature: function(f){ |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 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 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 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 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 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 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
return this._features; |
| 109 |
}, |
| 110 |
|
| 111 |
getFeatureAt: function(i){ |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
if(this._features == null){ |
| 119 |
return undefined; |
| 120 |
} |
| 121 |
return this._features[i]; |
| 122 |
}, |
| 123 |
|
| 124 |
getFeatureCount: function(){ |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
if(this._features == null){ |
| 130 |
return 0; |
| 131 |
} |
| 132 |
return this._features.length; |
| 133 |
}, |
| 134 |
|
| 135 |
clear: function(){ |
| 136 |
|
| 137 |
|
| 138 |
var fa = this.getFeatures(); |
| 139 |
this.removeFeature(fa); |
| 140 |
}, |
| 141 |
|
| 142 |
moveTo: function(event){ |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 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 |
|
| 159 |
|
| 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 |
|
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
}); |
| 175 |
}); |