diff options
Diffstat (limited to 'webapp/django/contrib/gis/templates/gis/admin')
4 files changed, 198 insertions, 0 deletions
diff --git a/webapp/django/contrib/gis/templates/gis/admin/openlayers.html b/webapp/django/contrib/gis/templates/gis/admin/openlayers.html new file mode 100644 index 0000000000..acf82b284e --- /dev/null +++ b/webapp/django/contrib/gis/templates/gis/admin/openlayers.html @@ -0,0 +1,37 @@ +{% block extrastyle %} +<style type="text/css"> + #{{ id }}_map { width: {{ map_width }}px; height: {{ map_height }}px; } + #{{ id }}_map .aligned label { float:inherit; } + #{{ id }}_admin_map { position: relative; vertical-align: top; float: left; } + {% if not display_wkt %}#{{ id }} { display: none; }{% endif %} + .olControlEditingToolbar .olControlModifyFeatureItemActive { + background-image: url("{{ admin_media_prefix }}img/gis/move_vertex_on.png"); + background-repeat: no-repeat; + } + .olControlEditingToolbar .olControlModifyFeatureItemInactive { + background-image: url("{{ admin_media_prefix }}img/gis/move_vertex_off.png"); + background-repeat: no-repeat; + } +</style> +<!--[if IE]> +<style type="text/css"> + /* This fixes the the mouse offset issues in IE. */ + #{{ id }}_admin_map { position: static; vertical-align: top; } + /* `font-size: 0` fixes the 1px border between tiles, but borks LayerSwitcher. + Thus, this is disabled until a better fix is found. + #{{ id }}_map { width: {{ map_width }}px; height: {{ map_height }}px; font-size: 0; } */ +</style> +<![endif]--> +{% endblock %} +<span id="{{ id }}_admin_map"> +<script type="text/javascript"> +//<![CDATA[ +{% block openlayers %}{% include "gis/admin/openlayers.js" %}{% endblock %} +//]]> +</script> +<div id="{{ id }}_map"></div> +<a href="javascript:{{ module }}.clearFeatures()">Delete all Features</a> +{% if display_wkt %}<p> WKT debugging window:</p>{% endif %} +<textarea id="{{ id }}" class="vWKTField required" cols="150" rows="10" name="{{ field_name }}">{{ wkt }}</textarea> +<script type="text/javascript">{% block init_function %}{{ module }}.init();{% endblock %}</script> +</span> diff --git a/webapp/django/contrib/gis/templates/gis/admin/openlayers.js b/webapp/django/contrib/gis/templates/gis/admin/openlayers.js new file mode 100644 index 0000000000..719426127c --- /dev/null +++ b/webapp/django/contrib/gis/templates/gis/admin/openlayers.js @@ -0,0 +1,157 @@ +{# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #} +{% block vars %}var {{ module }} = {}; +{{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\d+;(.+)", "i"); {{ module }}.layers = {}; +{{ module }}.wkt_f = new OpenLayers.Format.WKT(); +{{ module }}.is_collection = {% if is_collection %}true{% else %}false{% endif %}; +{{ module }}.collection_type = '{{ collection_type }}'; +{{ module }}.is_linestring = {% if is_linestring %}true{% else %}false{% endif %}; +{{ module }}.is_polygon = {% if is_polygon %}true{% else %}false{% endif %}; +{{ module }}.is_point = {% if is_point %}true{% else %}false{% endif %}; +{% endblock %} +{{ module }}.get_ewkt = function(feat){return 'SRID={{ srid }};' + {{ module }}.wkt_f.write(feat);} +{{ module }}.read_wkt = function(wkt){ + // OpenLayers cannot handle EWKT -- we make sure to strip it out. + // EWKT is only exposed to OL if there's a validation error in the admin. + var match = {{ module }}.re.exec(wkt); + if (match){wkt = match[1];} + return {{ module }}.wkt_f.read(wkt); +} +{{ module }}.write_wkt = function(feat){ + if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;} + else { {{ module }}.num_geom = 1;} + document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat); +} +{{ module }}.add_wkt = function(event){ + // This function will sync the contents of the `vector` layer with the + // WKT in the text field. + if ({{ module }}.is_collection){ + var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); + for (var i = 0; i < {{ module }}.layers.vector.features.length; i++){ + feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); + } + {{ module }}.write_wkt(feat); + } else { + // Make sure to remove any previously added features. + if ({{ module }}.layers.vector.features.length > 1){ + old_feats = [{{ module }}.layers.vector.features[0]]; + {{ module }}.layers.vector.removeFeatures(old_feats); + {{ module }}.layers.vector.destroyFeatures(old_feats); + } + {{ module }}.write_wkt(event.feature); + } +} +{{ module }}.modify_wkt = function(event){ + if ({{ module }}.is_collection){ + if ({{ module }}.is_point){ + {{ module }}.add_wkt(event); + return; + } else { + // When modifying the selected components are added to the + // vector layer so we only increment to the `num_geom` value. + var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); + for (var i = 0; i < {{ module }}.num_geom; i++){ + feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); + } + {{ module }}.write_wkt(feat); + } + } else { + {{ module }}.write_wkt(event.feature); + } +} +// Function to clear vector features and purge wkt from div +{{ module }}.deleteFeatures = function(){ + {{ module }}.layers.vector.removeFeatures({{ module }}.layers.vector.features); + {{ module }}.layers.vector.destroyFeatures(); +} +{{ module }}.clearFeatures = function (){ + {{ module }}.deleteFeatures(); + document.getElementById('{{ id }}').value = ''; + {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }}); +} +// Add Select control +{{ module }}.addSelectControl = function(){ + var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true}); + {{ module }}.map.addControl(select); + select.activate(); +} +{{ module }}.enableDrawing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.DrawFeature')[0].activate();} +{{ module }}.enableEditing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.ModifyFeature')[0].activate();} +// Create an array of controls based on geometry type +{{ module }}.getControls = function(lyr){ + {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'}); + var nav = new OpenLayers.Control.Navigation(); + var draw_ctl; + if ({{ module }}.is_linestring){ + draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}); + } else if ({{ module }}.is_polygon){ + draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'}); + } else if ({{ module }}.is_point){ + draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}); + } + {% if modifiable %} + var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'}); + {{ module }}.controls = [nav, draw_ctl, mod]; + {% else %} + {{ module }}.controls = [nav, darw_ctl]; + {% endif %} +} +{{ module }}.init = function(){ + {% block map_options %}// The options hash, w/ zoom, resolution, and projection settings. + var options = { +{% autoescape off %}{% for item in map_options.items %} '{{ item.0 }}' : {{ item.1 }}{% if not forloop.last %},{% endif %} +{% endfor %}{% endautoescape %} };{% endblock %} + // The admin map for this geometry field. + {{ module }}.map = new OpenLayers.Map('{{ id }}_map', options); + // Base Layer + {{ module }}.layers.base = {% block base_layer %}new OpenLayers.Layer.WMS( "{{ wms_name }}", "{{ wms_url }}", {layers: '{{ wms_layer }}'} );{% endblock %} + {{ module }}.map.addLayer({{ module }}.layers.base); + {% block extra_layers %}{% endblock %} + {% if is_linestring %}OpenLayers.Feature.Vector.style["default"]["strokeWidth"] = 3; // Default too thin for linestrings. {% endif %} + {{ module }}.layers.vector = new OpenLayers.Layer.Vector(" {{ field_name }}"); + {{ module }}.map.addLayer({{ module }}.layers.vector); + // Read WKT from the text field. + var wkt = document.getElementById('{{ id }}').value; + if (wkt){ + // After reading into geometry, immediately write back to + // WKT <textarea> as EWKT (so that SRID is included). + var admin_geom = {{ module }}.read_wkt(wkt); + {{ module }}.write_wkt(admin_geom); + if ({{ module }}.is_collection){ + // If geometry collection, add each component individually so they may be + // edited individually. + for (var i = 0; i < {{ module }}.num_geom; i++){ + {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]); + } + } else { + {{ module }}.layers.vector.addFeatures([admin_geom]); + } + // Zooming to the bounds. + {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds()); + } else { + {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }}); + } + // This allows editing of the geographic fields -- the modified WKT is + // written back to the content field (as EWKT, so that the ORM will know + // to transform back to original SRID). + {{ module }}.layers.vector.events.on({"featuremodified" : {{ module }}.modify_wkt}); + {{ module }}.layers.vector.events.on({"featureadded" : {{ module }}.add_wkt}); + {% block controls %} + // Map controls: + // Add geometry specific panel of toolbar controls + {{ module }}.getControls({{ module }}.layers.vector); + {{ module }}.panel.addControls({{ module }}.controls); + {{ module }}.map.addControl({{ module }}.panel); + {{ module }}.addSelectControl(); + // Then add optional visual controls + {% if mouse_position %}{{ module }}.map.addControl(new OpenLayers.Control.MousePosition());{% endif %} + {% if scale_text %}{{ module }}.map.addControl(new OpenLayers.Control.Scale());{% endif %} + {% if layerswitcher %}{{ module }}.map.addControl(new OpenLayers.Control.LayerSwitcher());{% endif %} + // Then add optional behavior controls + {% if scrollable %}{% else %}{{ module }}.map.getControlsByClass('OpenLayers.Control.Navigation')[0].disableZoomWheel();{% endif %} + {% endblock %} + if (wkt){ + {{ module }}.enableEditing(); + } else { + {{ module }}.enableDrawing(); + } +} diff --git a/webapp/django/contrib/gis/templates/gis/admin/osm.html b/webapp/django/contrib/gis/templates/gis/admin/osm.html new file mode 100644 index 0000000000..b74b41fee8 --- /dev/null +++ b/webapp/django/contrib/gis/templates/gis/admin/osm.html @@ -0,0 +1,2 @@ +{% extends "gis/admin/openlayers.html" %} +{% block openlayers %}{% include "gis/admin/osm.js" %}{% endblock %}
\ No newline at end of file diff --git a/webapp/django/contrib/gis/templates/gis/admin/osm.js b/webapp/django/contrib/gis/templates/gis/admin/osm.js new file mode 100644 index 0000000000..2a1f59e4d3 --- /dev/null +++ b/webapp/django/contrib/gis/templates/gis/admin/osm.js @@ -0,0 +1,2 @@ +{% extends "gis/admin/openlayers.js" %} +{% block base_layer %}new OpenLayers.Layer.OSM.Mapnik("OpenStreetMap (Mapnik)");{% endblock %} |