[mapguide-trac] #1245: Map Image format automatic optimization
MapGuide Open Source
trac_mapguide at osgeo.org
Thu Jan 14 11:11:44 EST 2010
#1245: Map Image format automatic optimization
---------------------------+------------------------------------------------
Reporter: msuing | Owner:
Type: enhancement | Status: new
Priority: medium | Milestone:
Component: AJAX Viewer | Version: 2.1.0
Severity: major | Keywords: image, format, png, png8
External_id: |
---------------------------+------------------------------------------------
Hi all,
Since the quality of PNG8 is still not ideal (see
http://trac.osgeo.org/mapguide/ticket/634), we often face a dilemma :
quality OR speed (PNG or PNG8).
It would be great to allow MapGuide to adapt automatically the map image
format depending on the client connection speed.
The idea would be to define the image format as a parameter in
ajaxmappane.templ :
var mapImageFormat = 'PNG'; // default map image format
var mapImageAutoFormat = true; //automatic optimization of map
image format
var connectionSpeedLimit = 5000; //minimum connection speed for
high quality
Then to change the map url to allow a dynamic map image format :
function RequestMapImage(reqId, viewParams){
url = webAgent + "?OPERATION=GETDYNAMICMAPOVERLAYIMAGE&FORMAT=" +
mapImageFormat + "&VERSION=2.1.0&SESSION="...
After the first map has been loaded we could evaluate the connection speed
to change the format to PNG if it's good or PNG8 if it's bad (below
connectionSpeedLimit Kbps), for the rest of the session :
function AutoImageFormat()
{
var st = new SpeedTest();
st.run({
onStart: function() {
//alert('Before Running Speed Test');
}
,onEnd: function(speed) {
//alert( 'Speed test complete: ' + speed.Kbps + ' Kbps ' +
speed.KBps + ' KBps');
if( speed.Kbps > connectionSpeedLimit )
mapImageFormat = 'PNG';
else
mapImageFormat = 'PNG8';
}
});
}
var SpeedTest = function() {
};
SpeedTest.prototype = {
imgUrl: "../stdicons/speedtest.png" // Where the image is located at
,size: 258048 // size in bytes
,run: function( options ) {
if( options && options.onStart )
options.onStart();
var imgUrl = this.imgUrl + "?r=" + Math.random();
this.startTime = (new Date()).getTime() ;
var testImage = new Image();
var me = this;
testImage.onload = function() {
me.endTime = (new Date()).getTime();
me.runTime = me.endTime - me.startTime;
if( options && options.onEnd )
options.onEnd( me.getResults() );
};
testImage.src = imgUrl;
}
,getResults: function() {
if( !this.runTime )
return null;
return {
runTime: this.runTime
,Kbps: ( this.size * 8 / 1024 / ( this.runTime / 1000 ) )
,KBps: ( this.size / 1024 / ( this.runTime / 1000 ) )
};
}
}
To go one step further, we could :
- evaluate this connection speed directly on the map image previously
loaded instead of "../stdicons/speedtest.png"
- choose to put automatically JPG format if one of the displayed layers is
based on a raster datasource.
Cheers,
Max.
--
Ticket URL: <http://trac.osgeo.org/mapguide/ticket/1245>
MapGuide Open Source <http://mapguide.osgeo.org/>
MapGuide Open Source Internals
More information about the mapguide-trac
mailing list