OpenLayers OpenLayers

Ticket #1406: wfs_reprojection.patch

File wfs_reprojection.patch, 6.3 kB (added by crschmidt, 10 months ago)
  • lib/OpenLayers/Layer/WFS.js

    old new  
    277277         
    278278            var params = {BBOX: this.encodeBBOX ? tileBounds.toBBOX()  
    279279                                                : tileBounds.toArray()}; 
     280             
     281            if (this.map && !this.projection.equals(this.map.getProjectionObject())) { 
     282                var projectedBounds = tileBounds.clone(); 
     283                projectedBounds.transform(this.map.getProjectionObject(),  
     284                                          this.projection); 
     285                params.BBOX = this.encodeBBOX ? projectedBounds.toBBOX()  
     286                                              : projectedBounds.toArray(); 
     287            }                                   
     288 
    280289            url += "&" + OpenLayers.Util.getParameterString(params); 
    281290 
    282291            if (!this.tile) { 
     
    434443     */ 
    435444    commit: function() { 
    436445        if (!this.writer) { 
    437             this.writer = new OpenLayers.Format.WFS({},this); 
     446            var options = {}; 
     447            if (this.map && !this.projection.equals(this.map.getProjectionObject())) { 
     448                options.externalProjection = this.projection; 
     449                options.internalProjection = this.map.getProjectionObject(); 
     450            }     
     451             
     452            this.writer = new OpenLayers.Format.WFS(options,this); 
    438453        } 
    439454 
    440455        var data = this.writer.write(this.features); 
  • examples/proxy.cgi

    old new  
    1818allowedHosts = ['www.openlayers.org', 'openlayers.org',  
    1919                'labs.metacarta.com', 'world.freemap.in',  
    2020                'prototype.openmnnd.org', 'geo.openplans.org', 
     21                'geo.openplans.org:8080', 
    2122                'www.openstreetmap.org'] 
    2223 
    2324method = os.environ["REQUEST_METHOD"] 
  • examples/wfs-reprojection.html

    old new  
     1<html xmlns="http://www.w3.org/1999/xhtml"> 
     2  <head> 
     3    <link rel="stylesheet" href="../theme/default/style.css" type="text/css" /> 
     4    <style type="text/css"> 
     5        #map { 
     6            width: 512px; 
     7            height: 512px; 
     8            border: 1px solid black; 
     9        } 
     10    </style> 
     11    <script src="../lib/OpenLayers.js"></script> 
     12    <script src='http://maps.google.com/maps?file=api&amp;v=2.82&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script> 
     13    <script type="text/javascript"> 
     14        var map, layer; 
     15        OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url="; 
     16        function init(){ 
     17            map = new OpenLayers.Map('map', { 
     18                projection: new OpenLayers.Projection("EPSG:900913"), 
     19                displayProjection: new OpenLayers.Projection("EPSG:4326"), 
     20                units: "m", 
     21                maxResolution: 156543.0339, 
     22                maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 
     23                                                 20037508.34, 20037508.34) 
     24            }); 
     25            layer = new OpenLayers.Layer.Google( "G", 
     26                    {sphericalMercator: true} ); 
     27            map.addLayer(layer); 
     28            layer = new OpenLayers.Layer.WFS( "States", 
     29                    "http://geo.openplans.org:8080/geoserver/ows", {typename: 'topp:states'}, 
     30               { 
     31                      typename: 'states', 
     32                      featureNS: 'http://www.openplans.org/topp', 
     33                      projection: new OpenLayers.Projection("EPSG:4326"), 
     34                      extractAttributes: false, 
     35                      ratio: 1.2 
     36               } ); 
     37            map.addLayer(layer); 
     38            map.addControl(new OpenLayers.Control.LayerSwitcher()); 
     39 
     40            map.zoomToExtent(new OpenLayers.Bounds( 
     41              -73.839111,40.287907,-68.214111,44.441624). 
     42              transform(map.displayProjection, map.getProjectionObject())); 
     43        } 
     44    </script> 
     45  </head> 
     46  <body onload="init()"> 
     47 
     48  <h1 id="title">WFS Reprojection Example</h1> 
     49 
     50  <div id="tags"> 
     51  </div> 
     52  <p id="shortdesc"> 
     53    Shows the use of the WFS layer reprojection support  
     54  </p> 
     55 
     56    <div id="map"></div> 
     57 
     58  <div id="docs"> 
     59    This example shows automatic WFS reprojection, displaying an 'unprojected' WFS layer projected on the client side over Google Maps. The key configuration here is the 'projection' option on the WFS layer.   
     60  </div> 
     61 
     62 
     63 
     64  </body> 
     65</html> 
     66 
     67 
  • examples/spherical-mercator.html

    old new  
    2424        OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; 
    2525        OpenLayers.Util.onImageLoadErrorColor = "transparent"; 
    2626 
     27        // Ability to load WFS data 
     28        OpenLayers.ProxyHost = '/proxy/?url='; 
     29 
    2730        function init(){ 
    2831            var options = { 
    2932                projection: new OpenLayers.Projection("EPSG:900913"), 
     
    110113                    'isBaseLayer': false,'wrapDateLine': true 
    111114                } 
    112115            ); 
     116            // create WFS layer, which is in EPSG:4326 
     117            wfs = new OpenLayers.Layer.WFS("WFS",  
     118              "http://featureserver.org/featureserver.cgi/scribble?format=WFS", 
     119              {maxfeatures: "50"},  
     120              { 
     121                extractAttributes: true,  
     122                projection: new OpenLayers.Projection("EPSG:4326") 
     123               } 
     124            ); 
    113125 
    114126            // create a vector layer for drawing 
    115127            var vector = new OpenLayers.Layer.Vector("Editable Vectors"); 
    116128 
    117129            map.addLayers([gmap, gsat, ghyb, veroad, veaer, vehyb, 
    118130                           yahoo, yahoosat, yahoohyb, mapnik, osmarender, 
    119                            wms, vector]); 
     131                           wms, vector, wfs]); 
    120132            map.addControl(new OpenLayers.Control.LayerSwitcher()); 
    121133            map.addControl(new OpenLayers.Control.EditingToolbar(vector)); 
    122134            map.addControl(new OpenLayers.Control.Permalink());