custom layer types issue with django/apache/mod_wsgi

21 views
Skip to first unread message

David Heinzerling

unread,
Dec 8, 2012, 6:53:15 PM12/8/12
to olwi...@googlegroups.com
Hello,
I'm trying to display a custom png TMS layer using olwidget custom layer types in django. The configuration I have below works great when I run the django development server, but fails when I run it on our production server using apache2/mod_wsgi

The error is:

TypeError: map_service is undefined
layers.push(map_service.map(map_type));

Which refers to line 277 in olwidget.js. 
        for (var i = 0; i < opts.layers.length; i++) {
            var parts = opts.layers[i].split(".");
            var map_service = olwidget[parts[0]];
            var map_type = parts[1];

            layers.push(map_service.map(map_type));

The parts reads ['image_map'] which refers to the custom layer defined below. However, it doesn't successfully generate map_service. Not sure why it works in development but not in production. Probably something stupid I'm doing. Great project!

from settings.py:

OLWIDGET_CUSTOM_LAYER_TYPES = {
    'image_layer': """OpenLayers.Layer.TMS(
        'Image TMS',
        '',
        {url: '',
        serviceVersion: '.',
        layername: '.',
        alpha: true,
        type: 'png',
        getURL: overlay_getTileURL 
        }
    )
       function overlay_getTileURL(bounds) {
            var projectId = sessvars.sessionObj['projectId']
            floor = $('#id_floor').val();
            var res = this.map.getResolution();
            var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
            var y = Math.round((bounds.bottom - this.maxExtent.bottom) / (res * this.tileSize.h));
            var z = this.map.getZoom();
            if (x >= 0 && y >= 0) {
                return "/static/userData/" + projectId + "/" + floor + "/" + z + "/" + x + "/" + y + "." + this.type;                
            } else {
                return "http://www.maptiler.org/img/none.png";
            }
        }
    """
}

Gora Mohanty

unread,
Dec 8, 2012, 11:47:07 PM12/8/12
to olwi...@googlegroups.com
On 9 December 2012 05:23, David Heinzerling <dheinz...@gmail.com> wrote:
> Hello,
> I'm trying to display a custom png TMS layer using olwidget custom layer
> types in django. The configuration I have below works great when I run the
> django development server, but fails when I run it on our production server
> using apache2/mod_wsgi
[...]
> if (x >= 0 && y >= 0) {
> return "/static/userData/" + projectId + "/" + floor + "/" +
> z + "/" + x + "/" + y + "." + this.type;
[...]

From the symptoms that you describe, I would guess that /static/...
URLs are being served in development, but not in production. You
probably need to set up an Alias directive in your Apache site
configuration file. This link should be of help:
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/
You should also consider using django.contrib.staticfiles :
https://docs.djangoproject.com/en/dev/howto/static-files/

Regards,
Gora

David Heinzerling

unread,
Dec 9, 2012, 4:04:27 PM12/9/12
to olwi...@googlegroups.com
That's unfortunately not the issue. I have static files setup correctly within Django and Apache. I can access the files fine--along with the scripts, etc. that are also in /static/ that are required to run olwidget in the first place. I can remove that whole section of the 'image_layer' instance and it doesn't make a difference. Something is preventing the custom layer type from successfully generating itself. I traced down how the custom layer types are generated and just copied the result as a new olwidget object in olwidget.js (below). This fixed the problem, but I still can't figure out why it is failing to do what it is supposed to do. My guess is there is some import error that is hidden from me--I'll have to do some more sleuthing.  

    image_layer: {
    map: function() {
    return new  OpenLayers.Layer.TMS(
       'Image TMS',
       '',
       {url: '',
       serviceVersion: '.',
       layername: '.',
       alpha: true,
       type: 'png',
       getURL: overlay_getTileURL 
       }
   )
      function overlay_getTileURL(bounds) {
           var projectId = sessvars.sessionObj['projectId']
           floor = $('#id_floor').val();
           var res = this.map.getResolution();
           var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
           var y = Math.round((bounds.bottom - this.maxExtent.bottom) / (res * this.tileSize.h));
           var z = this.map.getZoom();
           if (x >= 0 && y >= 0) {
               return "/static/userData/" + projectId + "/" + floor + "/" + z + "/" + x + "/" + y + "." + this.type;                
           } else {
               return "http://www.maptiler.org/img/none.png";
           }
       }
    }
    },

cha...@gmail.com

unread,
Dec 9, 2012, 4:36:32 PM12/9/12
to olwi...@googlegroups.com
Not sure why there would be a prod/dev difference, but the javascript there has something funny going on -- you're defining the function overlay_getTileURL after returning an object that encloses it.  It's the equivalent of:

    return foo;
    var foo = "bar";

Instead, you might probably want something like this:


return new OpenLayers.Layer.TMS(
    'Image TMS',
    '',
    {
        url: '',
        serviceVersion: '.',
        layername: '.',
        alpha: true,
        type: 'png',
        getURL: function (bounds) {

            var projectId = sessvars.sessionObj['projectId']
            var floor = $('#id_floor').val();

            var res = this.map.getResolution();
            var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
            var y = Math.round((bounds.bottom - this.maxExtent.bottom) / (res * this.tileSize.h));
            var z = this.map.getZoom();
            if (x >= 0 && y >= 0) {
                return "/static/userData/" + projectId + "/" + floor + "/" + z + "/" + x + "/" + y + "." + this.type;               
            } else {
                return "http://www.maptiler.org/img/none.png";
            }
        }
    }
)

Since the olwidget source is a little too clever and inserts the "return" and "new" keywords for you, you'll need to just use parts after "OpenLayers..." if you put it in OLWIDGET_CUSTOM_LAYER_TYPES.

best,
Charlie
--
 
 

Reply all
Reply to author
Forward
0 new messages