Mercurial > mxd2map
comparison src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 179:f3a91cd7440b
Added a first version of feature labeling.
author | raimund renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 08 Jul 2011 16:32:05 +0200 |
parents | f11d13940626 |
children | f4eb506499f5 |
comparison
equal
deleted
inserted
replaced
178:d10d5f560b1a | 179:f3a91cd7440b |
---|---|
1 package de.intevation.mxd.writer; | 1 package de.intevation.mxd.writer; |
2 | 2 |
3 import org.apache.log4j.Logger; | 3 import org.apache.log4j.Logger; |
4 | |
5 import java.awt.Color; | |
4 | 6 |
5 import org.w3c.dom.Document; | 7 import org.w3c.dom.Document; |
6 import org.w3c.dom.Element; | 8 import org.w3c.dom.Element; |
7 import org.w3c.dom.NodeList; | 9 import org.w3c.dom.NodeList; |
8 | 10 |
11 import javax.xml.xpath.XPathConstants; | 13 import javax.xml.xpath.XPathConstants; |
12 | 14 |
13 import edu.umn.gis.mapscript.mapObj; | 15 import edu.umn.gis.mapscript.mapObj; |
14 import edu.umn.gis.mapscript.layerObj; | 16 import edu.umn.gis.mapscript.layerObj; |
15 import edu.umn.gis.mapscript.classObj; | 17 import edu.umn.gis.mapscript.classObj; |
18 import edu.umn.gis.mapscript.labelObj; | |
19 import edu.umn.gis.mapscript.colorObj; | |
20 import edu.umn.gis.mapscript.fontSetObj; | |
21 import edu.umn.gis.mapscript.hashTableObj; | |
16 | 22 |
17 import edu.umn.gis.mapscript.MS_UNITS; | 23 import edu.umn.gis.mapscript.MS_UNITS; |
18 import edu.umn.gis.mapscript.MS_LAYER_TYPE; | 24 import edu.umn.gis.mapscript.MS_LAYER_TYPE; |
19 import edu.umn.gis.mapscript.MS_CONNECTION_TYPE; | 25 import edu.umn.gis.mapscript.MS_CONNECTION_TYPE; |
26 import edu.umn.gis.mapscript.MS_FONT_TYPE; | |
27 import edu.umn.gis.mapscript.MS_POSITIONS_ENUM; | |
20 | 28 |
21 import de.intevation.mxd.utils.XMLUtils; | 29 import de.intevation.mxd.utils.XMLUtils; |
22 | 30 |
23 /** | 31 /** |
24 * The Mapfile Writer. | 32 * The Mapfile Writer. |
274 } | 282 } |
275 } | 283 } |
276 | 284 |
277 } | 285 } |
278 layer.setTemplate("PleaseInsertAValidTemplateForGFI"); | 286 layer.setTemplate("PleaseInsertAValidTemplateForGFI"); |
287 | |
288 NodeList labels = layerElement.getElementsByTagName("label"); | |
289 if(labels.getLength() > 0) { | |
290 Element label = (Element)labels.item(0); | |
291 String expr = label.getAttribute("expression"); | |
292 expr = expr.replaceAll("\\[", ""); | |
293 expr = expr.replaceAll("\\]", ""); | |
294 if(!prefix.equals("")) { | |
295 expr = prefix + "." + expr; | |
296 } | |
297 layer.setLabelitem(expr); | |
298 } | |
279 //Write classes. | 299 //Write classes. |
280 writeClass(layer, layerElement); | 300 writeClass(layer, layerElement); |
281 } | 301 } |
282 | 302 |
283 } | 303 } |
304 if (list.getLength() > 1) { | 324 if (list.getLength() > 1) { |
305 name += "-" + i; | 325 name += "-" + i; |
306 } | 326 } |
307 } | 327 } |
308 co.setName (name); | 328 co.setName (name); |
329 | |
330 NodeList labels = layerElement.getElementsByTagName("label"); | |
331 if(labels.getLength() > 0) { | |
332 Element labelElement = (Element)labels.item(0); | |
333 String layerType = layerElement.getAttribute("type"); | |
334 writeLabel(co, labelElement, layerType); | |
335 } | |
309 if(classElement.hasAttribute("field_count")) { | 336 if(classElement.hasAttribute("field_count")) { |
310 co.setExpression(createExpression(classElement, i)); | 337 co.setExpression(createExpression(classElement, i)); |
311 } | 338 } |
312 //Write symbols and styles. | 339 //Write symbols and styles. |
313 NodeList l = classElement.getChildNodes(); | 340 NodeList l = classElement.getChildNodes(); |
327 FillStyleWriter swriter = new FillStyleWriter (this.map, co); | 354 FillStyleWriter swriter = new FillStyleWriter (this.map, co); |
328 swriter.write (elem); | 355 swriter.write (elem); |
329 } | 356 } |
330 } | 357 } |
331 } | 358 } |
359 } | |
360 | |
361 | |
362 private void writeLabel( | |
363 classObj co, | |
364 Element labelElement, | |
365 String layerType) { | |
366 | |
367 labelObj label = co.getLabel(); | |
368 Element symbol = (Element)labelElement.getFirstChild(); | |
369 if(symbol != null && symbol.getTagName().equals("symbol")) { | |
370 String type = symbol.getAttribute("type"); | |
371 if(type.equals("text")) { | |
372 label.setType(MS_FONT_TYPE.MS_TRUETYPE); | |
373 } | |
374 label.setSize(Double.parseDouble(symbol.getAttribute("size"))); | |
375 | |
376 if(symbol.hasAttribute("color")) { | |
377 String c = symbol.getAttribute("color"); | |
378 Color col = Color.decode(c); | |
379 colorObj color = new colorObj( | |
380 col.getRed(), | |
381 col.getGreen(), | |
382 col.getBlue(), | |
383 -4); | |
384 label.setColor(color); | |
385 } | |
386 if(symbol.hasAttribute("font")) { | |
387 String font = symbol.getAttribute("font"); | |
388 fontSetObj fso = this.map.getFontset(); | |
389 hashTableObj fonts = fso.getFonts(); | |
390 String mapFont = fonts.get(font,""); | |
391 if(mapFont != null && !mapFont.equals("")) { | |
392 label.setFont(font); | |
393 } | |
394 else { | |
395 logger.info( | |
396 "Could not find font " + font + " in font set. " + | |
397 "Using FreeSans for labels."); | |
398 label.setFont("FreeSans"); | |
399 } | |
400 } | |
401 | |
402 if(labelElement.hasAttribute("max_scale")) { | |
403 double min = | |
404 Double.parseDouble(labelElement.getAttribute("max_scale")); | |
405 if(min > 0) { | |
406 label.setMinscaledenom(min); | |
407 } | |
408 } | |
409 if(labelElement.hasAttribute("min_scale")) { | |
410 double max = | |
411 Double.parseDouble(labelElement.getAttribute("min_scale")); | |
412 if(max > 0) { | |
413 label.setMaxscaledenom(max); | |
414 } | |
415 } | |
416 | |
417 if(layerType.equals("point")) { | |
418 label.setPosition(MS_POSITIONS_ENUM.MS_UC.swigValue()); | |
419 } | |
420 } | |
332 } | 421 } |
333 | 422 |
334 | 423 |
335 private String createExpression(Element ce, int index) { | 424 private String createExpression(Element ce, int index) { |
336 String expression = "("; | 425 String expression = "("; |