[mapguide-users] Mapguide session timeout in Openlayers

Klaus Pedersen klauslp at gmail.com
Wed Aug 20 23:43:36 PDT 2014


I have created a small .Net webapplication that creates a Mapguide 2.2
session and I use the SessionID to create a map with Openlayers 2.13.1
client side. I have tiled the outmost layers and the map performs okay
except for one thing: when the mapguide session is timing out the user get
a pink map and he/she have to reload the whole page to get a new session.
My mapguide server has the connection timeout set to 180 seconds in the
serverconfig.ini and I do not want to change that setting because I have
other maps running on the same MapGuide server.



I have tried to call a map.GetScale() with the setInterval function from
javascript to avoid the session from timing out but with no luck. If the
user search for an address on the page I can check serverside that the
session is valid and if not I create a new session. There is another
problem that needs to be handled if the user leaves the map for 180 seconds
and then comes back and either pan’s or zoom’s in the map then he/she get
the pink map. I would like to renew the session from openlayers and the
second best solution would be to inform the user to reload the page because
the session has timed out. Does any one have a good solution to that
problem?

I have pasted in the javascript code maybe I’m doing something wrong.



var map, layer, selectControl;

var url = MAPAGENTFULLURL;



var metersPerUnit = 111319.4908;  //value returned from mapguide

var inPerUnit = OpenLayers.INCHES_PER_UNIT.m * metersPerUnit;

OpenLayers.INCHES_PER_UNIT["dd"] = inPerUnit;

OpenLayers.INCHES_PER_UNIT["degrees"] = inPerUnit;

OpenLayers.DOTS_PER_INCH = 96;



// Read a page's GET URL variables and return them as an associative array.

function getUrlVars() {

    var vars = [], hash;

    var hashes =
window.location.href.slice(window.location.href.indexOf('?') +
1).split('&');

    for (var i = 0; i < hashes.length; i++) {

        hash = hashes[i].split('=');

        vars.push(hash[0]);

        vars[hash[0]] = hash[1];

    }

    return vars;

}



var extent = new OpenLayers.Bounds(558039.925296475, 6203996.72440874,
588823.764743925, 6244575.71467263);



function initUnTiled() {

    var tempScales = [200000, 175000, 150000, 125000, 100000, 75000, 50000,
40000, 30000, 20000, 10000, 5000, 4000, 3000, 2000, 1000, 500, 250, 100];



    var mapOptions = {

        maxExtent: extent,

        restrictedExtent: extent,

        scales: tempScales,

        units: "m",

        projection: 'EPSG:25832'

     };



    map = new OpenLayers.Map('map', mapOptions);



    var params = {

        mapdefinition: KORTDEFINITION,

        basemaplayergroupname: "DETALJEKORTTILED",

        session: MAPGUIDESESSION

    };



    var options = {

        isBaseLayer: true,

        transitionEffect: "resize",

        buffer: 1,

        useOverlay: false,

        useAsyncOverlay: false,

        singleTile: false

    };

    // Coordinates from url

    var xkoord = getUrlVars()["X"];

    var ykoord = getUrlVars()["Y"];

    var mbr = getUrlVars()["MBR"];

    var point = new OpenLayers.Feature.Vector( new
OpenLayers.Geometry.Point(xkoord, ykoord));



    var my_style = new OpenLayers.StyleMap({

        "default": new OpenLayers.Style(

        {

            pointRadius: 5,

            strokeColor: "#ff0000",

            fillColor: "#ff0000",

            fillOpacity: 0.2,

            strokeWidth: 1,

            fontColor: "blue",

            fontSize: 10,

            fontFamily: "Arial",

            fontWeight: "bold"

        })

    });

    var soegtlayer = new OpenLayers.Layer.Vector("Din adresse",

    {

         isFixed: false,

         styleMap: my_style



    });



    soegtlayer.addFeatures([point]);

    var layer = new OpenLayers.Layer.MapGuide("kort med
Driftsforstyrrelser", url, params, options);



    var dynoptions = {

        isBaseLayer: false,

        useOverlay: false, //false

        useAsyncOverlay: false, // false

        singleTile: true

    };



    var dynparams = {

        mapdefinition: KORTDEFINITION,

        session: MAPGUIDESESSION



    };

    untiledlayer = new OpenLayers.Layer.MapGuide("Ledninger", url,
dynparams, dynoptions);

    map.addLayers([untiledlayer, layer, soegtlayer]);

    map.addControl(new OpenLayers.Control.MousePosition());

    map.addControl(new OpenLayers.Control.Scale());





    // TEST af select feature

     map.addControl(new OpenLayers.Control.LayerSwitcher());



            selectControl = new OpenLayers.Control.SelectFeature(

                [soegtlayer],

                {

                    clickout: true, toggle: false,

                    multiple: false, hover: false,

                    toggleKey: "ctrlKey", // ctrl key removes from selection

                    multipleKey: "shiftKey" // shift key adds to selection

                }

            );

            map.addControl(selectControl);

            selectControl.activate();



            // Pings map to avoid timeout

            setInterval(function () {

                var mLayers = map.GetScale();

            }, 30000);



            //oprindelig ZOOM i kort

            if (xkoord != null && ykoord != null) {

                map.setCenter(new OpenLayers.LonLat(xkoord, ykoord),
14);

            }

            else {

                // Hvis parameteren er en MBR rektangel zoomes til rektangel

                if (mbr != null) {

                    var koordSet = mbr.split(",");

                    // udregn nyt centerpunkt

                    var centerX = (parseFloat(koordSet[0]) +
parseFloat(koordSet[2])) / 2;

                    var centerY = (parseFloat(koordSet[1]) +
parseFloat(koordSet[3])) / 2;

                    var zoomLevel = new OpenLayers.Bounds(koordSet);

                    var nytZoom = map.getZoomForExtent(zoomLevel, true);

                    // Det beregnede zoom fratrækkes 1 for at få lidt
margin i kortet

                    map.setCenter(new OpenLayers.LonLat(centerX, centerY),
nytZoom - 1);

                }

                else {

                    map.zoomToMaxExtent();

                }



            }

        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20140821/6c058e6b/attachment.html>


More information about the mapguide-users mailing list