Ticket #13926: osm_ol_admin.django-20130706.diff

File osm_ol_admin.django-20130706.diff, 6.2 KB (added by Antti Kaihola, 6 years ago)

Patch updated for current Django trunk

  • django/contrib/gis/templates/gis/admin/openlayers.js

    diff --git a/django/contrib/gis/templates/gis/admin/openlayers.js b/django/contrib/gis/templates/gis/admin/openlayers.js
    index 4425fee..232c8c7 100644
    a b  
    11{% load l10n %}
    22OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.SphericalMercator.projectForward);
    33{% block vars %}var {{ module }} = {};
    4 {{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\\d+;(.+)", "i"); {{ module }}.layers = {};
     4{{ module }}.map = null;
     5{{ module }}.controls = null;
     6{{ module }}.panel = null;
     7{{ module }}.re = new RegExp("^SRID=\\d+;(.+)", "i");
     8{{ module }}.layers = {};
    59{{ module }}.modifiable = {{ modifiable|yesno:"true,false" }};
    610{{ module }}.wkt_f = new OpenLayers.Format.WKT();
    711{{ module }}.is_collection = {{ is_collection|yesno:"true,false" }};
    OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    1115{{ module }}.is_polygon = {{ is_polygon|yesno:"true,false" }};
    1216{{ module }}.is_point = {{ is_point|yesno:"true,false" }};
    1317{% endblock %}
     18// Patch for http://trac.osgeo.org/openlayers/ticket/2240
    1419{{ module }}.get_ewkt = function(feat){
    15   return 'SRID={{ srid|unlocalize }};' + {{ module }}.wkt_f.write(feat);
     20  if (feat.constructor == Array) {
     21    wkts = [];
     22    for(var i = 0; i < feat.length; i++){
     23      wkts.push(feat[i].geometry.toString());
     24    }
     25    return 'SRID={{ srid|unlocalize }};GEOMETRYCOLLECTION(' + wkts.join(', ') + ')';
     26  } else if (feat.geometry.CLASS_NAME == 'OpenLayers.Geometry.Collection') {
     27    wkts = [];
     28    for (var i=0; i < feat.geometry.components.length; i++){
     29      wkts.push(feat.geometry.components[i].toString());
     30    }
     31    return 'SRID={{ srid|unlocalize }};GEOMETRYCOLLECTION(' + wkts.join(', ') + ')';
     32  } else {
     33    return 'SRID={{ srid|unlocalize }};' + {{ module }}.wkt_f.write(feat);
     34  }
    1635};
    1736{{ module }}.read_wkt = function(wkt){
    1837  // OpenLayers cannot handle EWKT -- we make sure to strip it out.
    OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    2241  return {{ module }}.wkt_f.read(wkt);
    2342};
    2443{{ module }}.write_wkt = function(feat){
    25   if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;}
    26   else { {{ module }}.num_geom = 1;}
     44  if ({{ module }}.is_collection){
     45    if (feat.constructor == Array) {
     46      {{ module }}.num_geom = feat.length;
     47    } else {
     48      {{ module }}.num_geom = feat.geometry.components.length;
     49    }
     50  } else {
     51    {{ module }}.num_geom = 1;
     52  }
    2753  document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat);
    2854};
    2955{{ module }}.add_wkt = function(event){
    OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    5379    } else {
    5480      // When modifying the selected components are added to the
    5581      // vector layer so we only increment to the `num_geom` value.
    56       var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}());
     82      if ({{ module }}.collection_type == 'Any') {
     83        var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Collection());
     84      } else {
     85        var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}());
     86      }
    5787      for (var i = 0; i < {{ module }}.num_geom; i++){
    5888        feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]);
    5989      }
    OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    92122  {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'});
    93123  {{ module }}.controls = [new OpenLayers.Control.Navigation()];
    94124  if (!{{ module }}.modifiable && lyr.features.length) return;
    95   if ({{ module }}.is_linestring || {{ module }}.is_generic){
     125  if ({{ module }}.is_linestring || {{ module }}.is_generic || {{ module }}.is_collection){
    96126    {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}));
    97127  }
    98   if ({{ module }}.is_polygon || {{ module }}.is_generic){
     128  if ({{ module }}.is_polygon || {{ module }}.is_generic || {{ module }}.is_collection){
    99129    {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'}));
    100130  }
    101   if ({{ module }}.is_point || {{ module }}.is_generic){
     131  if ({{ module }}.is_point || {{ module }}.is_generic || {{ module }}.is_collection){
    102132    {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}));
    103133  }
    104134  if ({{ module }}.modifiable){
    OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    131161      if ({{ module }}.is_collection){
    132162        // If geometry collection, add each component individually so they may be
    133163        // edited individually.
    134         for (var i = 0; i < {{ module }}.num_geom; i++){
    135           {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]);
     164        if ({{ module }}.collection_type == 'Any') {
     165          {{ module }}.layers.vector.addFeatures(admin_geom);
     166          var admin_bounds = new OpenLayers.Bounds();
     167          for(var i = 0; i < {{ module }}.num_geom; i++){
     168            admin_bounds.extend(admin_geom[i].geometry.getBounds());
     169          }
     170        } else {
     171          for (var i = 0; i < {{ module }}.num_geom; i++){
     172            {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]);
     173          }
     174          var admin_bounds = admin_geom.geometry.getBounds();
    136175        }
    137176      } else {
    138177        {{ module }}.layers.vector.addFeatures([admin_geom]);
     178        var admin_bounds = admin_geom.geometry.getBounds();
    139179      }
    140180      // Zooming to the bounds.
    141       {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds());
     181      {{ module }}.map.zoomToExtent(admin_bounds);
    142182      if ({{ module }}.is_point){
    143183          {{ module }}.map.zoomTo({{ point_zoom }});
    144184      }
Back to Top