forms-api.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. .. _ref-gis-forms-api:
  2. ===================
  3. GeoDjango Forms API
  4. ===================
  5. .. module:: django.contrib.gis.forms
  6. :synopsis: GeoDjango forms API.
  7. .. versionadded:: 1.6
  8. GeoDjango provides some specialized form fields and widgets in order to visually
  9. display and edit geolocalized data on a map. By default, they use
  10. `OpenLayers`_-powered maps, with a base WMS layer provided by `Metacarta`_.
  11. .. _OpenLayers: http://openlayers.org/
  12. .. _Metacarta: http://metacarta.com/
  13. Field arguments
  14. ===============
  15. In addition to the regular :ref:`form field arguments <core-field-arguments>`,
  16. GeoDjango form fields take the following optional arguments.
  17. ``srid``
  18. ~~~~~~~~
  19. .. attribute:: Field.srid
  20. This is the SRID code that the field value should be transformed to. For
  21. example, if the map widget SRID is different from the SRID more generally
  22. used by your application or database, the field will automatically convert
  23. input values into that SRID.
  24. ``geom_type``
  25. ~~~~~~~~~~~~~
  26. .. attribute:: Field.geom_type
  27. You generally shouldn't have to set or change that attribute which should
  28. be setup depending on the field class. It matches the OpenGIS standard
  29. geometry name.
  30. Form field classes
  31. ==================
  32. ``GeometryField``
  33. ~~~~~~~~~~~~~~~~~
  34. .. class:: GeometryField
  35. ``PointField``
  36. ~~~~~~~~~~~~~~
  37. .. class:: PointField
  38. ``LineStringField``
  39. ~~~~~~~~~~~~~~~~~~~
  40. .. class:: LineStringField
  41. ``PolygonField``
  42. ~~~~~~~~~~~~~~~~
  43. .. class:: PolygonField
  44. ``MultiPointField``
  45. ~~~~~~~~~~~~~~~~~~~
  46. .. class:: MultiPointField
  47. ``MultiLineStringField``
  48. ~~~~~~~~~~~~~~~~~~~~~~~~
  49. .. class:: MultiLineStringField
  50. ``MultiPolygonField``
  51. ~~~~~~~~~~~~~~~~~~~~~
  52. .. class:: MultiPolygonField
  53. ``GeometryCollectionField``
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. .. class:: GeometryCollectionField
  56. Form widgets
  57. ============
  58. .. module:: django.contrib.gis.widgets
  59. :synopsis: GeoDjango widgets API.
  60. GeoDjango form widgets allow you to display and edit geographic data on a
  61. visual map.
  62. Note that none of the currently available widgets supports 3D geometries, hence
  63. geometry fields will fallback using a simple ``Textarea`` widget for such data.
  64. Widget attributes
  65. ~~~~~~~~~~~~~~~~~
  66. GeoDjango widgets are template-based, so their attributes are mostly different
  67. from other Django widget attributes.
  68. .. attribute:: BaseGeometryWidget.geom_type
  69. The OpenGIS geometry type, generally set by the form field.
  70. .. attribute:: BaseGeometryWidget.map_height
  71. .. attribute:: BaseGeometryWidget.map_width
  72. Height and width of the widget map (default is 400x600).
  73. .. attribute:: BaseGeometryWidget.map_srid
  74. SRID code used by the map (default is 4326).
  75. .. attribute:: BaseGeometryWidget.display_raw
  76. Boolean value specifying if a textarea input showing the serialized
  77. representation of the current geometry is visible, mainly for debugging
  78. purposes (default is ``False``).
  79. .. attribute:: BaseGeometryWidget.supports_3d
  80. Indicates if the widget supports edition of 3D data (default is ``False``).
  81. .. attribute:: BaseGeometryWidget.template_name
  82. The template used to render the map widget.
  83. You can pass widget attributes in the same manner that for any other Django
  84. widget. For example::
  85. from django.contrib.gis import forms
  86. class MyGeoForm(forms.Form):
  87. point = forms.PointField(widget=
  88. forms.OSMWidget(attrs={'map_width': 800, 'map_height': 500}))
  89. Widget classes
  90. ~~~~~~~~~~~~~~
  91. ``BaseGeometryWidget``
  92. .. class:: BaseGeometryWidget
  93. This is an abstract base widget containing the logic needed by subclasses.
  94. You cannot directly use this widget for a geometry field.
  95. Note that the rendering of GeoDjango widgets is based on a template,
  96. identified by the :attr:`template_name` class attribute.
  97. ``OpenLayersWidget``
  98. .. class:: OpenLayersWidget
  99. This is the default widget used by all GeoDjango form fields.
  100. ``template_name`` is ``gis/openlayers.html``.
  101. ``OSMWidget``
  102. .. class:: OSMWidget
  103. This widget uses an OpenStreetMap base layer (Mapnik) to display geographic
  104. objects on.
  105. ``template_name`` is ``gis/openlayers-osm.html``.