[OpenLayers-Users] OpenLayers with 900913 projection and drupal OpenLayers module

Stephen Woodbridge woodbri at swoodbridge.com
Thu Jan 10 13:39:20 PST 2013


Well, I think you need the:

	"SphericalMercator": true

But this also looks wrong:

         "projection": {
             "projCode": "EPSG:900913"
         },

This should be:

	projection: "EPSG:900913"

more inline below. I think whoever built the drupal code needs to fix this.

-Steve

On 1/10/2013 3:05 PM, Alexander Kocisky wrote:
> Hi Stephen,
>
> thanks for your quick reply, im actually using Drupal Openlayer module
> but i've got the options with which the map is created, the code:
>
> ...
>
> // Initialize openlayers map
>              var openlayers = new OpenLayers.Map(map.id <http://map.id>,
> options);
>              alert("The map: "+map.id <http://map.id>+" options are:
> "+JSON.stringify(options, null, 4));
>
>              // Run the layer addition first
>              Drupal.openlayers.addLayers(map, openlayers);
>
>              // Attach data to map DOM object
>              $(this).data('openlayers', {'map': map, 'openlayers':
> openlayers});
>
>              // Finally, attach behaviors
>              Drupal.attachBehaviors(this);
>
> ...
>
> The output:
>
> The map: openlayers-map-a47c4de7 options are: {
>      "projection": {
>          "projCode": "EPSG:900913"
>      },

This looks wrong: it should just be:
	"projection": "EPSG:900913",

>      "displayProjection": {
>          "projCode": "EPSG:4326"
>      },

This looks wrong: it should just be:
	"displayProjection": "EPSG:4326",

>      "maxExtent": {
>          "left": -20037508.34,
>          "bottom": -20037508.34,
>          "right": 20037508.34,
>          "top": 20037508.34
>      },
>      "units": "m",
>      "maxResolution": "auto",
>      "controls": [],
>      "theme": "/sites/all/modules/openlayers/themes/default_dark/style.css"
> }
>
> Here is how drupal adds the layers:
>
> 'addLayers': function(map, openlayers) {
>
>      var sorted = [];
>      for (var name in map.layers) {
>        sorted.push({'name': name, 'weight': map.layers[name].weight,
> 'baselayer': map.layers[name].baselayer });
>      }
>
>      sorted.sort(function(a, b) {
>        var x = parseInt(a.weight, 10), y = parseInt(b.weight, 10);
>        return ((a.baselayer && x < y) ? -1 : ((b.baselayer || x > y) ? 1
> : 0));
>      });
>
>      for (var i = 0; i < sorted.length; ++i) {
>        var layer,
>          name = sorted[i].name,
>          options = map.layers[name];
>
>        // Add reference to our layer ID
>        options.drupalID = name;
>        // Ensure that the layer handler is available
>        if (options.layer_handler !== undefined &&
>          Drupal.openlayers.layer[options.layer_handler] !== undefined) {
>          var layer =
> Drupal.openlayers.layer[options.layer_handler](map.layers[name].title,
> map, options);
>
>          layer.visibility = !!(!map.layer_activated ||
> map.layer_activated[name]);
>
>          if (layer.isBaseLayer === false) {
>            layer.displayInLayerSwitcher = (!map.layer_switcher ||
> map.layer_switcher[name]);
>          }
>
>          if (map.center.wrapdateline === '1') {
>            // TODO: move into layer specific settings
>            layer.wrapDateLine = true;
>          }
>
>          alert("The layer is "+JSON.stringify(map.layers, null, 4));
>          openlayers.addLayer(layer);
>        }
>      }
>
> and here is the result of the layer options:
>
> The layer is {
>      "my_wms_layer": {
>          "base_url":
> "http://gis.site.org:8080/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=MyMap:my_layer",
>          "params": {
>              "isBaseLayer": 0,
>              "buffer": 2,
>              "ratio": 1.5,
>              "singleTile": 0,
>              "resolutions": [
>                  156543.0339,
>                  78271.51695,
>                  39135.758475,
>                  19567.8792375,
>                  9783.93961875,
>                  4891.969809375,
>                  2445.9849046875,
>                  1222.9924523438,
>                  611.49622617188,
>                  305.74811308594,
>                  152.87405654297,
>                  76.437028271484,
>                  38.218514135742,
>                  19.109257067871,
>                  9.5546285339355,
>                  4.7773142669678,
>                  2.3886571334839,
>                  1.1943285667419,
>                  0.59716428337097
>              ],
>              "projection": {
>                  "projCode": "EPSG:900913"
>              },

This projection is wrong and should be like above.

>              "maxextent": [
>                  -20037508,
>                  -20037508,
>                  20037508,
>                  20037508
>              ],
>              "drupalID": "my_wms_layer",
>              "units": "m",
>              "maxExtent": {
>                  "left": -20037508.34,
>                  "bottom": -20037508.34,
>                  "right": 20037508.34,
>                  "top": 20037508.34
>              }
>          },
>          "options": {
>              ...rname": "world-bright",
>          "layer_type": "openlayers_layer_type_mapbox",
>          "osm": false,
>          "baselayer": true,
>          "type": "png",
>          "resolutions": [
>              156543.0339,
>              78271.51695,
>              39135.758475,
>              19567.8792375,
>              9783.93961875,
>              4891.969809375,
>              2445.9849046875,
>              1222.9924523438,
>              611.49622617188,
>              305.74811308594,
>              152.87405654297,
>              76.437028271484
>          ],
>          "projection": {
>              "projCode": "EPSG:900913"
>          },

Same problem here with projection.

>          "serverResolutions": [
>              156543.0339,
>              78271.51695,
>              39135.758475,
>              19567.8792375,
>              9783.93961875,
>              4891.969809375,
>              2445.9849046875,
>              1222.9924523438,
>              611.49622617188,
>              305.74811308594,
>              152.87405654297,
>              76.437028271484,
>              38.218514135742,
>              19.109257067871,
>              9.5546285339355,
>              4.7773142669678,
>              2.3886571334839,
>              1.1943285667419,
>              0.59716428337097
>          ],
>          "maxExtent": {
>              "left": -20037508,
>              "bottom": -20037508,
>              "right": 20037508,
>              "top": 20037508
>          },
>          "layer_handler": "MapBox",
>          "title": "MapBox World Bright",
>          "weight": 0,
>          "drupalID": "mapbox_world_bright",
>          "isBaseLayer": true
>      }
> }
>
> so it seems that "SphericalMercator: true" is missing in both the map
> and the layer (my_wms_layer), would you say this is the reason of why
> the WMS bound box parameter is incorrect when open layer fetches the
> different png images of the map?
>
> Thanks !!
> Alex
>
>
> On 9 January 2013 18:14, Gery . <gamejihou at hotmail.com
> <mailto:gamejihou at hotmail.com>> wrote:
>
>
>      > "Peru WMS",
>
>     cool =)
>     __________________________________________________________________________________________
>     Piensa en el medio ambiente - mantenlo en la pantalla. NO lo
>     imprimas si NO es necesario.
>     Think green - keep it on the screen. Do NOT print if it is NOT
>     necessary.
>     Denken Sie an die Umwelt- bewahren Sie es auf dem Bildschirm.
>     Drucken Sie NICHT, wenn es NICHT notwendig ist.
>
>
>      > Date: Wed, 9 Jan 2013 17:57:53 -0500
>      > From: woodbri at swoodbridge.com <mailto:woodbri at swoodbridge.com>
>      > To: openlayers-users at lists.osgeo.org
>     <mailto:openlayers-users at lists.osgeo.org>
>      > Subject: Re: [OpenLayers-Users] OpenLayers with 900913 projection
>     and drupal OpenLayers module
>
>      >
>      > On 1/9/2013 5:49 PM, Alexander Kocisky wrote:
>      > > Hi all,
>      > >
>      > > I've set up a Geoserver/PostGIS infrastructure in order to render a
>      > > database of GIS information. Initially i was working with the
>     projection
>      > > 4326 but when i've installed Drupal + OpenLayers i've realized that
>      > > there are almost no tiles with this projection, the way to go
>     seems the
>      > > projection 900913.
>      > >
>      > > So i've converted all my gis objects to 900913, verified that i
>     could
>      > > see the rendered points in the geoserver Layer Preview with
>     OpenLayer
>      > > and tried to add the WMS layer to my map created with Drupal
>     Openlayer
>      > > module.
>      > >
>      > > It apparently works but it fetches a bound box that is wrong,
>     in fact if
>      > > i modify manually the request urls (from the browser) i get the
>     correct
>      > > data. I need to understand better how this bounded box works,
>     how is it
>      > > initially set? i guess that for each png image downloaded there
>     is a
>      > > specific BBOX parameter, is this done by the Openlayers library?
>      > >
>      > > I've also explained the issue on the drupal openlayers module but
>      > > apparently it was never really tested with WMS 900931 (weird
>     right?) .
>      > > The module works well with the same configuration and the 4326
>      > > projection (http://drupal.org/node/1884422).
>      > >
>      > > Please let me know if you have any suggestion.
>      > > Thanks!!
>      > >
>      > > Alex
>      >
>      > Alex,
>      >
>      > I think you need to post how the OL map and layer objects are
>     defined or
>      > post a link to your site if it is public.
>      >
>      > More than likely you have left off something like:
>     SphericalMercator: true
>      >
>      >
>      > Here is what I use:
>      >
>      > map = new OpenLayers.Map('map', {
>      > maxResolution: 156543.0339/2,
>      > numZoomLevels: 18,
>      > units: 'm',
>      > maxExtent: new OpenLayers.Bounds(-20037508.34,
>      > -20037508.34, 20037508.34, 20037508.34),
>      > sphericalMercator: true,
>      > projection: epsg900913,
>      > displayProjection: epsg4326,
>      > controls:[
>      > new OpenLayers.Control.LayerSwitcher(),
>      > // new OpenLayers.Control.OverviewMap(),
>      > new OpenLayers.Control.Permalink('permalink'),
>      > new OpenLayers.Control.MouseToolbar(),
>      > new OpenLayers.Control.MousePosition(),
>      > new OpenLayers.Control.PanZoomBar(),
>      > new OpenLayers.Control.Scale(),
>      > new OpenLayers.Control.ScaleLine()
>      > ]
>      > });
>      >
>      > var wms = new OpenLayers.Layer.WMS(
>      > "Peru WMS",
>      > "http://server/cgi-bin/mapserv?",
>      > { map: "/u/data/mydata/peru4.map",
>      > format: "image/png",
>      > layers: "Peru4_4326_WMS"
>      > },
>      > {
>      > sphericalMercator: true,
>      > transitionEffect: 'resize',
>      > singleTile: true,
>      > ratio: 1.0
>      > });
>      > wms.addOptions({isBaseLayer: true});
>      > wms.setVisibility(false);
>      > map.addLayer(wms);
>      >
>      > -Steve
>      > _______________________________________________
>      > Users mailing list
>      > Users at lists.osgeo.org <mailto:Users at lists.osgeo.org>
>      > http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>     _______________________________________________
>     Users mailing list
>     Users at lists.osgeo.org <mailto:Users at lists.osgeo.org>
>     http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>



More information about the Users mailing list