gis_data_editor_form.twig 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <form id="gis_data_editor_form" action="{{ url('/gis-data-editor') }}" method="post">
  2. <input type="hidden" id="themeImagePath" value="{{ image() }}">
  3. <div id="gis_data_editor">
  4. <h3>{{ 'Value for the column "%s"'|trans|format(field) }}</h3>
  5. <input type="hidden" name="field" value="{{ field }}">
  6. <input type="hidden" name="type" value="{{ column_type }}">
  7. {# The input field to which the final result should be added and corresponding null checkbox #}
  8. {% if input_name is not null %}
  9. <input type="hidden" name="input_name" value="{{ input_name }}">
  10. {% endif %}
  11. {{ get_hidden_inputs() }}
  12. {# Visualization section #}
  13. <div id="placeholder">
  14. {{ visualization|raw }}
  15. </div>
  16. <div id="openlayersmap" style="width: {{width}}px; height: {{height}}px;"{{ srid == 0 ? ' class="hide"' }}></div>
  17. <div class="choice float-end">
  18. <input type="checkbox" id="choice" value="useBaseLayer">
  19. <label for="choice">{% trans "Use OpenStreetMaps as Base Layer" %}</label>
  20. </div>
  21. <script type="text/javascript">{{ open_layers|raw }}</script>
  22. {# End of visualization section #}
  23. {# Header section - Inclueds GIS type selector and input field for SRID #}
  24. <div id="gis_data_header">
  25. <select name="gis_data[gis_type]" class="gis_type{{ column_type != 'GEOMETRY' ? ' hide' }}">
  26. {% for gis_type in gis_types %}
  27. <option value="{{ gis_type }}"{{ geom_type == gis_type ? ' selected="selected"' }}>
  28. {{ gis_type }}
  29. </option>
  30. {% endfor %}
  31. </select>
  32. <label for="srid">{% trans %}SRID:{% context %}Spatial Reference System Identifier{% endtrans %}</label>
  33. <input id="srid" name="gis_data[srid]" type="text" value="{{ srid }}">
  34. </div>
  35. {# End of header section #}
  36. {# Data section #}
  37. <div id="gis_data">
  38. {% if geom_type == 'GEOMETRYCOLLECTION' %}
  39. <input type="hidden" name="gis_data[GEOMETRYCOLLECTION][geom_count]" value="{{ geom_count }}">
  40. {% endif %}
  41. <template id="gis_type_template">
  42. <select class="gis_type">
  43. {% for gis_type in gis_types|slice(0, 6) %}
  44. <option value="{{ gis_type }}">{{ gis_type }}</option>
  45. {% endfor %}
  46. </select>
  47. </template>
  48. {% for a in 0..geom_count - 1 %}
  49. {% if gis_data[a] is not null %}
  50. {% if geom_type == 'GEOMETRYCOLLECTION' %}
  51. <br><br>
  52. {{ 'Geometry %d:'|trans|format(a + 1) }}
  53. <br>
  54. {% if gis_data[a]['gis_type'] is not null %}
  55. {% set type = gis_data[a]['gis_type'] %}
  56. {% else %}
  57. {% set type = gis_types[0] %}
  58. {% endif %}
  59. <select name="gis_data[{{ a }}][gis_type]" class="gis_type">
  60. {% for gis_type in gis_types|slice(0, 6) %}
  61. <option value="{{ gis_type }}"{{ type == gis_type ? ' selected="selected"' }}>
  62. {{ gis_type }}
  63. </option>
  64. {% endfor %}
  65. </select>
  66. {% else %}
  67. {% set type = geom_type %}
  68. {% endif %}
  69. {% if type == 'POINT' %}
  70. <br>
  71. {% trans 'Point:' %}
  72. <label>
  73. {% trans 'X' %}
  74. <input name="gis_data[{{ a }}][POINT][x]" type="text" value="{{ gis_data[a]['POINT']['x'] }}">
  75. </label>
  76. <label>
  77. {% trans 'Y' %}
  78. <input name="gis_data[{{ a }}][POINT][y]" type="text" value="{{ gis_data[a]['POINT']['y'] }}">
  79. </label>
  80. {% elseif type == 'MULTIPOINT' or type == 'LINESTRING' %}
  81. {% set no_of_points = gis_data[a][type]['no_of_points'] ?? 1 %}
  82. {% if type == 'LINESTRING' and no_of_points < 2 %}
  83. {% set no_of_points = 2 %}
  84. {% endif %}
  85. {% if type == 'MULTIPOINT' and no_of_points < 1 %}
  86. {% set no_of_points = 1 %}
  87. {% endif %}
  88. {% if gis_data[a][type]['add_point'] is not null %}
  89. {% set no_of_points = no_of_points + 1 %}
  90. {% endif %}
  91. <input type="hidden" value="{{ no_of_points }}" name="gis_data[{{ a }}][{{ type }}][no_of_points]">
  92. {% for i in 0..no_of_points - 1 %}
  93. <br>
  94. {{ 'Point %d:'|trans|format(i + 1) }}
  95. <label>
  96. {% trans 'X' %}
  97. <input type="text" name="gis_data[{{ a }}][{{ type }}][{{ i }}][x]" value="{{ gis_data[a][type][i]['x'] }}">
  98. </label>
  99. <label>
  100. {% trans 'Y' %}
  101. <input type="text" name="gis_data[{{ a }}][{{ type }}][{{ i }}][y]" value="{{ gis_data[a][type][i]['y'] }}">
  102. </label>
  103. {% endfor %}
  104. <input type="submit" name="gis_data[{{ a }}][{{ type }}][add_point]" class="btn btn-secondary add addPoint" value="{% trans 'Add a point' %}">
  105. {% elseif type == 'MULTILINESTRING' or type == 'POLYGON' %}
  106. {% set no_of_lines = gis_data[a][type]['no_of_lines'] ?? 1 %}
  107. {% if no_of_lines < 1 %}
  108. {% set no_of_lines = 1 %}
  109. {% endif %}
  110. {% if gis_data[a][type]['add_line'] is not null %}
  111. {% set no_of_lines = no_of_lines + 1 %}
  112. {% endif %}
  113. <input type="hidden" value="{{ no_of_lines }}" name="gis_data[{{ a }}][{{ type }}][no_of_lines]">
  114. {% for i in 0..no_of_lines - 1 %}
  115. <br>
  116. {% if type == 'MULTILINESTRING' %}
  117. {{ 'Linestring %d:'|trans|format(i + 1) }}
  118. {% elseif i == 0 %}
  119. {% trans 'Outer ring:' %}
  120. {% else %}
  121. {{ 'Inner ring %d:'|trans|format(i) }}
  122. {% endif %}
  123. {% set no_of_points = gis_data[a][type][i]['no_of_points'] ?? 2 %}
  124. {% if type == 'MULTILINESTRING' and no_of_points < 2 %}
  125. {% set no_of_points = 2 %}
  126. {% endif %}
  127. {% if type == 'POLYGON' and no_of_points < 4 %}
  128. {% set no_of_points = 4 %}
  129. {% endif %}
  130. {% if gis_data[a][type][i]['add_point'] is not null %}
  131. {% set no_of_points = no_of_points + 1 %}
  132. {% endif %}
  133. <input type="hidden" value="{{ no_of_points }}" name="gis_data[{{ a }}][{{ type }}][{{ i }}][no_of_points]">
  134. {% for j in 0..no_of_points - 1 %}
  135. <br>
  136. {{ 'Point %d:'|trans|format(j + 1) }}
  137. <label>
  138. {% trans 'X' %}
  139. <input type="text" name="gis_data[{{ a }}][{{ type }}][{{ i }}][{{ j }}][x]" value="{{ gis_data[a][type][i][j]['x'] }}">
  140. </label>
  141. <label>
  142. {% trans 'Y' %}
  143. <input type="text" name="gis_data[{{ a }}][{{ type }}][{{ i }}][{{ j }}][y]" value="{{ gis_data[a][type][i][j]['y'] }}">
  144. </label>
  145. {% endfor %}
  146. <input type="submit" name="gis_data[{{ a }}][{{ type }}][{{ i }}][add_point]" class="btn btn-secondary add addPoint" value="{% trans 'Add a point' %}">
  147. {% endfor %}
  148. <br>
  149. <input type="submit" name="gis_data[{{ a }}][{{ type }}][add_line]" class="btn btn-secondary add addLine" value="
  150. {{- type == 'MULTILINESTRING' ? 'Add a linestring'|trans : 'Add an inner ring'|trans }}">
  151. {% elseif type == 'MULTIPOLYGON' %}
  152. {% set no_of_polygons = gis_data[a][type]['no_of_polygons'] ?? 1 %}
  153. {% if no_of_polygons < 1 %}
  154. {% set no_of_polygons = 1 %}
  155. {% endif %}
  156. {% if gis_data[a][type]['add_polygon'] is not null %}
  157. {% set no_of_polygons = no_of_polygons + 1 %}
  158. {% endif %}
  159. <input type="hidden" name="gis_data[{{ a }}][{{ type }}][no_of_polygons]" value="{{ no_of_polygons }}">
  160. {% for k in 0..no_of_polygons - 1 %}
  161. <br>
  162. {{ 'Polygon %d:'|trans|format(k + 1) }}
  163. {% set no_of_lines = gis_data[a][type][k]['no_of_lines'] ?? 1 %}
  164. {% if no_of_lines < 1 %}
  165. {% set no_of_lines = 1 %}
  166. {% endif %}
  167. {% if gis_data[a][type][k]['add_line'] is not null %}
  168. {% set no_of_lines = no_of_lines + 1 %}
  169. {% endif %}
  170. <input type="hidden" name="gis_data[{{ a }}][{{ type }}][{{ k }}][no_of_lines]" value="{{ no_of_lines }}">
  171. {% for i in 0..no_of_lines - 1 %}
  172. <br><br>
  173. {% if i == 0 %}
  174. {% trans 'Outer ring:' %}
  175. {% else %}
  176. {{ 'Inner ring %d:'|trans|format(i) }}
  177. {% endif %}
  178. {% set no_of_points = gis_data[a][type][k][i]['no_of_points'] ?? 4 %}
  179. {% if no_of_points < 4 %}
  180. {% set no_of_points = 4 %}
  181. {% endif %}
  182. {% if gis_data[a][type][k][i]['add_point'] is not null %}
  183. {% set no_of_points = no_of_points + 1 %}
  184. {% endif %}
  185. <input type="hidden" name="gis_data[{{ a }}][{{ type }}][{{ k }}][{{ i }}][no_of_points]" value="{{ no_of_points }}">
  186. {% for j in 0..no_of_points - 1 %}
  187. <br>
  188. {{ 'Point %d:'|trans|format(j + 1) }}
  189. <label>
  190. {% trans 'X' %}
  191. <input type="text" name="gis_data[{{ a }}][{{ type }}][{{ k }}][{{ i }}][{{ j }}][x]" value="{{ gis_data[a][type][k][i][j]['x'] }}">
  192. </label>
  193. <label>
  194. {% trans 'Y' %}
  195. <input type="text" name="gis_data[{{ a }}][{{ type }}][{{ k }}][{{ i }}][{{ j }}][y]" value="{{ gis_data[a][type][k][i][j]['y'] }}">
  196. </label>
  197. {% endfor %}
  198. <input type="submit" name="gis_data[{{ a }}][{{ type }}][{{ k }}][{{ i }}][add_point]" class="btn btn-secondary add addPoint" value="{% trans 'Add a point' %}">
  199. {% endfor %}
  200. <br>
  201. <input type="submit" name="gis_data[{{ a }}][{{ type }}][{{ k }}][add_line]" class="btn btn-secondary add addLine" value="{% trans 'Add an inner ring' %}">
  202. <br>
  203. {% endfor %}
  204. <br>
  205. <input type="submit" name="gis_data[{{ a }}][{{ type }}][add_polygon]" class="btn btn-secondary add addPolygon" value="{% trans 'Add a polygon' %}">
  206. {% endif %}
  207. {% endif %}
  208. {% endfor %}
  209. {% if geom_type == 'GEOMETRYCOLLECTION' %}
  210. <br><br>
  211. <input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]" class="btn btn-secondary add addGeom" value="{% trans 'Add geometry' %}">
  212. {% endif %}
  213. </div>
  214. {# End of data section #}
  215. <br>
  216. <input class="btn btn-primary" type="submit" name="gis_data[save]" value="{% trans 'Go' %}">
  217. <div id="gis_data_output">
  218. <h3>{% trans 'Output' %}</h3>
  219. <p>
  220. {% trans 'Choose "GeomFromText" from the "Function" column and paste the string below into the "Value" field.' %}
  221. </p>
  222. <textarea id="gis_data_textarea" rows="5">{{ result }}</textarea>
  223. </div>
  224. </div>
  225. </form>