[mapserver-commits] r12364 - trunk/mapserver/mapcache/src
svn at osgeo.org
svn at osgeo.org
Fri Aug 26 07:19:54 EDT 2011
Author: tbonfort
Date: 2011-08-26 04:19:54 -0700 (Fri, 26 Aug 2011)
New Revision: 12364
Modified:
trunk/mapserver/mapcache/src/service_demo.c
Log:
add ogc proxy support to wms service. needs documenting !
thomas.bonfort | 2011-05-19 16:46:10 +0200 (Thu, 19 May 2011)
Modified: trunk/mapserver/mapcache/src/service_demo.c
===================================================================
--- trunk/mapserver/mapcache/src/service_demo.c 2011-08-26 11:19:48 UTC (rev 12363)
+++ trunk/mapserver/mapcache/src/service_demo.c 2011-08-26 11:19:54 UTC (rev 12364)
@@ -24,6 +24,7 @@
static char *demo_head =
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
" <head>\n"
+ " <title>mod-geocache demo service</title>\n"
" <style type=\"text/css\">\n"
" #map {\n"
" width: 100%;\n"
@@ -33,21 +34,142 @@
" </style>\n"
" <script src=\"http://www.openlayers.org/api/OpenLayers.js\"></script>\n"
" <script type=\"text/javascript\">\n"
+ "%s\n"
"var map;\n"
"function init(){\n"
- " map = new OpenLayers.Map( 'map' );\n";
+ " map = new OpenLayers.Map( 'map', {\n"
+ " displayProjection: new OpenLayers.Projection(\"EPSG:4326\")\n"
+ " } );\n";
-static char *demo_layer =
- " var %s_%s_layer = new OpenLayers.Layer.WMS( \"%s-%s\",\n"
+static char *demo_ve_extra =
+ "function QuadTree(tx, ty, zoom) {\n"
+ " var tname = '';\n"
+ " var i, j, mask, digit;\n"
+ " var zero = '0'.charCodeAt(0);\n"
+ "\n"
+ " if (ty < 0) ty = 2 - ty;\n"
+ " ty = (Math.pow(2,zoom) - 1) - ty;\n"
+ "\n"
+ " for (i=zoom, j=0; i>0; i--, j++) {\n"
+ " digit = 0;\n"
+ " mask = 1 << (i-1);\n"
+ " if (tx & mask) digit += 1;\n"
+ " if (ty & mask) digit += 2;\n"
+ " tname += String.fromCharCode(zero + digit);\n"
+ " }\n"
+ " return tname;\n"
+ "}\n"
+ " function WGSQuadTree(tx, ty, zoom) {\n"
+ " var tname = '';\n"
+ " var i, n;\n"
+ " var zero = '0'.charCodeAt(0);\n"
+ "\n"
+ " ty = (Math.pow(2,zoom-1) - 1) - ty;\n"
+ "\n"
+ " for (i=zoom; i>0; i--) {\n"
+ " if (i == 1)\n"
+ " n = Math.floor(tx/2)*4 + tx%2 + (ty%2)*2;\n"
+ " else\n"
+ " n = (ty%2)*2 + tx%2;\n"
+ " if (n<0 || n>9)\n"
+ " return '';\n"
+ " tname = String.fromCharCode(zero + n) + tname;\n"
+ " tx = Math.floor(tx/2);\n"
+ " ty = Math.floor(ty/2);\n"
+ " }\n"
+ " return tname;\n"
+ " }\n"
+ "function get_ve_url (bounds) {\n"
+ " var xoriginShift, yoriginShift, id;\n"
+ " if (this.sphericalMercator) {\n"
+ " xoriginShift = 2 * Math.PI * 6378137.0 / 2.0; // meters\n"
+ " yoriginShift = xoriginShift;\n"
+ " }\n"
+ " else {\n"
+ " xoriginShift = 180.0;\n"
+ " yoriginShift = 90;\n"
+ " }\n"
+ "\n"
+ " var res = this.map.getResolution();\n"
+ " var x = Math.floor(Math.ceil(((bounds.left + bounds.right)/2.0 + xoriginShift) / res / this.tileSize.w) - 1);\n"
+ " var y = Math.floor(Math.ceil(((bounds.top + bounds.bottom)/2.0 + yoriginShift) / res / this.tileSize.h) - 1);\n"
+ " var z = this.map.getZoom();\n"
+ " if (this.sphericalMercator) {\n"
+ " id = QuadTree(x, y, z);\n"
+ " }\n"
+ " else {\n"
+ " id = WGSQuadTree(x, y, z);\n"
+ " }\n"
+ " var path = '?LAYER=' + this.options.layername + '&tile=' + id;\n"
+ " var url = this.url;\n"
+ " if (url instanceof Array) {\n"
+ " url = this.selectUrl(path, url);\n"
+ " }\n"
+ " return url + path;\n"
+ "}\n";
+
+static char *demo_layer_wms =
+ " var %s_%s_wms_layer = new OpenLayers.Layer.WMS( \"%s-%s-WMS\",\n"
" \"%s\",{layers: '%s'},\n"
" { gutter:0,buffer:0,isBaseLayer:true,transitionEffect:'resize',\n"
" resolutions:[%s],\n"
" units:\"%s\",\n"
" maxExtent: new OpenLayers.Bounds(%f,%f,%f,%f),\n"
- " projection: new OpenLayers.Projection(\"%s\")\n"
+ " projection: new OpenLayers.Projection(\"%s\".toUpperCase()),\n"
+ " sphericalMercator: %s\n"
" }\n"
- " );\n";
+ " );\n"
+ " map.addLayer(%s_%s_wms_layer)\n\n";
+static char *demo_layer_tms =
+ " var %s_%s_tms_layer = new OpenLayers.Layer.TMS( \"%s-%s-TMS\",\n"
+ " \"%s\",\n"
+ " { layername: '%s@%s', type: \"%s\", serviceVersion:\"1.0.0\",\n"
+ " gutter:0,buffer:0,isBaseLayer:true,transitionEffect:'resize',\n"
+ " tileOrigin: new OpenLayers.LonLat(%f,%f),\n"
+ " resolutions:[%s],\n"
+ " units:\"%s\",\n"
+ " maxExtent: new OpenLayers.Bounds(%f,%f,%f,%f),\n"
+ " projection: new OpenLayers.Projection(\"%s\".toUpperCase()),\n"
+ " sphericalMercator: %s\n"
+ " }\n"
+ " );\n"
+ " map.addLayer(%s_%s_tms_layer)\n\n";
+
+static char *demo_layer_wmts =
+ " var %s_%s_wmts_layer = new OpenLayers.Layer.WMTS({\n"
+ " name: \"%s-%s-WMTS\",\n"
+ " url: \"%s\",\n"
+ " layer: '%s',\n"
+ " matrixSet: '%s',\n"
+ " format: '%s',\n"
+ " style: 'default',\n"
+ " gutter:0,buffer:0,isBaseLayer:true,transitionEffect:'resize',\n"
+ " resolutions:[%s],\n"
+ " units:\"%s\",\n"
+ " maxExtent: new OpenLayers.Bounds(%f,%f,%f,%f),\n"
+ " projection: new OpenLayers.Projection(\"%s\".toUpperCase()),\n"
+ " sphericalMercator: %s\n"
+ " }\n"
+ " );\n"
+ " map.addLayer(%s_%s_wmts_layer)\n\n";
+
+static char *demo_layer_ve =
+ " var %s_%s_ve_layer = new OpenLayers.Layer.TMS( \"%s-%s-VE\",\n"
+ " \"%s\",\n"
+ " { layername: '%s@%s',\n"
+ " getURL: get_ve_url,\n"
+ " gutter:0,buffer:0,isBaseLayer:true,transitionEffect:'resize',\n"
+ " resolutions:[%s],\n"
+ " units:\"%s\",\n"
+ " maxExtent: new OpenLayers.Bounds(%f,%f,%f,%f),\n"
+ " projection: new OpenLayers.Projection(\"%s\".toUpperCase()),\n"
+ " sphericalMercator: %s\n"
+ " }\n"
+ " );\n"
+ " map.addLayer(%s_%s_ve_layer)\n\n";
+
+#ifdef USE_CAIRO
static char *demo_layer_singletile =
" var %s_%s_slayer = new OpenLayers.Layer.WMS( \"%s-%s (singleTile)\",\n"
" \"%s\",{layers: '%s'},\n"
@@ -56,10 +178,29 @@
" units:\"%s\",\n"
" singleTile:true,\n"
" maxExtent: new OpenLayers.Bounds(%f,%f,%f,%f),\n"
- " projection: new OpenLayers.Projection(\"%s\")\n"
+ " projection: new OpenLayers.Projection(\"%s\".toUpperCase()),\n"
+ " sphericalMercator: %s\n"
" }\n"
- " );\n";
+ " );\n"
+ " map.addLayer(%s_%s_slayer)\n\n";
+#endif
+static char *demo_footer =
+ "%s"
+ " if(!map.getCenter())\n"
+ " map.zoomToMaxExtent();\n"
+ " map.addControl(new OpenLayers.Control.LayerSwitcher());\n"
+ " map.addControl(new OpenLayers.Control.MousePosition());\n"
+ "}\n"
+ " </script>\n"
+ " </head>\n"
+ "\n"
+ "<body onload=\"init()\">\n"
+ " <div id=\"map\">\n"
+ " </div>\n"
+ "</body>\n"
+ "</html>\n";
+
/**
* \brief parse a demo request
* \private \memberof geocache_service_demo
@@ -114,9 +255,9 @@
void _create_demo_wms(geocache_context *ctx, geocache_request_get_capabilities *req,
const char *url_prefix) {
req->mime_type = apr_pstrdup(ctx->pool,"text/html");
- char *caps = apr_pstrdup(ctx->pool,demo_head);
+ char *caps = apr_psprintf(ctx->pool,demo_head, "");
+ char *ol_layer;
apr_hash_index_t *tileindex_index = apr_hash_first(ctx->pool,ctx->config->tilesets);
- char *layers="";
while(tileindex_index) {
geocache_tileset *tileset;
const void *key; apr_ssize_t keylen;
@@ -125,34 +266,42 @@
for(j=0;j<tileset->grid_links->nelts;j++) {
char *resolutions="";
char *unit="dd";
+ char *smerc = "false";
geocache_grid *grid = APR_ARRAY_IDX(tileset->grid_links,j,geocache_grid_link*)->grid;
if(grid->unit == GEOCACHE_UNIT_METERS) {
unit="m";
} else if(grid->unit == GEOCACHE_UNIT_FEET) {
unit="ft";
}
- layers = apr_psprintf(ctx->pool,"%s,%s_%s_layer",layers,tileset->name,grid->name);
- resolutions = apr_psprintf(ctx->pool,"%s%.20f",resolutions,grid->levels[0]->resolution);
-
+ if(strstr(grid->srs, ":900913") || strstr(grid->srs, ":3857")) {
+ smerc = "true";
+ }
+
+ resolutions = apr_psprintf(ctx->pool,"%s%.20f",resolutions,grid->levels[0]->resolution);
for(i=1;i<grid->nlevels;i++) {
resolutions = apr_psprintf(ctx->pool,"%s,%.20f",resolutions,grid->levels[i]->resolution);
}
- char *ol_layer = apr_psprintf(ctx->pool,demo_layer,
+
+ ol_layer = apr_psprintf(ctx->pool,demo_layer_wms,
tileset->name,
grid->name,
tileset->name,
grid->name,
apr_pstrcat(ctx->pool,url_prefix,"/wms?",NULL),
- tileset->name,resolutions,unit,
+ tileset->name,
+ resolutions,
+ unit,
grid->extent[0],
grid->extent[1],
grid->extent[2],
grid->extent[3],
- grid->srs);
+ grid->srs,
+ smerc,
+ tileset->name,
+ grid->name);
caps = apr_psprintf(ctx->pool,"%s%s",caps,ol_layer);
#ifdef USE_CAIRO
- layers = apr_psprintf(ctx->pool,"%s,%s_%s_slayer",layers,tileset->name,grid->name);
ol_layer = apr_psprintf(ctx->pool,demo_layer_singletile,
tileset->name,
grid->name,
@@ -164,33 +313,201 @@
grid->extent[1],
grid->extent[2],
grid->extent[3],
- grid->srs);
+ grid->srs,
+ smerc,
+ tileset->name,
+ grid->name);
caps = apr_psprintf(ctx->pool,"%s%s",caps,ol_layer);
#endif
}
tileindex_index = apr_hash_next(tileindex_index);
}
- /*skip leading comma */
- layers++;
- caps = apr_psprintf(ctx->pool,"%s"
- " map.addLayers([%s]);\n"
- " if(!map.getCenter())\n"
- " map.zoomToMaxExtent();\n"
- " map.addControl(new OpenLayers.Control.LayerSwitcher());\n"
- " map.addControl(new OpenLayers.Control.MousePosition());\n"
- "}\n"
- " </script>\n"
- " </head>\n"
- "\n"
- "<body onload=\"init()\">\n"
- " <div id=\"map\">\n"
- " </div>\n"
- "</body>\n"
- "</html>\n",caps,layers);
+ caps = apr_psprintf(ctx->pool,demo_footer,caps);
req->capabilities = caps;
}
+void _create_demo_tms(geocache_context *ctx, geocache_request_get_capabilities *req,
+ const char *url_prefix) {
+ req->mime_type = apr_pstrdup(ctx->pool,"text/html");
+ char *caps = apr_psprintf(ctx->pool,demo_head, "");
+ char *ol_layer;
+ apr_hash_index_t *tileindex_index = apr_hash_first(ctx->pool,ctx->config->tilesets);
+ while(tileindex_index) {
+ geocache_tileset *tileset;
+ const void *key; apr_ssize_t keylen;
+ apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);
+ int i,j;
+ char *extension = "png";
+ if (tileset->format && tileset->format->extension)
+ extension = tileset->format->extension;
+ for(j=0;j<tileset->grid_links->nelts;j++) {
+ char *resolutions="";
+ char *unit="dd";
+ char *smerc = "false";
+ geocache_grid *grid = APR_ARRAY_IDX(tileset->grid_links,j,geocache_grid_link*)->grid;
+ if(grid->unit == GEOCACHE_UNIT_METERS) {
+ unit="m";
+ } else if(grid->unit == GEOCACHE_UNIT_FEET) {
+ unit="ft";
+ }
+ if(strstr(grid->srs, ":900913") || strstr(grid->srs, ":3857")) {
+ smerc = "true";
+ }
+
+ resolutions = apr_psprintf(ctx->pool,"%s%.20f",resolutions,grid->levels[0]->resolution);
+ for(i=1;i<grid->nlevels;i++) {
+ resolutions = apr_psprintf(ctx->pool,"%s,%.20f",resolutions,grid->levels[i]->resolution);
+ }
+
+ ol_layer = apr_psprintf(ctx->pool, demo_layer_tms,
+ tileset->name,
+ grid->name,
+ tileset->name,
+ grid->name,
+ apr_pstrcat(ctx->pool,url_prefix,"/tms/",NULL),
+ tileset->name,
+ grid->name,
+ extension,
+ grid->extent[0],
+ grid->extent[1],
+ resolutions,
+ unit,
+ grid->extent[0],
+ grid->extent[1],
+ grid->extent[2],
+ grid->extent[3],
+ grid->srs,
+ smerc,
+ tileset->name,
+ grid->name);
+ caps = apr_psprintf(ctx->pool,"%s%s",caps,ol_layer);
+ }
+ tileindex_index = apr_hash_next(tileindex_index);
+ }
+ caps = apr_psprintf(ctx->pool,demo_footer,caps);
+
+ req->capabilities = caps;
+}
+
+void _create_demo_wmts(geocache_context *ctx, geocache_request_get_capabilities *req,
+ const char *url_prefix) {
+ req->mime_type = apr_pstrdup(ctx->pool,"text/html");
+ char *caps = apr_psprintf(ctx->pool,demo_head, "");
+ char *ol_layer;
+ apr_hash_index_t *tileindex_index = apr_hash_first(ctx->pool,ctx->config->tilesets);
+ while(tileindex_index) {
+ geocache_tileset *tileset;
+ const void *key; apr_ssize_t keylen;
+ apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);
+ int i,j;
+ char *mime_type = "image/png";
+ if (tileset->format && tileset->format->mime_type)
+ mime_type = tileset->format->mime_type;
+ for(j=0;j<tileset->grid_links->nelts;j++) {
+ char *resolutions="";
+ char *unit="dd";
+ char *smerc = "false";
+ geocache_grid *grid = APR_ARRAY_IDX(tileset->grid_links,j,geocache_grid_link*)->grid;
+ if(grid->unit == GEOCACHE_UNIT_METERS) {
+ unit="m";
+ } else if(grid->unit == GEOCACHE_UNIT_FEET) {
+ unit="ft";
+ }
+ if(strstr(grid->srs, ":900913") || strstr(grid->srs, ":3857")) {
+ smerc = "true";
+ }
+
+ resolutions = apr_psprintf(ctx->pool,"%s%.20f",resolutions,grid->levels[0]->resolution);
+ for(i=1;i<grid->nlevels;i++) {
+ resolutions = apr_psprintf(ctx->pool,"%s,%.20f",resolutions,grid->levels[i]->resolution);
+ }
+
+ ol_layer = apr_psprintf(ctx->pool, demo_layer_wmts,
+ tileset->name,
+ grid->name,
+ tileset->name,
+ grid->name,
+ apr_pstrcat(ctx->pool,url_prefix,"/wmts/",NULL),
+ tileset->name,
+ grid->name,
+ mime_type,
+ resolutions,
+ unit,
+ grid->extent[0],
+ grid->extent[1],
+ grid->extent[2],
+ grid->extent[3],
+ grid->srs,
+ smerc,
+ tileset->name,
+ grid->name);
+ caps = apr_psprintf(ctx->pool,"%s%s",caps,ol_layer);
+ }
+ tileindex_index = apr_hash_next(tileindex_index);
+ }
+ caps = apr_psprintf(ctx->pool,demo_footer,caps);
+
+ req->capabilities = caps;
+}
+
+void _create_demo_ve(geocache_context *ctx, geocache_request_get_capabilities *req,
+ const char *url_prefix) {
+ req->mime_type = apr_pstrdup(ctx->pool,"text/html");
+ char *caps = apr_psprintf(ctx->pool,demo_head, demo_ve_extra);
+ char *ol_layer;
+ apr_hash_index_t *tileindex_index = apr_hash_first(ctx->pool,ctx->config->tilesets);
+ while(tileindex_index) {
+ geocache_tileset *tileset;
+ const void *key; apr_ssize_t keylen;
+ apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);
+ int i,j;
+ for(j=0;j<tileset->grid_links->nelts;j++) {
+ char *resolutions="";
+ char *unit="dd";
+ char *smerc = "false";
+ geocache_grid *grid = APR_ARRAY_IDX(tileset->grid_links,j,geocache_grid_link*)->grid;
+ if(grid->unit == GEOCACHE_UNIT_METERS) {
+ unit="m";
+ } else if(grid->unit == GEOCACHE_UNIT_FEET) {
+ unit="ft";
+ }
+ if(strstr(grid->srs, ":900913") || strstr(grid->srs, ":3857")) {
+ smerc = "true";
+ }
+
+ resolutions = apr_psprintf(ctx->pool,"%s%.20f",resolutions,grid->levels[0]->resolution);
+ for(i=1;i<grid->nlevels;i++) {
+ resolutions = apr_psprintf(ctx->pool,"%s,%.20f",resolutions,grid->levels[i]->resolution);
+ }
+
+ ol_layer = apr_psprintf(ctx->pool, demo_layer_ve,
+ tileset->name,
+ grid->name,
+ tileset->name,
+ grid->name,
+ apr_pstrcat(ctx->pool,url_prefix,"/ve",NULL),
+ tileset->name,
+ grid->name,
+ resolutions,
+ unit,
+ grid->extent[0],
+ grid->extent[1],
+ grid->extent[2],
+ grid->extent[3],
+ grid->srs,
+ smerc,
+ tileset->name,
+ grid->name);
+ caps = apr_psprintf(ctx->pool,"%s%s",caps,ol_layer);
+ }
+ tileindex_index = apr_hash_next(tileindex_index);
+ }
+ caps = apr_psprintf(ctx->pool,demo_footer,caps);
+
+ req->capabilities = caps;
+}
+
void _create_capabilities_demo(geocache_context *ctx, geocache_request_get_capabilities *req,
char *url, char *path_info, geocache_cfg *cfg) {
geocache_request_get_capabilities_demo *request = (geocache_request_get_capabilities_demo*)req;
@@ -205,11 +522,14 @@
switch(request->service->type) {
case GEOCACHE_SERVICE_WMS:
return _create_demo_wms(ctx,req,onlineresource);
- case GEOCACHE_SERVICE_GMAPS:
case GEOCACHE_SERVICE_TMS:
+ return _create_demo_tms(ctx,req,onlineresource);
case GEOCACHE_SERVICE_WMTS:
+ return _create_demo_wmts(ctx,req,onlineresource);
+ case GEOCACHE_SERVICE_VE:
+ return _create_demo_ve(ctx,req,onlineresource);
case GEOCACHE_SERVICE_KML:
- case GEOCACHE_SERVICE_VE:
+ case GEOCACHE_SERVICE_GMAPS:
req->mime_type = apr_pstrdup(ctx->pool,"text/plain");
req->capabilities = apr_pstrdup(ctx->pool,"not implemented");
return;
More information about the mapserver-commits
mailing list