Ticket #13926: osm_ol_admin.django-1.5.1.diff

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

Patch updated for the Django 1.5.1 release

  • openlayers.js

    diff --git a/openlayers.js b/openlayers.js
    index eb40eda..813756b 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 
    1014{{ module }}.is_polygon = {{ is_polygon|yesno:"true,false" }};
    1115{{ module }}.is_point = {{ is_point|yesno:"true,false" }};
    1216{% endblock %}
    13 {{ module }}.get_ewkt = function(feat){return 'SRID={{ srid }};' + {{ module }}.wkt_f.write(feat);}
     17// Patch for http://trac.osgeo.org/openlayers/ticket/2240
     18{{ module }}.get_ewkt = function(feat){
     19  if (feat.constructor == Array) {
     20    wkts = [];
     21    for(var i = 0; i < feat.length; i++){
     22      wkts.push(feat[i].geometry.toString());
     23    }
     24    return 'SRID={{ srid }};GEOMETRYCOLLECTION(' + wkts.join(', ') + ')';
     25  } else if (feat.geometry.CLASS_NAME == 'OpenLayers.Geometry.Collection') {
     26    wkts = [];
     27    for (var i=0; i < feat.geometry.components.length; i++){
     28      wkts.push(feat.geometry.components[i].toString());
     29    }
     30    return 'SRID={{ srid }};GEOMETRYCOLLECTION(' + wkts.join(', ') + ')';
     31  } else {
     32    return 'SRID={{ srid }};' + {{ module }}.wkt_f.write(feat);
     33  }
     34}
    1435{{ module }}.read_wkt = function(wkt){
    1536  // OpenLayers cannot handle EWKT -- we make sure to strip it out.
    1637  // EWKT is only exposed to OL if there's a validation error in the admin.
    OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    1940  return {{ module }}.wkt_f.read(wkt);
    2041}
    2142{{ module }}.write_wkt = function(feat){
    22   if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;}
    23   else { {{ module }}.num_geom = 1;}
     43  if ({{ module }}.is_collection){
     44    if (feat.constructor == Array) {
     45      {{ module }}.num_geom = feat.length;
     46    } else {
     47      {{ module }}.num_geom = feat.geometry.components.length;
     48    }
     49  } else {
     50    {{ module }}.num_geom = 1;
     51  }
    2452  document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat);
    2553}
    2654{{ module }}.add_wkt = function(event){
    2755  // This function will sync the contents of the `vector` layer with the
    2856  // WKT in the text field.
    2957  if ({{ module }}.is_collection){
     58    if ({{ module }}.collection_type == 'Any') {
     59      var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Collection());
     60    } else {
    3061    var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}());
     62    }
    3163    for (var i = 0; i < {{ module }}.layers.vector.features.length; i++){
    3264      feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]);
    3365    }
    OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    5082    } else {
    5183      // When modifying the selected components are added to the
    5284      // vector layer so we only increment to the `num_geom` value.
     85      if ({{ module }}.collection_type == 'Any') {
     86        var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Collection());
     87      } else {
    5388      var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}());
     89      }
    5490      for (var i = 0; i < {{ module }}.num_geom; i++){
    5591        feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]);
    5692      }
    OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    84120{{ module }}.getControls = function(lyr){
    85121  {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'});
    86122  var nav = new OpenLayers.Control.Navigation();
    87   var draw_ctl;
    88   if ({{ module }}.is_linestring){
    89     draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'});
    90   } else if ({{ module }}.is_polygon){
    91     draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'});
    92   } else if ({{ module }}.is_point){
    93     draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'});
     123  var draw_ctl = [];
     124  if ({{ module }}.is_linestring || {{ module }}.is_collection){
     125    draw_ctl.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}));
     126  }
     127  if ({{ module }}.is_polygon || {{ module }}.is_collection){
     128    draw_ctl.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'}));
     129  }
     130  if ({{ module }}.is_point|| {{ module }}.is_collection){
     131    draw_ctl.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}));
    94132  }
     133  var ctls = draw_ctl;
    95134  if ({{ module }}.modifiable){
    96135    var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'});
    97     {{ module }}.controls = [nav, draw_ctl, mod];
     136    ctls.splice(0, 0, nav);
     137    ctls.push(mod);
    98138  } else {
    99139    if(!lyr.features.length){
    100       {{ module }}.controls = [nav, draw_ctl];
     140      ictls.splice(0, 0, nav);
    101141    } else {
    102       {{ module }}.controls = [nav];
     142      ctls = [nav];
    103143    }
    104144  }
     145  {{ module }}.controls = ctls;
    105146}
     147
    106148{{ module }}.init = function(){
    107149    {% block map_options %}// The options hash, w/ zoom, resolution, and projection settings.
    108150    var options = {
    OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    129171      if ({{ module }}.is_collection){
    130172        // If geometry collection, add each component individually so they may be
    131173        // edited individually.
     174        if ({{ module }}.collection_type == 'Any') {
     175          {{ module }}.layers.vector.addFeatures(admin_geom);
     176          var admin_bounds = new OpenLayers.Bounds();
     177          for(var i = 0; i < {{ module }}.num_geom; i++){
     178            admin_bounds.extend(admin_geom[i].geometry.getBounds());
     179          }
     180        } else {
    132181        for (var i = 0; i < {{ module }}.num_geom; i++){
    133182          {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]);
    134183        }
     184          var admin_bounds = admin_geom.geometry.getBounds();
     185        }
    135186      } else {
    136187        {{ module }}.layers.vector.addFeatures([admin_geom]);
     188        var admin_bounds = admin_geom.geometry.getBounds();
    137189      }
    138190      // Zooming to the bounds.
    139       {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds());
     191      {{ module }}.map.zoomToExtent(admin_bounds);
    140192      if ({{ module }}.is_point){
    141193          {{ module }}.map.zoomTo({{ point_zoom }});
    142194      }
Back to Top