[mapserver-commits] r10704 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Wed Nov 3 17:04:47 EDT 2010
Author: aboudreault
Date: 2010-11-03 14:04:46 -0700 (Wed, 03 Nov 2010)
New Revision: 10704
Modified:
trunk/mapserver/HISTORY.TXT
trunk/mapserver/mapserv.c
trunk/mapserver/maptemplate.c
trunk/mapserver/maptemplate.h
trunk/mapserver/mapwms.c
Log:
Added a built-in OpenLayers map viewer (#3549)
Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT 2010-11-03 03:04:54 UTC (rev 10703)
+++ trunk/mapserver/HISTORY.TXT 2010-11-03 21:04:46 UTC (rev 10704)
@@ -14,6 +14,8 @@
Current Version (SVN trunk):
----------------------------
+- Added a built-in OpenLayers map viewer (#3549)
+
- Fixed issues with static buffers and sprintf (#3537)
- Fix for the memory corruption when mapping the string data type in the Java bindings (3491)
Modified: trunk/mapserver/mapserv.c
===================================================================
--- trunk/mapserver/mapserv.c 2010-11-03 03:04:54 UTC (rev 10703)
+++ trunk/mapserver/mapserv.c 2010-11-03 21:04:46 UTC (rev 10704)
@@ -1120,6 +1120,7 @@
int sendheaders = MS_TRUE;
struct mstimeval execstarttime, execendtime;
struct mstimeval requeststarttime, requestendtime;
+ char *service = NULL;
msSetup();
@@ -1284,7 +1285,7 @@
if( (ms_error->code != MS_NOERR) && (ms_error->isreported == MS_FALSE) )
writeError();
}
-
+
/*
** This was a WMS/WFS request... cleanup and exit
** At this point any error has already been handled
@@ -1296,8 +1297,26 @@
(requestendtime.tv_sec+requestendtime.tv_usec/1.0e6)-
(requeststarttime.tv_sec+requeststarttime.tv_usec/1.0e6) );
}
- msFreeMapServObj(mapserv);
+ if (strcasecmp(mapserv->map->imagetype, "application/openlayers")==0)
+ {
+ for( i=0; i<mapserv->request->NumParams; i++)
+ {
+ if(strcasecmp(mapserv->request->ParamNames[i], "SERVICE") == 0) {
+ service = mapserv->request->ParamValues[i];
+ break;
+ }
+ }
+ if (service && strcasecmp(service,"WMS")==0)
+ {
+ msIO_printf("Content-type: text/html%c%c",10,10);
+
+ if (msReturnOpenLayersPage(mapserv) != MS_SUCCESS)
+ writeError();
+ }
+ }
+
+ msFreeMapServObj(mapserv);
#ifdef USE_FASTCGI
/* FCGI_ --- return to top of loop */
continue;
@@ -1357,7 +1376,12 @@
if(mapserv->Mode == BROWSE) {
- if(!mapserv->map->web.template) {
+ char *template = NULL;
+ for(i=0;i<mapserv->request->NumParams;i++) /* find the template param value */
+ if (strcasecmp(mapserv->request->ParamNames[i], "template") == 0)
+ template = mapserv->request->ParamValues[i];
+
+ if ( (!mapserv->map->web.template) && (template==NULL || (strcasecmp(template, "openlayers")!=0)) ) {
msSetError(MS_WEBERR, "Traditional BROWSE mode requires a TEMPLATE in the WEB section, but none was provided.", "mapserv()");
writeError();
}
@@ -1375,8 +1399,13 @@
/* -------------------------------------------------------------------- */
if(msGenerateImages(mapserv, MS_FALSE, MS_TRUE) != MS_SUCCESS)
writeError();
-
- if(QueryFile) {
+
+ if ( (template != NULL) && (strcasecmp(template, "openlayers")==0) ) {
+ msIO_printf("Content-type: text/html%c%c",10,10);
+ if (msReturnOpenLayersPage(mapserv) != MS_SUCCESS)
+ writeError();
+ }
+ else if(QueryFile) {
if(msReturnTemplateQuery(mapserv, mapserv->map->web.queryformat, NULL) != MS_SUCCESS)
writeError();
} else {
Modified: trunk/mapserver/maptemplate.c
===================================================================
--- trunk/mapserver/maptemplate.c 2010-11-03 03:04:54 UTC (rev 10703)
+++ trunk/mapserver/maptemplate.c 2010-11-03 21:04:46 UTC (rev 10704)
@@ -39,6 +39,40 @@
MS_CVSID("$Id$")
+static char *olUrl = "http://www.mapserver.org/lib/OpenLayers-ms60.js";
+static char *olTemplate = \
+"<html>\n"
+"<head>\n"
+" <title>MapServer Simple Viewer</title>\n"
+" <script type=\"text/javascript\" src=\"[openlayers_js_url]\"></script>\n"
+" </head>\n"
+" <body>\n"
+" <div style=\"width:[mapwidth]; height:[mapheight]\" id=\"map\"></div>\n"
+" <script defer=\"defer\" type=\"text/javascript\">\n"
+" var map = new OpenLayers.Map('map',\n"
+" {maxExtent: new OpenLayers.Bounds([minx],[miny],[maxx],[maxy]),\n"
+" maxResolution: [cellsize]});\n"
+" [openlayers_layer];\n"
+" map.addLayer(mslayer);\n"
+" map.zoomToMaxExtent();\n"
+" </script>\n"
+"</body>\n"
+"</html>";
+
+static char *olLayerMapServerTag = \
+"var mslayer = new OpenLayers.Layer.MapServer( \"MapServer Layer\",\n"
+" \"[mapserv_onlineresource]\",\n"
+" {layers: '[layers]'},\n"
+" {singleTile: \"true\", ratio:1} )";
+
+static char *olLayerWMSTag = \
+"var mslayer = new OpenLayers.Layer.WMS('MapServer Simple Viewer\',\n"
+" '[mapserv_onlineresource]',\n"
+" {layers: '[LAYERS]',\n"
+" bbox: '[minx],[miny],[maxx],[maxy]',\n"
+" width: [mapwidth], height: [mapheight] },"
+" {singleTile: \"true\", ratio:1, projection: '[SRS]'});\n";
+
static char *processLine(mapservObj *mapserv, char *instr, FILE *stream, int mode);
static int isValidTemplate(FILE *stream, const char *filename)
@@ -3429,6 +3463,9 @@
snprintf(repstr, PROCESSLINE_BUFLEN, "%s%s%s.map", mapserv->map->web.imagepath, mapserv->map->name, mapserv->Id);
outstr = msReplaceSubstring(outstr, "[map]", repstr);
}
+
+ outstr = msReplaceSubstring(outstr, "[mapserv_onlineresource]",
+ msOWSGetOnlineResource(mapserv->map, "O", "onlineresource", mapserv->request));
if(getenv("HTTP_HOST")) {
snprintf(repstr, PROCESSLINE_BUFLEN, "%s", getenv("HTTP_HOST"));
@@ -4168,7 +4205,52 @@
return MS_SUCCESS;
}
+int msReturnOpenLayersPage(mapservObj *mapserv)
+{
+ int i;
+ char *buffer = NULL, *layer = NULL;
+ const char *tmpUrl = NULL;
+ char *openlayersUrl = olUrl;
+ /* 2 CGI parameters are used in the template. we need to transform them
+ * to be sure the case match during the template processing */
+ for( i=0; i<mapserv->request->NumParams; i++)
+ {
+ if(strcasecmp(mapserv->request->ParamNames[i], "SRS") == 0) {
+ free(mapserv->request->ParamNames[i]);
+ mapserv->request->ParamNames[i] = strdup("SRS");
+ }
+ else if(strcasecmp(mapserv->request->ParamNames[i], "LAYERS") == 0) {
+ free(mapserv->request->ParamNames[i]);
+ mapserv->request->ParamNames[i] = strdup("LAYERS");
+ }
+ }
+
+ /* check if the environment variable or config MS_OPENLAYERS_JS_URL is set */
+ tmpUrl = msGetConfigOption(mapserv->map, "MS_OPENLAYERS_JS_URL");
+ if (tmpUrl)
+ openlayersUrl = (char*)tmpUrl;
+ else if (getenv("MS_OPENLAYERS_JS_URL"))
+ openlayersUrl = getenv("MS_OPENLAYERS_JS_URL");
+
+ if (mapserv->Mode == BROWSE) {
+ msSetError(MS_WMSERR, "At least one layer name required in LAYERS.",
+ "msWMSLoadGetMapParams()");
+ layer = processLine(mapserv, olLayerMapServerTag, NULL, BROWSE);
+ }
+ else
+ layer = processLine(mapserv, olLayerWMSTag, NULL, BROWSE);
+
+ buffer = processLine(mapserv, olTemplate, NULL, BROWSE);
+ buffer = msReplaceSubstring(buffer, "[openlayers_js_url]", openlayersUrl);
+ buffer = msReplaceSubstring(buffer, "[openlayers_layer]", layer);
+ msIO_fwrite(buffer, strlen(buffer), 1, stdout);
+ free(layer);
+ free(buffer);
+
+ return MS_SUCCESS;
+}
+
mapservObj *msAllocMapServObj()
{
mapservObj *mapserv = malloc(sizeof(mapservObj));
Modified: trunk/mapserver/maptemplate.h
===================================================================
--- trunk/mapserver/maptemplate.h 2010-11-03 03:04:54 UTC (rev 10703)
+++ trunk/mapserver/maptemplate.h 2010-11-03 21:04:46 UTC (rev 10704)
@@ -139,6 +139,7 @@
MS_DLL_EXPORT int msReturnURL(mapservObj* msObj, char*, int);
MS_DLL_EXPORT int msReturnNestedTemplateQuery(mapservObj* msObj, char* pszMimeType, char **papszBuffer);
MS_DLL_EXPORT int msReturnTemplateQuery(mapservObj *msObj, char* pszMimeType, char **papszBuffer);
+MS_DLL_EXPORT int msReturnOpenLayersPage(mapservObj *mapserv);
MS_DLL_EXPORT int msRedirect(char* url);
Modified: trunk/mapserver/mapwms.c
===================================================================
--- trunk/mapserver/mapwms.c 2010-11-03 03:04:54 UTC (rev 10703)
+++ trunk/mapserver/mapwms.c 2010-11-03 21:04:46 UTC (rev 10704)
@@ -672,39 +672,42 @@
outputFormatObj *psFormat=NULL;
formatfound = 1;
- /*check to see if a predefined list is given*/
- format_list = msOWSLookupMetadata(&(map->web.metadata), "M","getmap_formatlist");
- if (format_list)
+ if (strcasecmp(values[i], "application/openlayers")!=0)
{
- psFormat = msOwsIsOutputFormatValid(map, values[i], &(map->web.metadata),
- "M", "getmap_formatlist");
- if (psFormat == NULL)
+ /*check to see if a predefined list is given*/
+ format_list = msOWSLookupMetadata(&(map->web.metadata), "M","getmap_formatlist");
+ if (format_list)
{
- msSetError(MS_IMGERR,
- "Unsupported output format (%s).",
- "msWMSLoadGetMapParams()",
- values[i] );
- return msWMSException(map, nVersion, "InvalidFormat");
+ psFormat = msOwsIsOutputFormatValid(map, values[i], &(map->web.metadata),
+ "M", "getmap_formatlist");
+ if (psFormat == NULL &&
+ strcasecmp(values[i], "application/openlayers")!=0)
+ {
+ msSetError(MS_IMGERR,
+ "Unsupported output format (%s).",
+ "msWMSLoadGetMapParams()",
+ values[i] );
+ return msWMSException(map, nVersion, "InvalidFormat");
+ }
}
- }
- else
- {
- format = msSelectOutputFormat( map, values[i] );
- if( format == NULL ||
- (strncasecmp(format->driver, "GD/", 3) != 0 &&
- strncasecmp(format->driver, "GDAL/", 5) != 0 &&
- strncasecmp(format->driver, "AGG/", 4) != 0 &&
- strncasecmp(format->driver, "AGG2/", 5) != 0 &&
- strncasecmp(format->driver, "CAIRO/", 6) != 0 &&
- strncasecmp(format->driver, "SVG", 3) != 0 &&
- strncasecmp(format->driver, "KML", 3) != 0))
-
+ else
{
- msSetError(MS_IMGERR,
- "Unsupported output format (%s).",
- "msWMSLoadGetMapParams()",
- values[i] );
- return msWMSException(map, nVersion, "InvalidFormat");
+ format = msSelectOutputFormat( map, values[i] );
+ if( format == NULL ||
+ (strncasecmp(format->driver, "GD/", 3) != 0 &&
+ strncasecmp(format->driver, "GDAL/", 5) != 0 &&
+ strncasecmp(format->driver, "AGG/", 4) != 0 &&
+ strncasecmp(format->driver, "AGG2/", 5) != 0 &&
+ strncasecmp(format->driver, "CAIRO/", 6) != 0 &&
+ strncasecmp(format->driver, "SVG", 3) != 0 &&
+ strncasecmp(format->driver, "KML", 3) != 0))
+ {
+ msSetError(MS_IMGERR,
+ "Unsupported output format (%s).",
+ "msWMSLoadGetMapParams()",
+ values[i] );
+ return msWMSException(map, nVersion, "InvalidFormat");
+ }
}
}
msFree( map->imagetype );
@@ -2789,14 +2792,16 @@
msIO_printf("Cache-Control: max-age=%s\n", http_max_age , 10, 10);
}
- msIO_printf("Content-type: %s%c%c",
- MS_IMAGE_MIME_TYPE(map->outputformat), 10,10);
- if (msSaveImage(map, img, NULL) != MS_SUCCESS)
- return msWMSException(map, nVersion, NULL);
+ if (strcasecmp(map->imagetype, "application/openlayers")!=0)
+ {
+ msIO_printf("Content-type: %s%c%c",
+ MS_IMAGE_MIME_TYPE(map->outputformat), 10,10);
+ if (msSaveImage(map, img, NULL) != MS_SUCCESS)
+ return msWMSException(map, nVersion, NULL);
+ msFreeImage(img);
+ }
- msFreeImage(img);
-
return(MS_SUCCESS);
}
More information about the mapserver-commits
mailing list