void KmlRenderer::setupRenderingParams(hashTableObj *layerMetadata) { AltitudeMode = 0; Extrude = 0; Tessellate = 0; const char *altitudeModeVal = msLookupHashTable(layerMetadata, "kml_altitudeMode"); if (altitudeModeVal) { if(strcasecmp(altitudeModeVal, "absolute") == 0) AltitudeMode = absolute; else if(strcasecmp(altitudeModeVal, "relativeToGround") == 0) AltitudeMode = relativeToGround; else if(strcasecmp(altitudeModeVal, "clampToGround") == 0) AltitudeMode = clampToGround; } const char *extrudeVal = msLookupHashTable(layerMetadata, "kml_extrude"); if (altitudeModeVal) { Extrude = atoi(extrudeVal); } const char *tessellateVal = msLookupHashTable(layerMetadata, "kml_tessellate"); if (tessellateVal) { Tessellate = atoi(tessellateVal); } }
/************************************************************************ * msTileSetParams * ************************************************************************/ static void msTileGetParams(mapObj *map, tileParams *params) { const char *value = NULL; hashTableObj *meta = &(map->web.metadata); params->tile_size = SPHEREMERC_IMAGE_SIZE; /* Check for tile buffer, set to buffer==0 as default */ if((value = msLookupHashTable(meta, "tile_map_edge_buffer")) != NULL) { params->map_edge_buffer = atoi(value); if(map->debug) msDebug("msTileSetParams(): tile_map_edge_buffer = %d\n", params->map_edge_buffer); } else params->map_edge_buffer = 0; /* Check for metatile size, set to tile==metatile as default */ if((value = msLookupHashTable(meta, "tile_metatile_level")) != NULL) { params->metatile_level = atoi(value); /* Quietly force metatile_level to be sane */ if( params->metatile_level < 0 ) params->metatile_level = 0; if( params->metatile_level > 2 ) params->metatile_level = 2; if(map->debug) msDebug("msTileSetParams(): tile_metatile_level = %d\n", params->metatile_level); } else params->metatile_level = 0; }
void KmlRenderer::processLayer(layerObj *layer, outputFormatObj *format) { int i; const char *asRaster = NULL; int nMaxFeatures = -1; const char *pszTmp; char szTmp[10]; if (!layer) return; /*turn of labelcache*/ layer->labelcache = MS_OFF; /*if there are labels we want the coordinates to be the center of the element.*/ for(i=0; i<layer->numclasses; i++) if(layer->_class[i]->numlabels > 0) layer->_class[i]->labels[0]->position = MS_XY; /*we do not want to draw multiple styles. the new rendering architecture does not allow to know if we are dealing with a multi-style. So here we remove all styles beside the first one*/ for(i=0; i<layer->numclasses; i++) { while (layer->_class[i]->numstyles > 1) msDeleteStyle(layer->_class[i], layer->_class[i]->numstyles-1); } /*if layer has a metadata KML_OUTPUTASRASTER set to true, add a processing directive to use an agg driver*/ asRaster = msLookupHashTable(&layer->metadata, "kml_outputasraster"); if (!asRaster) asRaster = msLookupHashTable(&(layer->map->web.metadata), "kml_outputasraster"); if (asRaster && (strcasecmp(asRaster, "true") == 0 || strcasecmp(asRaster, "yes") == 0)) msLayerAddProcessing(layer, "RENDERER=png24"); /*set a maxfeaturestodraw, if not already set*/ pszTmp = msLookupHashTable(&layer->metadata, "maxfeaturestodraw"); if (pszTmp) nMaxFeatures = atoi(pszTmp); else { pszTmp = msLookupHashTable(&layer->map->web.metadata, "maxfeaturestodraw"); if (pszTmp) nMaxFeatures = atoi(pszTmp); } if (nMaxFeatures < 0 && format) nMaxFeatures = atoi(msGetOutputFormatOption( format, "maxfeaturestodraw", "-1")); if (nMaxFeatures < 0 && format) { snprintf(szTmp, sizeof(szTmp), "%d", KML_MAXFEATURES_TODRAW); msSetOutputFormatOption( format, "maxfeaturestodraw", szTmp); } }
int msSetConfigOption( mapObj *map, const char *key, const char *value) { /* We have special "early" handling of this so that it will be */ /* in effect when the projection blocks are parsed and pj_init is called. */ if( strcasecmp(key,"PROJ_LIB") == 0 ) { /* value may be relative to map path */ msSetPROJ_LIB( value, map->mappath ); } /* Same for MS_ERRORFILE, we want it to kick in as early as possible * to catch parsing errors. * Value can be relative to mapfile, unless it's already absolute */ if( strcasecmp(key,"MS_ERRORFILE") == 0 ) { if (msSetErrorFile( value, map->mappath ) != MS_SUCCESS) return MS_FAILURE; } if( msLookupHashTable( &(map->configoptions), key ) != NULL ) msRemoveHashTable( &(map->configoptions), key ); msInsertHashTable( &(map->configoptions), key, value ); return MS_SUCCESS; }
void msApplyMapConfigOptions( mapObj *map ) { const char *key; for( key = msFirstKeyFromHashTable( &(map->configoptions) ); key != NULL; key = msNextKeyFromHashTable( &(map->configoptions), key ) ) { const char *value = msLookupHashTable( &(map->configoptions), key ); if( strcasecmp(key,"PROJ_LIB") == 0 ) { msSetPROJ_LIB( value, map->mappath ); } else if( strcasecmp(key,"MS_ERRORFILE") == 0 ) { msSetErrorFile( value, map->mappath ); } else { #if defined(USE_GDAL) && GDAL_RELEASE_DATE > 20030601 CPLSetConfigOption( key, value ); #endif } } }
char* KmlRenderer::lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyleObj *symstyle) { char symbolHexColor[32]; /* <Style id="randomColorIcon"> <IconStyle> <color>ff00ff00</color> <colorMode>random</colorMode> <scale>1.1</scale> <Icon> <href>http://maps.google.com/mapfiles/kml/pal3/icon21.png</href> </Icon> </IconStyle> </Style> */ sprintf(symbolHexColor,"%02x%02x%02x%02x", symstyle->style->color.alpha, symstyle->style->color.blue, symstyle->style->color.green, symstyle->style->color.red); snprintf(SymbolName, sizeof(SymbolName), "symbol_%s_%.1f_%s", symbol->name, symstyle->scale, symbolHexColor); char *symbolUrl = msLookupHashTable(StyleHashTable, SymbolName); if (!symbolUrl) { char iconFileName[MS_MAXPATHLEN]; char iconUrl[MS_MAXPATHLEN]; if (img->imagepath) { char *tmpFileName = msTmpFile(NULL, MapPath, img->imagepath, "png"); snprintf(iconFileName, sizeof(iconFileName), "%s", tmpFileName); msFree(tmpFileName); } else { sprintf(iconFileName, "symbol_%s_%.1f.%s", symbol->name, symstyle->scale, "png"); } if (createIconImage(iconFileName, symbol, symstyle) != MS_SUCCESS) { char errMsg[512]; sprintf(errMsg, "Error creating icon file '%s'", iconFileName); msSetError(MS_IOERR, errMsg, "KmlRenderer::lookupSymbolStyle()" ); return NULL; } if (img->imageurl) sprintf(iconUrl, "%s%s.%s", img->imageurl, msGetBasename(iconFileName), "png"); else snprintf(iconUrl, sizeof(iconUrl), "%s", iconFileName); hashObj *hash = msInsertHashTable(StyleHashTable, SymbolName, iconUrl); symbolUrl = hash->data; } return symbolUrl; }
int msCopyHashTable(hashTableObj *dst, hashTableObj *src) { const char *key=NULL; while (1) { key = msNextKeyFromHashTable(src, key); if (!key) break; else msInsertHashTable(dst, key, msLookupHashTable(src, key)); } return MS_SUCCESS; }
Handle<Value> MSHashTable::NamedGetter (Local<String> property, const AccessorInfo& info) { MSHashTable *table = ObjectWrap::Unwrap<MSHashTable>(info.This()); v8::String::AsciiValue key(property); char *value; hashTableObj *metadataTable = table->this_; value = msLookupHashTable(metadataTable, *key); if (value == NULL){ return Undefined(); } RETURN_STRING(value); }
int msFontsetLookupFonts(char* fontstring, int *numfonts, fontSetObj *fontset, char **lookedUpFonts) { char *start,*ptr; *numfonts = 0; start = ptr = fontstring; while(*numfonts<MS_MAX_LABEL_FONTS) { if(*ptr==',') { if(start==ptr) { /*first char is a comma, or two successive commas*/ start = ++ptr; continue; } *ptr = 0; lookedUpFonts[*numfonts] = msLookupHashTable(&(fontset->fonts), start); *ptr = ','; if (!lookedUpFonts[*numfonts]) { msSetError(MS_TTFERR, "Requested font (%s) not found.","msFontsetLookupFonts()", fontstring); return MS_FAILURE; } start = ++ptr; (*numfonts)++; } else if(*ptr==0) { if(start==ptr) { /* last char of string was a comma */ return MS_SUCCESS; } lookedUpFonts[*numfonts] = msLookupHashTable(&(fontset->fonts), start); if (!lookedUpFonts[*numfonts]) { msSetError(MS_TTFERR, "Requested font (%s) not found.","msFontsetLookupFonts()", fontstring); return (MS_FAILURE); } (*numfonts)++; return MS_SUCCESS; } else { ptr++; } } msSetError(MS_TTFERR, "Requested font (%s) not has too many members (max is %d)", "msFontsetLookupFonts()", fontstring, MS_MAX_LABEL_FONTS); return MS_FAILURE; }
char *msFontsetLookupFont(fontSetObj *fontset, char *fontKey) { char *font; if(!fontKey) { msSetError(MS_TTFERR, "Requested font (NULL) not found.", "msFontsetLookupFont()"); return NULL; } font = msLookupHashTable(&(fontset->fonts), fontKey); if(!font) { msSetError(MS_TTFERR, "Requested font (%s) not found.", "msFontsetLookupFont()", fontKey); return NULL; } return font; }
static void msTileResetMetatileLevel(mapObj *map) { hashTableObj *meta = &(map->web.metadata); const char *zero = "0"; const char *value = NULL; /* Is the tile_metatile_levetl set... */ if((value = msLookupHashTable(meta, "tile_metatile_level")) != NULL) { msRemoveHashTable(meta, "tile_metatile_level"); msInsertHashTable(meta, "tile_metatile_level", zero); } /* No tile_metatile_level value. */ else { msInsertHashTable(meta, "tile_metatile_level", zero); } }
char* KmlRenderer::getLayerName(layerObj *layer) { char stmp[20]; const char *name=NULL;; if (!layer) return NULL; name = msLookupHashTable(&layer->metadata, "ows_name"); if (name && strlen(name) > 0) return msStrdup(name); if (layer->name && strlen(layer->name) > 0) return msStrdup(layer->name); sprintf(stmp, "Layer%d",layer->index); return msStrdup(stmp); }
char *mapObj_getMetaData(mapObj *self, char *name) { return(msLookupHashTable(&(self->web.metadata), name)); }
/* * RFC89 implementation: * - transform directly the shapeobj */ int msGeomTransformShape(mapObj *map, layerObj *layer, shapeObj *shape) { int i; expressionObj *e = &layer->_geomtransform; #ifdef USE_V8_MAPSCRIPT if (!map->v8context) { msV8CreateContext(map); if (!map->v8context) { msSetError(MS_V8ERR, "Unable to create v8 context.", "msGeomTransformShape()"); return MS_FAILURE; } } msV8ContextSetLayer(map, layer); #endif switch(e->type) { case MS_GEOMTRANSFORM_EXPRESSION: { int status; shapeObj *tmpshp; parseObj p; p.shape = shape; /* set a few parser globals (hence the lock) */ p.expr = e; p.expr->curtoken = p.expr->tokens; /* reset */ p.type = MS_PARSE_TYPE_SHAPE; p.dblval = map->cellsize * (msInchesPerUnit(map->units,0)/msInchesPerUnit(layer->units,0)); p.dblval2 = 0; /* data_cellsize is only set with contour layer */ if (layer->connectiontype == MS_CONTOUR) { char *value = msLookupHashTable(&layer->metadata, "__data_cellsize__"); if (value) p.dblval2 = atof(value); } status = yyparse(&p); if (status != 0) { msSetError(MS_PARSEERR, "Failed to process shape expression: %s", "msGeomTransformShape()", e->string); return MS_FAILURE; } tmpshp = p.result.shpval; for (i= 0; i < shape->numlines; i++) free(shape->line[i].point); shape->numlines = 0; if (shape->line) free(shape->line); for(i=0; i<tmpshp->numlines; i++) msAddLine(shape, &(tmpshp->line[i])); /* copy each line */ msFreeShape(tmpshp); msFree(tmpshp); } break; default: msSetError(MS_MISCERR, "unknown geomtransform", "msGeomTransformShape()"); return MS_FAILURE; } return MS_SUCCESS; }
int updateMap(mapservObj *mapserv, mapObj *map) { int i, j; if(!msLookupHashTable(&(map->web.validation), "immutable")) { /* check for any %variable% substitutions here, also do any map_ changes, we do this here so WMS/WFS */ /* services can take advantage of these "vendor specific" extensions */ for(i=0; i<mapserv->request->NumParams; i++) { /* ** a few CGI variables should be skipped altogether ** ** qstring: there is separate per layer validation for attribute queries and the substitution checks ** below conflict with that so we avoid it here */ if(strncasecmp(mapserv->request->ParamNames[i],"qstring",7) == 0) continue; /* check to see if there are any additions to the mapfile */ if(strncasecmp(mapserv->request->ParamNames[i],"map_",4) == 0 || strncasecmp(mapserv->request->ParamNames[i],"map.",4) == 0) { msAcquireLock( TLOCK_PARSER ); if(msUpdateMapFromURL(map, mapserv->request->ParamNames[i], mapserv->request->ParamValues[i]) != MS_SUCCESS) { msReleaseLock( TLOCK_PARSER ); return MS_FAILURE; } msReleaseLock( TLOCK_PARSER ); continue; } if(strncasecmp(mapserv->request->ParamNames[i],"classgroup",10) == 0) { /* #4207 */ for(j=0; j<map->numlayers; j++) { setClassGroup(GET_LAYER(map, j), mapserv->request->ParamValues[i]); } continue; } } msApplySubstitutions(map, mapserv->request->ParamNames, mapserv->request->ParamValues, mapserv->request->NumParams); msApplyDefaultSubstitutions(map); /* check to see if a ogc map context is passed as argument. if there */ /* is one load it */ for(i=0; i<mapserv->request->NumParams; i++) { if(strcasecmp(mapserv->request->ParamNames[i],"context") == 0) { if(mapserv->request->ParamValues[i] && strlen(mapserv->request->ParamValues[i]) > 0) { if(strncasecmp(mapserv->request->ParamValues[i],"http",4) == 0) { if(msGetConfigOption(map, "CGI_CONTEXT_URL")) msLoadMapContextURL(map, mapserv->request->ParamValues[i], MS_FALSE); } else msLoadMapContext(map, mapserv->request->ParamValues[i], MS_FALSE); } } } } /* * RFC-42 HTTP Cookie Forwarding * Here we set the http_cookie_data metadata to handle the * HTTP Cookie Forwarding. The content of this metadata is the cookie * content. In the future, this metadata will probably be replaced * by an object that is part of the mapObject that would contain * information on the application status (such as cookie). */ if( mapserv->request->httpcookiedata != NULL ) { msInsertHashTable( &(map->web.metadata), "http_cookie_data", mapserv->request->httpcookiedata ); } return MS_SUCCESS; }
int msPrepareWFSLayerRequest(int nLayerId, mapObj *map, layerObj *lp, httpRequestObj *pasReqInfo, int *numRequests) { #ifdef USE_WFS_LYR char *pszURL = NULL; const char *pszTmp; rectObj bbox; int nTimeout; int nStatus = MS_SUCCESS; msWFSLayerInfo *psInfo = NULL; int bPostRequest = 0; wfsParamsObj *psParams = NULL; char *pszHTTPCookieData = NULL; if (lp->connectiontype != MS_WFS || lp->connection == NULL) return MS_FAILURE; /* ------------------------------------------------------------------ * Build a params object that will be used by to build the request, this will also set layer projection and compute BBOX in that projection. * ------------------------------------------------------------------ */ psParams = msBuildRequestParams(map, lp, &bbox); if (!psParams) return MS_FAILURE; /* -------------------------------------------------------------------- */ /* Depending on the metadata wfs_request_method, build a Get or */ /* a Post URL. */ /* If it is a Get request the URL would contain all the parameters in*/ /* the string; */ /* If it is a Post request, the URL will only contain the */ /* connection string comming from the layer. */ /* -------------------------------------------------------------------- */ if ((pszTmp = msOWSLookupMetadata(&(lp->metadata), "FO", "request_method")) != NULL) { if (strncmp(pszTmp, "GET", 3) ==0) { pszURL = msBuildWFSLayerGetURL(map, lp, &bbox, psParams); if (!pszURL) { /* an error was already reported. */ return MS_FAILURE; } } } /* else it is a post request and just get the connection string */ if (!pszURL) { bPostRequest = 1; pszURL = msStrdup(lp->connection); } /* ------------------------------------------------------------------ * check to see if a the metadata wfs_connectiontimeout is set. If it is * the case we will use it, else we use the default which is 30 seconds. * First check the metadata in the layer object and then in the map object. * ------------------------------------------------------------------ */ nTimeout = 30; /* Default is 30 seconds */ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata), "FO", "connectiontimeout")) != NULL) { nTimeout = atoi(pszTmp); } /*------------------------------------------------------------------ * Check to see if there's a HTTP Cookie to forward * If Cookie differ between the two connection, it's NOT OK to merge * the connection * ------------------------------------------------------------------ */ if ((pszTmp = msOWSLookupMetadata(&(lp->metadata), "FO", "http_cookie")) != NULL) { if(strcasecmp(pszTmp, "forward") == 0) { pszTmp= msLookupHashTable(&(map->web.metadata),"http_cookie_data"); if(pszTmp != NULL) { pszHTTPCookieData = msStrdup(pszTmp); } } else { pszHTTPCookieData = msStrdup(pszTmp); } } else if ((pszTmp = msOWSLookupMetadata(&(map->web.metadata), "FO", "http_cookie")) != NULL) { if(strcasecmp(pszTmp, "forward") == 0) { pszTmp= msLookupHashTable(&(map->web.metadata),"http_cookie_data"); if(pszTmp != NULL) { pszHTTPCookieData = msStrdup(pszTmp); } } else { pszHTTPCookieData = msStrdup(pszTmp); } } /* ------------------------------------------------------------------ * If nLayerId == -1 then we need to figure it * ------------------------------------------------------------------ */ if (nLayerId == -1) { int iLayer; for(iLayer=0; iLayer < map->numlayers; iLayer++) { if (GET_LAYER(map, iLayer) == lp) { nLayerId = iLayer; break; } } } /* ------------------------------------------------------------------ * Add a request to the array (already preallocated) * ------------------------------------------------------------------ */ pasReqInfo[(*numRequests)].nLayerId = nLayerId; pasReqInfo[(*numRequests)].pszGetUrl = pszURL; if (bPostRequest) { pasReqInfo[(*numRequests)].pszPostRequest = msBuildWFSLayerPostRequest(map, lp, &bbox, psParams); pasReqInfo[(*numRequests)].pszPostContentType = msStrdup("text/xml"); } /* We'll store the remote server's response to a tmp file. */ pasReqInfo[(*numRequests)].pszOutputFile = msTmpFile(map, map->mappath, NULL, "tmp.gml"); /* TODO: Implement Caching of GML responses. There was an older caching * method, but it suffered from a race condition. See #3137. */ pasReqInfo[(*numRequests)].pszHTTPCookieData = pszHTTPCookieData; pszHTTPCookieData = NULL; pasReqInfo[(*numRequests)].nStatus = 0; pasReqInfo[(*numRequests)].nTimeout = nTimeout; pasReqInfo[(*numRequests)].bbox = bbox; pasReqInfo[(*numRequests)].debug = lp->debug; if (msHTTPAuthProxySetup(&(map->web.metadata), &(lp->metadata), pasReqInfo, *numRequests, map, "FO") != MS_SUCCESS) { if (psParams) { msWFSFreeParamsObj(psParams); } return MS_FAILURE; } /* ------------------------------------------------------------------ * Pre-Open the layer now, (i.e. alloc and fill msWFSLayerInfo inside * layer obj). Layer will be ready for use when the main mapserver * code calls msLayerOpen(). * ------------------------------------------------------------------ */ if (lp->wfslayerinfo != NULL) { psInfo =(msWFSLayerInfo*)(lp->wfslayerinfo); } else { lp->wfslayerinfo = psInfo = msAllocWFSLayerInfo(); } if (psInfo->pszGMLFilename) free(psInfo->pszGMLFilename); psInfo->pszGMLFilename=msStrdup(pasReqInfo[(*numRequests)].pszOutputFile); psInfo->rect = pasReqInfo[(*numRequests)].bbox; if (psInfo->pszGetUrl) free(psInfo->pszGetUrl); psInfo->pszGetUrl = msStrdup(pasReqInfo[(*numRequests)].pszGetUrl); psInfo->nStatus = 0; (*numRequests)++; if (psParams) { msWFSFreeParamsObj(psParams); } return nStatus; #else /* ------------------------------------------------------------------ * WFS CONNECTION Support not included... * ------------------------------------------------------------------ */ msSetError(MS_WFSCONNERR, "WFS CLIENT CONNECTION support is not available.", "msPrepareWFSLayerRequest"); return(MS_FAILURE); #endif /* USE_WFS_LYR */ }
const char* KmlRenderer::lookupPlacemarkStyle() { char lineHexColor[32]; char polygonHexColor[32]; char labelHexColor[32]; char *styleName=NULL; styleName = msStringConcatenate(styleName, "style"); if (SymbologyFlag[Line]) { /* <LineStyle id="ID"> <!-- inherited from ColorStyle --> <color>ffffffff</color> <!-- kml:color --> <colorMode>normal</colorMode> <!-- colorModeEnum: normal or random --> <!-- specific to LineStyle --> <width>1</width> <!-- float --> </LineStyle> */ for (int i=0; i<numLineStyle; i++) { if (currentLayer && currentLayer->compositer && currentLayer->compositer->opacity > 0 && currentLayer->compositer->opacity < 100 && LineStyle[i].color->alpha == 255) LineStyle[i].color->alpha = MS_NINT(currentLayer->compositer->opacity*2.55); sprintf(lineHexColor,"%02x%02x%02x%02x", LineStyle[i].color->alpha, LineStyle[0].color->blue, LineStyle[i].color->green, LineStyle[i].color->red); char lineStyleName[32]; sprintf(lineStyleName, "_line_%s_w%.1f", lineHexColor, LineStyle[i].width); styleName = msStringConcatenate(styleName, lineStyleName); } } if (SymbologyFlag[Polygon]) { /* <PolyStyle id="ID"> <!-- inherited from ColorStyle --> <color>ffffffff</color> <!-- kml:color --> <colorMode>normal</colorMode> <!-- kml:colorModeEnum: normal or random --> <!-- specific to PolyStyle --> <fill>1</fill> <!-- boolean --> <outline>1</outline> <!-- boolean --> </PolyStyle> */ if (currentLayer && currentLayer->compositer && currentLayer->compositer->opacity > 0 && currentLayer->compositer->opacity < 100 && PolygonColor.alpha == 255) PolygonColor.alpha = MS_NINT(currentLayer->compositer->opacity*2.55); sprintf(polygonHexColor,"%02x%02x%02x%02x", PolygonColor.alpha, PolygonColor.blue, PolygonColor.green, PolygonColor.red); char polygonStyleName[64]; sprintf(polygonStyleName, "_polygon_%s", polygonHexColor); styleName = msStringConcatenate(styleName, polygonStyleName); } if (SymbologyFlag[Label]) { /* <LabelStyle id="ID"> <!-- inherited from ColorStyle --> <color>ffffffff</color> <!-- kml:color --> <colorMode>normal</colorMode> <!-- kml:colorModeEnum: normal or random --> <!-- specific to LabelStyle --> <scale>1</scale> <!-- float --> </LabelStyle> */ if (currentLayer && currentLayer->compositer && currentLayer->compositer->opacity > 0 && currentLayer->compositer->opacity < 100 && LabelColor.alpha == 255) LabelColor.alpha = MS_NINT(currentLayer->compositer->opacity*2.55); sprintf(labelHexColor,"%02x%02x%02x%02x", LabelColor.alpha, LabelColor.blue, LabelColor.green, LabelColor.red); // __TODO__ add label scale char labelStyleName[64]; sprintf(labelStyleName, "_label_%s", labelHexColor); styleName = msStringConcatenate(styleName, labelStyleName); } if (SymbologyFlag[Symbol]) { /* <Style id="randomColorIcon"> <IconStyle> <color>ff00ff00</color> <colorMode>random</colorMode> <scale>1.1</scale> <Icon> <href>http://maps.google.com/mapfiles/kml/pal3/icon21.png</href> </Icon> </IconStyle> </Style> */ /* __TODO__ add label scale */ styleName = msStringConcatenate(styleName, "_"); styleName = msStringConcatenate(styleName, SymbolName); } const char *styleUrl = msLookupHashTable(StyleHashTable, styleName); if (!styleUrl) { char *styleValue=NULL; styleValue = msStringConcatenate(styleValue, "#"); styleValue = msStringConcatenate(styleValue, styleName); hashObj *hash = msInsertHashTable(StyleHashTable, styleName, styleValue); styleUrl = hash->data; msFree(styleValue); /* Insert new Style node into Document node*/ xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL); xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName); if (SymbologyFlag[Polygon]) { xmlNodePtr polyStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "PolyStyle", NULL); xmlNewChild(polyStyleNode, NULL, BAD_CAST "color", BAD_CAST polygonHexColor); } if (SymbologyFlag[Line]) { for (int i=0; i<numLineStyle; i++) { xmlNodePtr lineStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "LineStyle", NULL); sprintf(lineHexColor,"%02x%02x%02x%02x", LineStyle[i].color->alpha, LineStyle[i].color->blue, LineStyle[i].color->green, LineStyle[i].color->red); xmlNewChild(lineStyleNode, NULL, BAD_CAST "color", BAD_CAST lineHexColor); char width[16]; sprintf(width, "%.1f", LineStyle[i].width); xmlNewChild(lineStyleNode, NULL, BAD_CAST "width", BAD_CAST width); } } if (SymbologyFlag[Symbol]) { xmlNodePtr iconStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "IconStyle", NULL); xmlNodePtr iconNode = xmlNewChild(iconStyleNode, NULL, BAD_CAST "Icon", NULL); xmlNewChild(iconNode, NULL, BAD_CAST "href", BAD_CAST SymbolUrl); /*char scale[16]; sprintf(scale, "%.1f", style->scale); xmlNewChild(iconStyleNode, NULL, BAD_CAST "scale", BAD_CAST scale);*/ } else { const char *value=msLookupHashTable(¤tLayer->metadata, "kml_default_symbol_href"); if (value && strlen(value) > 0) { xmlNodePtr iconStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "IconStyle", NULL); xmlNodePtr iconNode = xmlNewChild(iconStyleNode, NULL, BAD_CAST "Icon", NULL); xmlNewChild(iconNode, NULL, BAD_CAST "href", BAD_CAST value); } } if (SymbologyFlag[Label]) { xmlNodePtr labelStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "LabelStyle", NULL); xmlNewChild(labelStyleNode, NULL, BAD_CAST "color", BAD_CAST labelHexColor); /*char scale[16]; sprintf(scale, "%.1f", style->scale); xmlNewChild(iconStyleNode, NULL, BAD_CAST "scale", BAD_CAST scale);*/ } } if (styleName) msFree(styleName); return styleUrl; }
const char *msGetConfigOption( mapObj *map, const char *key) { return msLookupHashTable( &(map->configoptions), key ); }
/** * Is there any XMP metadata in the map file for us to worry about? */ int msXmpWrite( mapObj *map, const char *filename ) { #ifdef USE_EXEMPI /* Should hold our keys */ hashTableObj hash_metadata = map->web.metadata; /* Temporary place for custom name spaces */ hashTableObj hash_ns; /* We use regex to strip out the namespace and XMP key value from the metadata key */ regex_t xmp_regex; const char *xmp_ns_str = "^xmp_(.+)_namespace$"; const char *xmp_tag_str = "^xmp_(.+)_(.+)$"; const char *key = NULL; static int regflags = REG_ICASE | REG_EXTENDED; /* XMP object and file pointers */ XmpPtr xmp; XmpFilePtr f; /* Force the hash table to empty */ hash_ns.numitems = 0; /* Prepare XMP library */ xmp_init(); f = xmp_files_open_new(filename, XMP_OPEN_FORUPDATE); if ( ! f ) { msSetError( MS_MISCERR, "Unable to open temporary file '%s' to write XMP info", "msXmpWrite()", filename ); return MS_FAILURE; } /* Create a new XMP structure if the file doesn't already have one */ xmp = xmp_files_get_new_xmp(f); if ( xmp == NULL ) xmp = xmp_new_empty(); /* Check we can write to the file */ if ( ! xmp_files_can_put_xmp(f, xmp) ) { msSetError( MS_MISCERR, "Unable to write XMP information to '%s'", "msXmpWrite()", filename ); return MS_FAILURE; } /* Compile our "xmp_*_namespace" regex */ if ( regcomp(&xmp_regex, xmp_ns_str, regflags) ) { msSetError( MS_MISCERR, "Unable compile regex '%s'", "msXmpWrite()", xmp_ns_str ); return MS_FAILURE; } /* Check all the keys for "xmp_*_namespace" pattern */ initHashTable(&hash_ns); key = msFirstKeyFromHashTable(&hash_metadata); /* No first key? No license info. We shouldn't get here. */ if ( ! key ) return MS_SUCCESS; do { /* Our regex has one match slot */ regmatch_t matches[2]; /* Found a custom namespace entry! Store it for later. */ if ( 0 == regexec(&xmp_regex, key, 2, matches, 0) ) { size_t ns_size = 0; char *ns_name = NULL; const char *ns_uri; /* Copy in the namespace name */ ns_size = matches[1].rm_eo - matches[1].rm_so; ns_name = msSmallMalloc(ns_size + 1); memcpy(ns_name, key + matches[1].rm_so, ns_size); ns_name[ns_size] = 0; /* null terminate */ /* Copy in the namespace uri */ ns_uri = msLookupHashTable(&hash_metadata, key); msInsertHashTable(&hash_ns, ns_name, ns_uri); xmp_register_namespace(ns_uri, ns_name, NULL); msFree(ns_name); } } while( (key = msNextKeyFromHashTable(&hash_metadata, key)) ); /* Clean up regex */ regfree(&xmp_regex); /* Compile our "xmp_*_*" regex */ if ( regcomp(&xmp_regex, xmp_tag_str, regflags) ) { msFreeHashItems(&hash_ns); msSetError( MS_MISCERR, "Unable compile regex '%s'", "msXmpWrite()", xmp_tag_str ); return MS_FAILURE; } /* Check all the keys for "xmp_*_*" pattern */ key = msFirstKeyFromHashTable(&hash_metadata); do { /* Our regex has two match slots */ regmatch_t matches[3]; /* Found a namespace entry! Write it into XMP. */ if ( 0 == regexec(&xmp_regex, key, 3, matches, 0) ) { /* Get the namespace and tag name */ size_t ns_name_size = matches[1].rm_eo - matches[1].rm_so; size_t ns_tag_size = matches[2].rm_eo - matches[2].rm_so; char *ns_name = msSmallMalloc(ns_name_size + 1); char *ns_tag = msSmallMalloc(ns_tag_size + 1); const char *ns_uri = NULL; memcpy(ns_name, key + matches[1].rm_so, ns_name_size); memcpy(ns_tag, key + matches[2].rm_so, ns_tag_size); ns_name[ns_name_size] = 0; /* null terminate */ ns_tag[ns_tag_size] = 0; /* null terminate */ if ( strcmp(ns_tag,"namespace") == 0 ) { msFree(ns_name); msFree(ns_tag); continue; } /* If this is a default name space?... */ if ( (ns_uri = msXmpUri(ns_name)) ) { xmp_register_namespace(ns_uri, ns_name, NULL); xmp_set_property(xmp, ns_uri, ns_tag, msLookupHashTable(&hash_metadata, key), 0); } /* Or maybe it's a custom one?... */ else if ( (ns_uri = msLookupHashTable(&hash_ns, ns_name)) ) { xmp_set_property(xmp, ns_uri, ns_tag, msLookupHashTable(&hash_metadata, key), 0); } /* Or perhaps we're screwed. */ else { msSetError( MS_MISCERR, "Unable to identify XMP namespace '%s' in metadata key '%s'", "msXmpWrite()", ns_name, key ); msFreeHashItems(&hash_ns); msFree(ns_name); msFree(ns_tag); return MS_FAILURE; } msFree(ns_name); msFree(ns_tag); } } while( (key = msNextKeyFromHashTable(&hash_metadata, key)) ); /* Clean up regex */ regfree(&xmp_regex); /* Write out the XMP */ if ( !xmp_files_put_xmp(f, xmp) ) { msFreeHashItems(&hash_ns); msSetError( MS_MISCERR, "Unable to execute '%s' on pointer %p", "msXmpWrite()", "xmp_files_put_xmp", f ); return MS_FAILURE; } /* Write out the file and flush */ if ( !xmp_files_close(f, XMP_CLOSE_SAFEUPDATE) ) { msFreeHashItems(&hash_ns); msSetError( MS_MISCERR, "Unable to execute '%s' on pointer %p", "msXmpWrite()", "xmp_files_close", f ); return MS_FAILURE; } msFreeHashItems(&hash_ns); xmp_free(xmp); xmp_terminate(); return MS_SUCCESS; #else return MS_FAILURE; #endif }
int KmlRenderer::startNewLayer(imageObj *img, layerObj *layer) { char *layerName=NULL; const char *value=NULL; LayerNode = xmlNewNode(NULL, BAD_CAST "Folder"); layerName = getLayerName(layer); xmlNewChild(LayerNode, NULL, BAD_CAST "name", BAD_CAST layerName); msFree(layerName); const char *layerVisibility = layer->status != MS_OFF ? "1" : "0"; xmlNewChild(LayerNode, NULL, BAD_CAST "visibility", BAD_CAST layerVisibility); const char *layerDsiplayFolder = msLookupHashTable(&(layer->metadata), "kml_folder_display"); if (layerDsiplayFolder == NULL) layerDsiplayFolder = msLookupHashTable(&(layer->map->web.metadata), "kml_folder_display"); if (!layerDsiplayFolder || strlen(layerDsiplayFolder)<=0) { xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_check"); } else { if (strcasecmp(layerDsiplayFolder, "checkHideChildren") == 0) xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_checkHideChildren"); else if (strcasecmp(layerDsiplayFolder, "checkOffOnly") == 0) xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_checkOffOnly"); else if (strcasecmp(layerDsiplayFolder, "radioFolder") == 0) xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_radioFolder"); else xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_check"); } /*Init few things on the first layer*/ if (FirstLayer) { FirstLayer = MS_FALSE; map = layer->map; if (layer->map->mappath) snprintf(MapPath, sizeof(MapPath), "%s", layer->map->mappath); /*First rendered layer - check mapfile projection*/ checkProjection(layer->map); /*check for image path and image url*/ if (layer->map->debug && (layer->map->web.imageurl == NULL || layer->map->web.imagepath == NULL)) msDebug("KmlRenderer::startNewLayer: imagepath and imageurl should be set in the web object\n"); /*map rect for ground overlay*/ MapExtent = layer->map->extent; MapCellsize = layer->map->cellsize; BgColor = layer->map->imagecolor; xmlNewChild(DocNode, NULL, BAD_CAST "name", BAD_CAST layer->map->name); aggFormat = msSelectOutputFormat( layer->map, "png24"); aggFormat->transparent = MS_TRUE; } currentLayer = layer; if (!msLayerIsOpen(layer)) { if (msLayerOpen(layer) != MS_SUCCESS) { msSetError(MS_MISCERR, "msLayerOpen failed", "KmlRenderer::startNewLayer" ); return MS_FAILURE; } } /*pre process the layer to set things that make sense for kml output*/ if (img) processLayer(layer, img->format); else processLayer(layer, NULL); if (msLookupHashTable(&layer->metadata, "kml_description")) pszLayerDescMetadata = msLookupHashTable(&layer->metadata, "kml_description"); else if (msLookupHashTable(&layer->metadata, "ows_description")) pszLayerDescMetadata = msLookupHashTable(&layer->metadata, "ows_description"); value=msLookupHashTable(&layer->metadata, "kml_include_items"); if (!value) value=msLookupHashTable(&layer->metadata, "ows_include_items"); if (value) papszLayerIncludeItems = msStringSplit(value, ',', &nIncludeItems); value=msLookupHashTable(&layer->metadata, "kml_exclude_items"); if (!value) value=msLookupHashTable(&layer->metadata, "ows_exclude_items"); if (value) papszLayerExcludeItems = msStringSplit(value, ',', &nExcludeItems); if (msLookupHashTable(&layer->metadata, "kml_name_item")) pszLayerNameAttributeMetadata = msLookupHashTable(&layer->metadata, "kml_name_item"); /*get all attributes*/ if(msLayerWhichItems(layer, MS_TRUE, NULL) != MS_SUCCESS) { return MS_FAILURE; } NumItems = layer->numitems; if (NumItems) { Items = (char **)msSmallCalloc(NumItems, sizeof(char *)); for (int i=0; i<NumItems; i++) Items[i] = msStrdup(layer->items[i]); } const char* elevationAttribute = msLookupHashTable(&layer->metadata, "kml_elevation_attribute"); if( elevationAttribute ) { mElevationFromAttribute = true; for( int i = 0; i < layer->numitems; ++i ) { if( strcasecmp( layer->items[i], elevationAttribute ) == 0 ) { mElevationAttributeIndex = i; } } } setupRenderingParams(&layer->metadata); return MS_SUCCESS; }