Revision 22616 branches/v10/extensions/extPublishMapserver/src/org/gvsig/publish/mapserver/model/wms/MapserverWMSLayer.java
MapserverWMSLayer.java | ||
---|---|---|
46 | 46 |
import java.io.IOException; |
47 | 47 |
|
48 | 48 |
import org.gvsig.publish.PublishLogger; |
49 |
import org.gvsig.publish.exceptions.LayerInfoNotAvailableException; |
|
50 | 49 |
import org.gvsig.publish.exceptions.PublishException; |
51 | 50 |
import org.gvsig.publish.infoproject.IDataSourceInfo; |
52 | 51 |
import org.gvsig.publish.infoproject.ILayerInfo; |
... | ... | |
118 | 117 |
*/ |
119 | 118 |
public void setLayerInfo(ILayerInfo layerInfo) { |
120 | 119 |
super.setLayerInfo(layerInfo); |
121 |
try { |
|
122 |
setName(getLayerInfo().getName()); |
|
123 |
setTitle(getLayerInfo().getTitle()); |
|
124 |
setAbstract("generated by gvSIG"); |
|
125 |
} catch (LayerInfoNotAvailableException e) { |
|
126 |
PublishLogger.getLog().error("ERROR " + getClassName() + " : Cannot initialize layer info", e); |
|
127 |
} |
|
128 |
|
|
120 |
setName(getLayerInfo().getName()); |
|
121 |
setTitle(getLayerInfo().getTitle()); |
|
122 |
setAbstract("generated by gvSIG"); |
|
129 | 123 |
} |
130 |
|
|
124 |
|
|
131 | 125 |
private Mapserver getMapServer(){ |
132 | 126 |
//Cast to Mapserver |
133 | 127 |
Mapserver mapserver = (Mapserver)getService().getServer(); |
... | ... | |
140 | 134 |
public void publish() throws PublishException{ |
141 | 135 |
//only for no group layers |
142 | 136 |
//TODO: wms_group_abstract ... |
143 |
try { |
|
144 |
if (getLayerInfo().getDataSource() != null){ |
|
145 |
config = new MapFile.Layer(); |
|
146 |
getMapfile().add(config); |
|
147 |
generateLayerSection(); |
|
148 |
} |
|
149 |
} catch (LayerInfoNotAvailableException e) { |
|
150 |
throw new PublishException("publish_infolayer_not_available"); |
|
151 |
} |
|
152 | 137 |
|
138 |
if (getLayerInfo().getDataSource() != null){ |
|
139 |
config = new MapFile.Layer(); |
|
140 |
getMapfile().add(config); |
|
141 |
generateLayerSection(); |
|
142 |
} |
|
153 | 143 |
//publish all its childs |
154 | 144 |
super.publish(); |
155 | 145 |
} |
156 |
|
|
157 |
private void generateLayerSection() throws PublishException, LayerInfoNotAvailableException{
|
|
158 |
|
|
146 |
|
|
147 |
private void generateLayerSection() throws PublishException{ |
|
148 |
|
|
159 | 149 |
config.name = getName(); |
160 | 150 |
config.status = "ON"; |
161 | 151 |
config.debug = getMapServer().isDebug(); |
... | ... | |
167 | 157 |
config.minscale = new Double(getLayerInfo().getMinscale()).toString(); |
168 | 158 |
config.transparency = getLayerInfo().getOpacityPercent(); |
169 | 159 |
config.dump = isQueryable(); |
170 |
|
|
160 |
|
|
171 | 161 |
//mosaic |
172 | 162 |
generateMosaicSection(); |
173 | 163 |
//labeling |
... | ... | |
175 | 165 |
//PROJECTION (I must query the layer to know the shape projection) |
176 | 166 |
//lyr.layercrs = new CRS(getLayerInfo().getEPSG(),true); |
177 | 167 |
config.layercrs = new CRS(getLayerInfo().getDataSource().getEPSG(),true); |
178 |
|
|
168 |
|
|
179 | 169 |
//CLASS |
180 | 170 |
generateClassSection(); |
181 | 171 |
//METADATA |
... | ... | |
184 | 174 |
} |
185 | 175 |
/** |
186 | 176 |
* Generates the LAYER->DATA parameter |
187 |
* @throws LayerInfoNotAvailableException
|
|
177 |
* |
|
188 | 178 |
*/ |
189 |
private void generateDataParameter() throws LayerInfoNotAvailableException {
|
|
179 |
private void generateDataParameter(){ |
|
190 | 180 |
IDataSourceInfo ds = getLayerInfo().getDataSource(); |
191 | 181 |
if (ds.getType() == IDataSourceInfo.POSTGIS_TYPE){ |
192 | 182 |
IDataBaseInfo db = (IDataBaseInfo)ds; |
... | ... | |
201 | 191 |
} |
202 | 192 |
} |
203 | 193 |
|
204 |
private void generateMosaicSection() throws LayerInfoNotAvailableException {
|
|
194 |
private void generateMosaicSection(){ |
|
205 | 195 |
if (getSpecificParams().isMosaic()){ |
206 | 196 |
config.type = "RASTER"; |
207 | 197 |
config.tileIndex = getService().getServer().getPublication().getServerSideFilePath(getLayerInfo().getDataSource()); |
208 | 198 |
config.data = null; |
209 | 199 |
config.classList.clear(); |
210 | 200 |
config.tileItem="location"; |
211 |
} |
|
212 |
|
|
201 |
} |
|
213 | 202 |
} |
214 | 203 |
|
215 | 204 |
/** |
216 | 205 |
* TODO: |
217 | 206 |
* lyr.labelsizeitem = getLayerInfo().getLabeling().getLabelHeightField(); |
218 | 207 |
* lyr.labelangleitem = getLayerInfo().getLabeling().getLabelRotationField(); |
219 |
* @throws LayerInfoNotAvailableException
|
|
208 |
* |
|
220 | 209 |
*/ |
221 |
private void generateLabelingSection() throws LayerInfoNotAvailableException{
|
|
210 |
private void generateLabelingSection(){ |
|
222 | 211 |
if (getLayerInfo().getLabeling() != null){ |
223 |
config.labelitem = getLayerInfo().getLabeling().getLabelField(); |
|
224 |
|
|
212 |
config.labelitem = getLayerInfo().getLabeling().getLabelField(); |
|
225 | 213 |
} |
226 | 214 |
} |
227 |
private void generateClassSection() throws PublishException, LayerInfoNotAvailableException{ |
|
215 |
/** |
|
216 |
* Generates object MAP->LAYER->CLASS |
|
217 |
* @throws PublishException |
|
218 |
* |
|
219 |
*/ |
|
220 |
private void generateClassSection() throws PublishException{ |
|
228 | 221 |
//CLASS |
229 | 222 |
Object source = getLayerInfo().getLegend(); |
230 | 223 |
if(source instanceof ISingleSymbolLegendInfo){ |
... | ... | |
241 | 234 |
} |
242 | 235 |
} |
243 | 236 |
|
244 |
private void generateSingleLegend(ISingleSymbolLegendInfo legend, Layer lyr) throws PublishException, LayerInfoNotAvailableException {
|
|
237 |
private void generateSingleLegend(ISingleSymbolLegendInfo legend, Layer lyr) throws PublishException{ |
|
245 | 238 |
ISymbolInfo isymbol = legend.getSymbolInfo(); |
246 | 239 |
lyr.classList.clear(); |
247 | 240 |
MapClass clase = new MapClass(); |
... | ... | |
254 | 247 |
//put labeling if exists |
255 | 248 |
if ( getLayerInfo().getLabeling().getLabelField() != null){ |
256 | 249 |
generateSymbol(getLayerInfo().getLabeling().getSymbolInfo(), clase); |
257 |
|
|
250 |
|
|
258 | 251 |
} |
259 | 252 |
//add the class into the layer |
260 | 253 |
lyr.addClass(clase); |
... | ... | |
268 | 261 |
* @param lyr |
269 | 262 |
* The layer |
270 | 263 |
* @throws PublishException |
271 |
* @throws LayerInfoNotAvailableException |
|
264 |
* |
|
265 |
* |
|
272 | 266 |
*/ |
273 |
private void generateIntervalLegend(IIntervalLegendInfo legend, Layer lyr) throws PublishException, LayerInfoNotAvailableException {
|
|
267 |
private void generateIntervalLegend(IIntervalLegendInfo legend, Layer lyr) throws PublishException{ |
|
274 | 268 |
//check if is labeled |
275 | 269 |
boolean islabeled = false; |
276 | 270 |
if ( getLayerInfo().getLabeling().getLabelField() != null){ |
277 | 271 |
islabeled = true; |
278 | 272 |
} |
279 |
|
|
273 |
|
|
280 | 274 |
String[] expressions = legend.getExpressions(); |
281 | 275 |
for (int i=0 ; i<expressions.length ; i++){ |
282 | 276 |
ISymbolInfo isymbol = legend.getSymbolByExpression(expressions[i]); |
... | ... | |
292 | 286 |
} |
293 | 287 |
} |
294 | 288 |
|
295 |
private void generateUniqueLegend(IUniqueValuesLegendInfo legend, Layer lyr) throws PublishException, LayerInfoNotAvailableException {
|
|
289 |
private void generateUniqueLegend(IUniqueValuesLegendInfo legend, Layer lyr) throws PublishException{ |
|
296 | 290 |
//check if is labeled |
297 | 291 |
boolean islabeled = false; |
298 | 292 |
if ( getLayerInfo().getLabeling().getLabelField() != null){ |
... | ... | |
318 | 312 |
} |
319 | 313 |
} |
320 | 314 |
|
321 |
private void generateStyle(ISymbolInfo isymbol, MapClass clase) throws PublishException, LayerInfoNotAvailableException{
|
|
315 |
private void generateStyle(ISymbolInfo isymbol, MapClass clase) throws PublishException{ |
|
322 | 316 |
if (getLayerInfo().getDataSource().getDataType() == IDataSourceInfo.POINT_DATA){ |
323 | 317 |
//I can do a cast to Marker Symbol |
324 | 318 |
IMarkerSymbolInfo pointSymbol = (IMarkerSymbolInfo)isymbol; |
... | ... | |
337 | 331 |
|
338 | 332 |
} |
339 | 333 |
|
340 |
private void generateSymbol(ITextSymbolInfo textSymbol, MapClass clase) throws LayerInfoNotAvailableException{
|
|
334 |
private void generateSymbol(ITextSymbolInfo textSymbol, MapClass clase){ |
|
341 | 335 |
clase.etiqueta = new Label(); |
342 | 336 |
//TODO: change by getColor() |
343 | 337 |
Color c = textSymbol.getFontColor(); |
... | ... | |
369 | 363 |
Mapserver m = (Mapserver)getService().getServer(); |
370 | 364 |
String s = m.getMapfileFile().getParentFile().getAbsolutePath(); |
371 | 365 |
File dst = new File(s+ File.separator+ icon.getName()); |
372 |
|
|
366 |
|
|
373 | 367 |
try { |
374 | 368 |
FileUtils.copy(icon, dst); |
375 | 369 |
} catch (IOException e) { |
376 | 370 |
throw new PublishException("cannot_copy_icons"); |
377 | 371 |
} |
378 | 372 |
} |
379 |
|
|
373 |
|
|
380 | 374 |
} |
381 | 375 |
/** |
382 | 376 |
* In Mapserver is impossible to have a dashed outline |
... | ... | |
409 | 403 |
/** |
410 | 404 |
* Generates the METADATA object |
411 | 405 |
* @param mapLayer |
412 |
* @throws LayerInfoNotAvailableException
|
|
406 |
* |
|
413 | 407 |
*/ |
414 |
private void generateMetadata(Layer mapLayer) throws LayerInfoNotAvailableException{
|
|
408 |
private void generateMetadata(Layer mapLayer){ |
|
415 | 409 |
//add metadata |
416 | 410 |
mapLayer.metadata.wms_name = getName(); |
417 | 411 |
mapLayer.metadata.wms_title =getTitle(); |
... | ... | |
421 | 415 |
mapLayer.metadata.wms_extent = bbox; |
422 | 416 |
mapLayer.metadata.gml_include_items = "all"; |
423 | 417 |
//adding layer_group |
424 |
|
|
418 |
|
|
425 | 419 |
if (getLayerInfo().getPathString().equals("/")==false){ |
426 | 420 |
String aux2 = getLayerInfo().getPathString(); |
427 | 421 |
mapLayer.metadata.wms_layer_group = aux2.substring(0,aux2.length()-1); |
428 | 422 |
} |
429 | 423 |
} |
430 |
|
|
424 |
|
|
431 | 425 |
/* |
432 | 426 |
* (non-Javadoc) |
433 | 427 |
* @see com.iver.utiles.IPersistance#getClassName() |
Also available in: Unified diff