/webportal/src/main/java/org/ala/spatial/analysis/web/AreaPolygon.java

http://alageospatialportal.googlecode.com/ · Java · 138 lines · 90 code · 21 blank · 27 comment · 16 complexity · 12f2246fcd9615283717c7f578ae5297 MD5 · raw file

  1. package org.ala.spatial.analysis.web;
  2. import au.org.emii.portal.composer.MapComposer;
  3. import au.org.emii.portal.composer.UtilityComposer;
  4. import au.org.emii.portal.menu.MapLayer;
  5. import au.org.emii.portal.menu.MapLayerMetadata;
  6. import au.org.emii.portal.settings.SettingsSupplementary;
  7. import net.sf.json.JSONArray;
  8. import net.sf.json.JSONException;
  9. import net.sf.json.JSONObject;
  10. import org.ala.spatial.util.CommonData;
  11. import org.ala.spatial.util.LayersUtil;
  12. import org.ala.spatial.util.Util;
  13. import org.apache.commons.httpclient.HttpClient;
  14. import org.apache.commons.httpclient.methods.PostMethod;
  15. import org.zkoss.zk.ui.Page;
  16. import org.zkoss.zk.ui.event.Event;
  17. import org.zkoss.zul.Button;
  18. import org.zkoss.zul.Textbox;
  19. /**
  20. *
  21. * @author Adam
  22. */
  23. public class AreaPolygon extends AreaToolComposer {
  24. private Textbox displayGeom;
  25. Button btnNext;
  26. //String layerName;
  27. Textbox txtLayerName;
  28. Button btnClear;
  29. @Override
  30. public void afterCompose() {
  31. super.afterCompose();
  32. txtLayerName.setValue(getMapComposer().getNextAreaLayerName("My Area"));
  33. }
  34. public void onClick$btnNext(Event event) {
  35. //reapply layer name
  36. getMapComposer().getMapLayer(layerName).setDisplayName(txtLayerName.getValue());
  37. getMapComposer().redrawLayersList();
  38. ok = true;
  39. this.detach();
  40. }
  41. public void onClick$btnClear(Event event) {
  42. MapComposer mc = getThisMapComposer();
  43. if(layerName != null && mc.getMapLayer(layerName) != null) {
  44. mc.removeLayer(layerName);
  45. }
  46. String script = mc.getOpenLayersJavascript().addPolygonDrawingTool();
  47. mc.getOpenLayersJavascript().execute(mc.getOpenLayersJavascript().iFrameReferences + script);
  48. displayGeom.setValue("");
  49. btnNext.setDisabled(true);
  50. btnClear.setDisabled(true);
  51. }
  52. public void onClick$btnCancel(Event event) {
  53. MapComposer mc = getThisMapComposer();
  54. if(layerName != null && mc.getMapLayer(layerName) != null) {
  55. mc.removeLayer(layerName);
  56. }
  57. this.detach();
  58. }
  59. /**
  60. *
  61. * @param event
  62. */
  63. public void onSelectionGeom(Event event) {
  64. String selectionGeom = (String) event.getData();
  65. try {
  66. String wkt = "";
  67. if (selectionGeom.contains("NaN NaN")) {
  68. displayGeom.setValue("");
  69. // lastTool = null;
  70. } else if (selectionGeom.startsWith("LAYER(")) {
  71. //reset stored size
  72. // storedSize = null;
  73. //get WKT from this feature
  74. String v = selectionGeom.replace("LAYER(", "");
  75. //FEATURE(table name if known, class name)
  76. v = v.substring(0, v.length() - 1);
  77. wkt = Util.wktFromJSON(getMapComposer().getMapLayer(v).getGeoJSON());
  78. displayGeom.setValue(wkt);
  79. //calculate area is not populated
  80. // if (storedSize == null) {
  81. // storedSize = getAreaOfWKT(wkt);
  82. // }
  83. } else {
  84. wkt = selectionGeom;
  85. displayGeom.setValue(wkt);
  86. }
  87. //get the current MapComposer instance
  88. MapComposer mc = getThisMapComposer();
  89. //add feature to the map as a new layer
  90. if (wkt.length() > 0) {
  91. layerName = (mc.getMapLayer(txtLayerName.getValue()) == null)?txtLayerName.getValue():mc.getNextAreaLayerName(txtLayerName.getValue());
  92. MapLayer mapLayer = mc.addWKTLayer(wkt, layerName, txtLayerName.getValue());
  93. MapLayerMetadata md = mapLayer.getMapLayerMetadata();
  94. if(md == null) {
  95. md = new MapLayerMetadata();
  96. mapLayer.setMapLayerMetadata(md);
  97. }
  98. md.setMoreInfo(LayersUtil.getMetadataForWKT("User drawn polygon", wkt));
  99. btnNext.setDisabled(false);
  100. btnClear.setDisabled(false);
  101. }
  102. // rgAreaSelection.getSelectedItem().setChecked(false);
  103. } catch (Exception e) {//FIXME
  104. }
  105. }
  106. /**
  107. * Gets the main pages controller so we can add a
  108. * drawing tool to the map
  109. * @return MapComposer = map controller class
  110. */
  111. private MapComposer getThisMapComposer() {
  112. MapComposer mapComposer = null;
  113. Page page = getPage();
  114. mapComposer = (MapComposer) page.getFellow("mapPortalPage");
  115. return mapComposer;
  116. }
  117. }