Hi,

attached is my now cleaned up patch for mod_tile.c that can be used to display 
a transparent overlay layer showing the oceantiles status os a tile.
Screenshot attached too.
I did not spent too long time in optimizing the overlay images. I tried dotted 
images, but that was sometimes hart to distinguish when usinf 1px dots. larger 
dots lookeg ugly. Small border only was not enought too in my opinion, thats 
why I used L S and X, so it is clear without color too. 

Spaetz: If you dont want to modify mod_tile I could implement that in python 
for django next week ;-)


Cheers, Martin.

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: 
http://www.gmx.net/de/go/multimessenger

<<attachment: Screenshot.png>>

Index: mod_tah.c
===================================================================
--- mod_tah.c	(revision 11432)
+++ mod_tah.c	(working copy)
@@ -81,7 +81,61 @@
   "\x00\x00\x00\x00\x00\x00\x00\x00\x78\x03\x01\x3c\x00\x01\xd8\x29"
   "\x43\x04\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
 
+const char ot_land[] = 
+  "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52"
+  "\x00\x00\x01\x00\x00\x00\x01\x00\x01\x03\x00\x00\x00\x66\xbc\x3a"
+  "\x25\x00\x00\x00\x01\x73\x52\x47\x42\x00\xae\xce\x1c\xe9\x00\x00"
+  "\x00\x06\x50\x4c\x54\x45\xb7\x90\x21\x00\xff\x00\xf8\x04\x88\x3b"
+  "\x00\x00\x00\x01\x74\x52\x4e\x53\x00\x40\xe6\xd8\x66\x00\x00\x00"
+  "\x01\x62\x4b\x47\x44\x00\x88\x05\x1d\x48\x00\x00\x00\x09\x70\x48"
+  "\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a\x9c\x18\x00"
+  "\x00\x00\x07\x74\x49\x4d\x45\x07\xd8\x0a\x16\x12\x34\x11\xc3\x43"
+  "\x80\x1b\x00\x00\x00\x57\x49\x44\x41\x54\x68\xde\xed\xd9\xa1\x0d"
+  "\x00\x30\x08\x04\x40\x46\x61\x8c\xee\x3f\x59\x07\xa8\x78\xd1\x04"
+  "\x41\xee\x2d\x2f\xe0\x2c\x55\xdf\xe9\x90\x89\xc2\x09\xa9\x81\x74"
+  "\x1a\x0f\x14\xc2\xa1\x1c\x38\x70\xe0\xc0\x81\x03\x07\x0e\x1c\x38"
+  "\x70\xe0\xc0\x81\x03\x07\x0e\x1c\x38\x70\xe0\xc0\x81\x03\x07\x0e"
+  "\x1c\x38\x70\xe0\xc0\x81\xc3\xbb\xc5\x86\xbf\xff\x05\x48\xda\x59"
+  "\x21\x14\xc2\x72\x3a\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60"
+  "\x82";
 
