[fusion-commits] r1373 - in trunk: MapGuide/php widgets
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Tue Apr 15 11:24:28 EDT 2008
Author: zjames
Date: 2008-04-15 11:24:27 -0400 (Tue, 15 Apr 2008)
New Revision: 1373
Modified:
trunk/MapGuide/php/SaveMap.php
trunk/widgets/SaveMap.js
Log:
re #50 re #51 - savemap printlayout and image size improvements.
Modified: trunk/MapGuide/php/SaveMap.php
===================================================================
--- trunk/MapGuide/php/SaveMap.php 2008-04-11 13:21:40 UTC (rev 1372)
+++ trunk/MapGuide/php/SaveMap.php 2008-04-15 15:24:27 UTC (rev 1373)
@@ -32,6 +32,8 @@
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'png';
$layout = isset($_REQUEST['layout']) ? $_REQUEST['layout'] : null;
$scale = isset($_REQUEST['scale']) ? $_REQUEST['scale'] : null;
+$imgWidth = isset($_REQUEST['width']) ? $_REQUEST['width'] : null;
+$imgHeight = isset($_REQUEST['height']) ? $_REQUEST['height'] : null;
try
{
@@ -43,8 +45,14 @@
$selection = new MgSelection($map);
$selection->Open($resourceService, $mapName);
+ //compute center
+ $extent = $map->GetMapExtent();
+ $centerX = $extent->GetLowerLeftCoordinate()->GetX() + ($extent->GetWidth())/2;
+ $centerY = $extent->GetLowerLeftCoordinate()->GetY() + ($extent->GetHeight())/2;
+ $geomFactory = new MgGeometryFactory();
+ $center = $geomFactory->CreateCoordinateXY($centerX, $centerY);
+
if ($format == 'DWF') {
- $extent = $map->GetMapExtent();
$oLayout = null;
if ($layout) {
$layoutId = new MgResourceIdentifier($layout);
@@ -56,31 +64,17 @@
$dwfVersion = new MgDwfVersion('6.01','1.2');
if ($scale) {
- //compute center point and plot with the passed scale
-
- $centerX = $extent->GetLowerLeftCoordinate()->GetX() + ($extent->GetWidth())/2;
- $centerY = $extent->GetLowerLeftCoordinate()->GetY() + ($extent->GetHeight())/2;
- $geomFactory = new MgGeometryFactory();
- $center = $geomFactory->CreateCoordinateXY($centerX, $centerY);
+ //plot with the passed scale
- //echo $centerX.", ".$centerY;exit;
- //$metersPerUnit = $map->GetMetersPerUnit();
$coordSysFactory = new MgCoordinateSystemFactory();
$coordSystem = $coordSysFactory->Create($map->GetMapSRS());
$metersPerUnit = $coordSystem->ConvertCoordinateSystemUnitsToMeters(1.0);
$metersPerPixel = 1.0/(100.0 / 2.54 * $map->GetDisplayDpi());
- //echo $metersPerPixel; exit;
$height = $map->GetDisplayHeight();
$width = $map->GetDisplayWidth();
$mapWidth = $scale * $width * $metersPerPixel/$metersPerUnit;
$mapHeight = $scale * $height * $metersPerPixel/$metersPerUnit;
- //echo $mapWidth.", ".$mapHeight;exit;
-
- // $lowerLeft = $geomFactory->CreateCoordinateXY($center->GetX() - 0.5*$mapWidth,
- // $center->GetY() - 0.5*$mapHeight);
- // $topRight = $geomFactory->CreateCoordinateXY($center->GetX() + 0.5*$mapWidth,
- // $center->GetY() + 0.5*$mapHeight);
$extent = new MgEnvelope(
$center->GetX() - 0.5*$mapWidth,
$center->GetY() - 0.5*$mapHeight,
@@ -113,8 +107,18 @@
$dwfVersion);
}
} else {
- $oImg = $renderingService->RenderMap($map, $selection, $format);
- }
+ //render as an image
+ if (isset($imgHeight) && isset($imgWidth)) {
+ $scale = $map->GetViewScale();
+ $oImg = $renderingService->RenderMap($map, $selection,
+ $center, $scale,
+ $imgWidth, $imgHeight,
+ new MgColor(255,255,255),
+ $format);
+ }else{
+ $oImg = $renderingService->RenderMap($map, $selection, $format);
+ };
+ };
}
catch (MgException $e)
{
@@ -124,16 +128,8 @@
exit;
}
-/*
-header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
-header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
- // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
-header("Cache-Control: post-check=0, pre-check=0", false);
-header("Pragma: no-cache"); // HTTP/1.0
-header( "Content-type: application/octet-stream" );
-header( "Content-Disposition: attachment; filename=$mapName.png" );
-*/
+header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header( "Content-type: image/$format" );
header( "Content-disposition: attachment; filename=$mapName.$format" );
Modified: trunk/widgets/SaveMap.js
===================================================================
--- trunk/widgets/SaveMap.js 2008-04-11 13:21:40 UTC (rev 1372)
+++ trunk/widgets/SaveMap.js 2008-04-15 15:24:27 UTC (rev 1373)
@@ -43,27 +43,55 @@
iframe : null,
printLayout : null,
printScale : null,
+ imageWidth : null,
+ imageHeight : null,
initialize : function(widgetTag) {
Object.inheritFrom(this, Fusion.Widget.prototype, [widgetTag, false]);
- Object.inheritFrom(this, Fusion.Tool.ButtonBase.prototype, []);
var json = widgetTag.extension;
this.format = (json.Format && json.Format[0] != '')?
json.Format[0] : 'png';
//for DWF, parse printLayouts and build menu
- if (this.format == 'DWF') {
- var config = json.PrintLayout && json.PrintLayout[0];
- if (config && config.ResourceId) {
- this.printLayout = config.ResourceId[0];
- if (config.Scale) {
- this.printScale = config.Scale[0];
- }
- } else {
- //TODO: Warning that the widget is improperly configured
- //because we need print layout for this to work.
- //TODO: deactivate the widget?
+ if (this.format == 'DWF' && json.PrintLayout.length) {
+ Object.inheritFrom(this, Fusion.Tool.MenuBase.prototype, []);
+
+ var layouts = json.PrintLayout;
+ for (var i = 0; i < layouts.length; i++) {
+ var layout = layouts[i];
+ var opt = {};
+ opt.label = layout.Name[0];
+ var data = layout.ResourceId[0];
+ var menuItem = null;
+ if (layout.Scale) {
+ //create entries for weblayout specified scales
+ menuItem = new Jx.SubMenu(opt);
+ for (var j=0; j < layout.Scale.length; j++) {
+ var scale = layout.Scale[j];
+ var scaleAction = new Jx.Action(this.setLayout.bind(this, data, scale));
+ var subMenuItem = new Jx.MenuItem(scaleAction,{label:scale});
+ menuItem.add(subMenuItem);
+ }
+ //add an entry for current scale
+ var currentScaleAction = new Jx.Action(this.setLayout.bind(this, data));
+ var currentScaleItem = new Jx.MenuItem(currentScaleAction,
+ {label:'Current Scale'});
+ menuItem.add(currentScaleItem);
+ } else {
+ //if there are no scales, the layout is used with current scale
+ var action = new Jx.Action(this.setLayout.bind(this, data));
+ menuItem = new Jx.MenuItem(action,opt);
+ };
+ this.oMenu.add(menuItem);
}
+ } else {
+ Object.inheritFrom(this, Fusion.Tool.ButtonBase.prototype, []);
+ if (json.Width && json.Width[0] != '') {
+ this.imageWidth = json.Width[0];
+ }
+ if (json.Height && json.Height[0] != '') {
+ this.imageHeight = json.Height[0];
+ }
}
this.enable = Fusion.Widget.SaveMap.prototype.enable;
@@ -73,6 +101,14 @@
Fusion.Tool.ButtonBase.prototype.enable.apply(this, []);
},
+ setLayout: function(rid) {
+ if (arguments.length > 1) {
+ this.printScale = parseInt(arguments[1]);
+ }
+ this.printLayout = rid;
+ this.activateTool();
+ },
+
/**
* called when the button is clicked by the Fusion.Tool.ButtonBase widget
* prompts user to save the map.
@@ -97,17 +133,20 @@
szScale = '&scale=' + this.printScale;
}
}
- //TODO: revisit Fusion.getWebAgentURL
- var m = this.getMap().aMaps[0];
+ var szHeight = '';
+ if (this.imageHeight) {
+ szHeight = '&height=' + this.imageHeight;
+ };
+ var szWidth = '';
+ if (this.imageWidth) {
+ szWidth = '&width=' + this.imageWidth;
+ };
+ var m = this.getMap().aMaps[0];
if(navigator.appVersion.match(/\bMSIE\b/)) {
- //var url = Fusion.getWebAgentURL() + "OPERATION=GETDYNAMICMAPOVERLAYIMAGE&FORMAT=PNG&VERSION=1.0.0&SESSION=" + this.getMap().getSessionID() + "&MAPNAME=" + this.getMap().getMapName() + "&SEQ=" + Math.random();
-
- var url = Fusion.fusionURL + '/' + m.arch + '/' + Fusion.getScriptLanguage() + "/SaveMapFrame." + Fusion.getScriptLanguage() + '?session='+m.getSessionID() + '&mapname=' + m.getMapName() + '&format=' + this.format + szLayout;
- //this.iframe.src = url;
+ var url = Fusion.fusionURL + '/' + m.arch + '/' + Fusion.getScriptLanguage() + "/SaveMapFrame." + Fusion.getScriptLanguage() + '?session='+m.getSessionID() + '&mapname=' + m.getMapName() + '&format=' + this.format + szLayout + szWidth + szHeight;
w = open(url, "Save", 'menubar=no,height=200,width=300');
} else {
- var s = Fusion.fusionURL + '/' + m.arch + '/' + Fusion.getScriptLanguage() + "/SaveMap." + Fusion.getScriptLanguage() + '?session='+m.getSessionID() + '&mapname=' + m.getMapName() + '&format=' + this.format + szLayout;
- //console.log(s);
+ var s = Fusion.fusionURL + '/' + m.arch + '/' + Fusion.getScriptLanguage() + "/SaveMap." + Fusion.getScriptLanguage() + '?session='+m.getSessionID() + '&mapname=' + m.getMapName() + '&format=' + this.format + szLayout + szWidth + szHeight;
this.iframe.src = s;
}
More information about the fusion-commits
mailing list