Ticket #13926: osm_ol_admin.diff

File osm_ol_admin.diff, 6.7 KB (added by elpaso66, 13 years ago)

New patch for django/contrib/gis/templates/gis/admin/openlayers.js, should apply on trunk.

  • openlayers.

    old new  
    11{% load l10n %}{# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #}
    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 = /^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" }};
     
    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.
     
    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    }
     
    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      }
     
    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'}));
    94129  }
     130  if ({{ module }}.is_point|| {{ module }}.is_collection){
     131    draw_ctl.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}));
     132  }
     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 = {
     
    127169      if ({{ module }}.is_collection){
    128170        // If geometry collection, add each component individually so they may be
    129171        // edited individually.
     172        if ({{ module }}.collection_type == 'Any') {
     173          {{ module }}.layers.vector.addFeatures(admin_geom);
     174          var admin_bounds = new OpenLayers.Bounds();
     175          for(var i = 0; i < {{ module }}.num_geom; i++){
     176            admin_bounds.extend(admin_geom[i].geometry.getBounds());
     177          }
     178        } else {
    130179        for (var i = 0; i < {{ module }}.num_geom; i++){
    131180          {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]);
    132181        }
     182          var admin_bounds = admin_geom.geometry.getBounds();
     183        }
    133184      } else {
    134185        {{ module }}.layers.vector.addFeatures([admin_geom]);
     186        var admin_bounds = admin_geom.geometry.getBounds();
    135187      }
    136188      // Zooming to the bounds.
    137       {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds());
     189      {{ module }}.map.zoomToExtent(admin_bounds);
    138190      if ({{ module }}.is_point){
    139191          {{ module }}.map.zoomTo({{ point_zoom }});
    140192      }
Back to Top