+const char ot_sea[] = 
+  "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52"
+  "\x00\x00\x01\x00\x00\x00\x01\x00\x01\x03\x00\x00\x00\x66\xbc\x3a"
+  "\x25\x00\x00\x00\x01\x73\x52\x47\x42\x00\xae\xce\x1c\xe9\x00\x00"
+  "\x00\x06\x50\x4c\x54\x45\xb7\x90\xc1\x00\x00\xff\x90\x5d\xdb\xfc"
+  "\x00\x00\x00\x01\x74\x52\x4e\x53\x00\x40\xe6\xd8\x66\x00\x00\x00"
+  "\x01\x62\x4b\x47\x44\x00\x88\x05\x1d\x48\x00\x00\x00\x09\x70\x48"
+  "\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a\x9c\x18\x00"
+  "\x00\x00\x07\x74\x49\x4d\x45\x07\xd8\x0a\x16\x12\x37\x0e\x65\x66"
+  "\xde\x2d\x00\x00\x00\x62\x49\x44\x41\x54\x68\xde\xed\xd9\xb1\x0d"
+  "\x00\x31\x08\x03\x40\x4a\xc6\x60\x8c\xec\x3f\xd9\xf7\x5f\xc4\x45"
+  "\xa4\x14\xd1\xb9\x05\x19\xe9\x5a\xaa\x8e\xb3\x42\x6a\x42\x72\x43"
+  "\x87\xe4\x86\x0b\x59\x69\x3c\xfb\x85\xc9\x0d\xbd\x5f\xe8\xdc\xc0"
+  "\x81\x03\x07\x0e\x1c\x38\x70\xe0\xc0\x81\x03\x07\x0e\x1c\x38\x70"
+  "\xe0\xc0\x81\x03\x07\x0e\x1c\x38\x70\xe0\xc0\x81\x03\x07\x0e\x1c"
+  "\x38\xfc\x8f\xbc\xf0\xf7\xff\x00\xe3\x57\x64\xc1\x5d\x75\xec\xa9"
+  "\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
+
+const char ot_mixed[] = 
+  "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52"
+  "\x00\x00\x01\x00\x00\x00\x01\x00\x01\x03\x00\x00\x00\x66\xbc\x3a"
+  "\x25\x00\x00\x00\x01\x73\x52\x47\x42\x00\xae\xce\x1c\xe9\x00\x00"
+  "\x00\x06\x50\x4c\x54\x45\xb7\x90\xf1\x00\x00\x00\x4d\x74\xcc\xd0"
+  "\x00\x00\x00\x01\x74\x52\x4e\x53\x00\x40\xe6\xd8\x66\x00\x00\x00"
+  "\x01\x62\x4b\x47\x44\x00\x88\x05\x1d\x48\x00\x00\x00\x09\x70\x48"
+  "\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a\x9c\x18\x00"
+  "\x00\x00\x07\x74\x49\x4d\x45\x07\xd8\x0a\x16\x12\x35\x29\xf2\x5a"
+  "\x09\xc4\x00\x00\x00\x5b\x49\x44\x41\x54\x68\xde\xed\xd9\xb1\x0d"
+  "\x00\x20\x0c\x03\x30\x4e\xe8\x19\xfc\x7f\x21\x3b\x03\x19\xa8\x18"
+  "\x90\xb3\x36\x52\x24\xaf\x1d\xe3\x3a\x33\x24\x17\x2a\xa4\x61\xe2"
+  "\x41\x66\x3a\xc7\x42\x9d\x0b\xd5\x30\xc1\x81\x03\x07\x0e\x1c\x38"
+  "\x70\xe0\xc0\x81\x03\x07\x0e\x1c\x38\x70\xe0\xc0\x81\x03\x07\x0e"
+  "\x1c\x38\x70\xe0\xc0\x81\x03\x07\x0e\x1c\x38\xec\x23\x3f\xfc\xfd"
+  "\x17\x94\x77\x55\x41\x83\x13\x18\xc1\x00\x00\x00\x00\x49\x45\x4e"
+  "\x44\xae\x42\x60\x82";
+
+
 typedef struct dir_data_t dir_data_t;
 struct dir_data_t {
   int state;
@@ -139,6 +193,14 @@
 }
 
 
