Mapguide session timeout in Openlayers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Mapguide session timeout in Openlayers

Klaus Pedersen

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();

                }

 

            }

        }


_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Jackie Ng
This fragment looks suspect:

            // Pings map to avoid timeout

            setInterval(function () {

                var mLayers = map.GetScale();          

            }, 30000);

If GetScale() doesn't actually make a request to the mapagent with your session id (and I strongly suspect it doesn't), then you're not actually doing anything to keep that particular session alive.

- Jackie
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Hans Milling
In reply to this post by Klaus Pedersen
We have some service side code that uses the MapGuide API to perform a request to the MapGuide server. We do an "OpenMap" request to an empty map. This is called every few minutes or so to keep the session alive on the mapguide server.

Best regards
  Hans Milling...
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Klaus Pedersen
In reply to this post by Jackie Ng
Hi Jackie,
You are right the code does not do anything to the session.
Is it possible some how to make a request to mapagent from javascript in order to reset the session timeout counter? 

Best regards
Klaus Leth


On Thu, Aug 21, 2014 at 12:32 PM, Jackie Ng <[hidden email]> wrote:
This fragment looks suspect:

            // Pings map to avoid timeout

            setInterval(function () {

                var mLayers = map.GetScale();

            }, 30000);

If GetScale() doesn't actually make a request to the mapagent with your
session id (and I strongly suspect it doesn't), then you're not actually
doing anything to keep that particular session alive.

- Jackie



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Mapguide-session-timeout-in-Openlayers-tp5157507p5157559.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users


_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Jackie Ng
Assuming you have jquery, just $.ajax to any operation in the mapagent in your setInterval function with your session id is enough to keep it alive.

- Jackie
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Jackie Ng
In reply to this post by Klaus Pedersen
If you want a dynamic setInterval() value instead of hard-coding 30 seconds, you can use GETSESSIONTIMEOUT as your keep-alive function

http://trac.osgeo.org/mapguide/wiki/MapGuideRfc66

GETSESSIONTIMEOUT returns the session expiry timeout, which you can use to calibrate/schedule the next GETSESSIONTIMEOUT keep-alive request. Making this request will also keep said session alive.

- Jackie
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Klaus Pedersen
I will test it out. It looks like an easy fix.
Your are right hardcoding magic numbers is not a good idea :-)

/Klaus Leth  


On Thu, Aug 21, 2014 at 1:22 PM, Jackie Ng <[hidden email]> wrote:
If you want a dynamic setInterval() value instead of hard-coding 30 seconds,
you can use GETSESSIONTIMEOUT as your keep-alive function

http://trac.osgeo.org/mapguide/wiki/MapGuideRfc66

GETSESSIONTIMEOUT returns the session expiry timeout, which you can use to
calibrate/schedule the next GETSESSIONTIMEOUT keep-alive request. Making
this request will also keep said session alive.

- Jackie



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Mapguide-session-timeout-in-Openlayers-tp5157507p5157575.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users


_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Klaus Pedersen
In reply to this post by Hans Milling
Hi Hans,
Do you register your sessions at a service and then the service perform the request to the mapguide server or is it something that you have build into your map application.   

/Klaus Leth


On Thu, Aug 21, 2014 at 12:58 PM, Hans Milling <[hidden email]> wrote:
We have some service side code that uses the MapGuide API to perform a
request to the MapGuide server. We do an "OpenMap" request to an empty map.
This is called every few minutes or so to keep the session alive on the
mapguide server.

Best regards
  Hans Milling...



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Mapguide-session-timeout-in-Openlayers-tp5157507p5157568.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users


_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Hans Milling
I have the session id registered on the server. But you should have the mapguide session id available in javascript as well and can send this to the code behind to make the actual connection.

Hans...
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Klaus Pedersen
In reply to this post by Jackie Ng
Thank you Jackie,
You saved my project it was on the edge of being closed down.

I made another mistake of compiling the project for .NET 4.0 but all of the MapGuide 2.2 Api
is runing under .NET 2.0 the only thing that did not work was the 3 minut timeout that was my setting on the MapGuide server.
The timeout was more like 4 or 5 minunts no matter what the setting in the mapGuide server said but changing the framework to 2.0 fixed it.     

I ended up implementing you GETSESSIONTIMEOUT solution with this code:

setInterval(function () {
MAPGUIDESESSION + "&LOCALE=en&CLIENTAGENT=Ajax%20Viewer"
                $.ajax({
                    url: timeoutpoll,
                    context: document.body,
                    error: function (XMLHttpRequest, textStatus, errorThrown) { 
                        alert(errorThrown);}
                });
            }, 60000);

I have tested the jquery code and now I can leave the map open and come back and do a zoom without getting a pink map image.
I'm sorry for the hardcoded 60 second timeout, just for tesing :-)

/Klaus Leth



On Thu, Aug 21, 2014 at 1:22 PM, Jackie Ng <[hidden email]> wrote:
If you want a dynamic setInterval() value instead of hard-coding 30 seconds,
you can use GETSESSIONTIMEOUT as your keep-alive function

http://trac.osgeo.org/mapguide/wiki/MapGuideRfc66

GETSESSIONTIMEOUT returns the session expiry timeout, which you can use to
calibrate/schedule the next GETSESSIONTIMEOUT keep-alive request. Making
this request will also keep said session alive.

- Jackie



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Mapguide-session-timeout-in-Openlayers-tp5157507p5157575.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users


_______________________________________________
mapguide-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/mapguide-users
Reply | Threaded
Open this post in threaded view
|

Re: Mapguide session timeout in Openlayers

Liglio
Hi Klaus,

I did the same approuch you did, I can get the map session timeout from
mapagent (I put an alert to see it). But my map session is still expiring. I
am using MGOS 3.0 and Fusion Viewer.

Thanks,

Liglio



--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
_______________________________________________
mapguide-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapguide-users