+/* serves the given char buffer as png image */
+static int serve_png( request_rec *r, const char *data, int size) {
+  if( size == 0) return HTTP_NOT_FOUND;
+  ap_set_content_type(r, content_imagepng);
+  ap_set_content_length(r, size);
+  ap_rwrite(data,size,r);
+  return OK;
+}
 
 static int serve_tileset(request_rec* r, request_data* d) {
   char * tilesetName;
@@ -188,39 +250,22 @@
   d->tileOffset = offset_table[tileNo];
 
   if (d->tileOffset < MIN_VALID_OFFSET) {
+    apr_mmap_delete(header);
+    apr_file_close(d->tileset);
     switch (d->tileOffset) {
       case 0: {
-        apr_mmap_delete(header);
-        apr_file_close(d->tileset);
         return HTTP_NOT_FOUND;
       }
       case 1: {
-        ap_set_content_length(r, sizeof(sea));
-        ap_set_content_type(r, content_imagepng);
-        ap_rwrite(sea,sizeof(sea),r);
-        apr_mmap_delete(header);
-        apr_file_close(d->tileset);
-        return OK;
+        return( serve_png(r,sea,sizeof(sea)));
       }
       case 2: {
-        ap_set_content_length(r, sizeof(land));
-        ap_set_content_type(r, content_imagepng);
-        ap_rwrite(land,sizeof(land),r);
-        apr_mmap_delete(header);
-        apr_file_close(d->tileset);
-        return OK;
+        return( serve_png(r,land,sizeof(land)));
       }
       case 3: {
-        ap_set_content_length(r, sizeof(transparent));   /* TRANSPARENT */
-        ap_set_content_type(r, content_imagepng);
-        ap_rwrite(transparent,sizeof(transparent),r);
-        apr_mmap_delete(header);
-        apr_file_close(d->tileset);
-        return OK;
+        return( serve_png(r,transparent,sizeof(transparent)));
       }
       default: { /* ERROR_TILE */
-        apr_mmap_delete(header);
-        apr_file_close(d->tileset);
         return HTTP_NOT_FOUND;
       }
     }
@@ -278,7 +323,7 @@
   return 0;
 }
 
-static int serve_oceantile(request_rec *r, request_data* rd) {
+static int serve_oceantile(request_rec *r, request_data* rd, const char *i1, int s1, const char *i2, int s2, const char *i3, int s3 ) {
   char * fileName;
   apr_status_t res;
   apr_size_t len;
@@ -287,14 +332,6 @@
   int bit_off;
   int type;
 
-  /* send transparent tile if transparent layer */
-  if (is_transparent_layer(rd->layer)) {
-    ap_set_content_type(r, content_imagepng);
-    ap_set_content_length(r, sizeof(transparent));
-    ap_rwrite(transparent,sizeof(transparent),r);
-    return OK;
-  }
-
   if (rd->z < 12) {
     /* only available for zooms levels >= 12. */
     return HTTP_NOT_FOUND;
@@ -313,19 +350,15 @@
       case 0: {
         return HTTP_NOT_FOUND;
       }
-      case 1: {
-        ap_set_content_type(r, content_imagepng);
-        ap_set_content_length(r, sizeof(land));
-        ap_rwrite(land,sizeof(land),r);
-        return OK;
+      case 1: {  /* land */
+        return( serve_png(r,i1,s1));
       }
-      case 2:     
-      case 3: {  /* Also for type mixed */
-        ap_set_content_type(r, content_imagepng);
-        ap_set_content_length(r, sizeof(sea));
-        ap_rwrite(sea,sizeof(sea),r);
-        return OK;
+      case 2: {  /* sea */
+        return( serve_png(r,i2,s2));
       }
+      case 3: {  /* mixed */
+        return( serve_png(r,i3,s3));
+      }
     } 
   }
 } /* serve_oceantile */
@@ -359,8 +392,16 @@
 
   int code;
   if( (code = serve_tileset(r, d)) != HTTP_NOT_FOUND ) { return code; }
+
   /* not found. look into the OceanDB. Fail if problem */
-  return serve_oceantile(r, d);
+  if (is_transparent_layer(d->layer)) {
+    /* send transparent tile for transparent layers */
+    return( serve_png(r,transparent,sizeof(transparent)));
+  }
+  if(strcmp(d->layer,"oceantiles")==0) {
+    return serve_oceantile(r, d, ot_land, sizeof(ot_land), ot_sea, sizeof(ot_sea), ot_mixed, sizeof(ot_mixed));
+  }
+  return serve_oceantile(r, d, land, sizeof(land), sea, sizeof(sea), sea, sizeof(sea));
 } /* tah_handler */
 
 
_______________________________________________
Tilesathome mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/tilesathome

Reply via email to