MCPcopy Index your code
hub / github.com/MapServer/MapServer / msAddImageSymbol

Function msAddImageSymbol

mapsymbol.c:326–385  ·  view source on GitHub ↗

** Little helper function to allow us to build symbol files on-the-fly ** from just a file name. ** ** Returns the symbol index or -1 if it could not be added. */

Source from the content-addressed store, hash-verified

324** Returns the symbol index or -1 if it could not be added.
325*/
326int msAddImageSymbol(symbolSetObj *symbolset, char *filename)
327{
328 char szPath[MS_MAXPATHLEN];
329 symbolObj *symbol=NULL;
330
331 if(!symbolset) {
332 msSetError(MS_SYMERR, "Symbol structure unallocated.", "msAddImageSymbol()");
333 return(-1);
334 }
335
336 if(!filename || strlen(filename) == 0) return(-1);
337
338 /* Allocate/init memory for new symbol if needed */
339 if (msGrowSymbolSet(symbolset) == NULL)
340 return -1;
341 symbol = symbolset->symbol[symbolset->numsymbols];
342
343#ifdef USE_CURL
344 if (strncasecmp(filename, "http", 4) == 0)
345 {
346 char *tmpfullfilename = NULL;
347 char *tmpfilename = NULL;
348 char *tmppath = NULL;
349 int status = 0;
350 char szPath[MS_MAXPATHLEN];
351 int bCheckLocalCache = MS_TRUE;
352
353 tmppath = msTmpPath(NULL, NULL, NULL);
354 if (tmppath)
355 {
356 tmpfilename = msEncodeUrl(filename);
357 tmpfullfilename = msBuildPath(szPath, tmppath, tmpfilename);
358 if (tmpfullfilename)
359 {
360 /*use the url for now as a caching mechanism*/
361 if (msHTTPGetFile(filename, tmpfullfilename, &status, -1, bCheckLocalCache, 0) == MS_SUCCESS)
362 {
363 symbol->imagepath = msStrdup(tmpfullfilename);
364 symbol->full_pixmap_path = msStrdup(tmpfullfilename);
365 }
366 }
367 msFree(tmpfilename);
368 msFree(tmppath);
369 }
370 }
371#endif
372 /*if the http did not work, allow it to be treated as a file*/
373 if (!symbol->full_pixmap_path)
374 {
375 if(symbolset->map) {
376 symbol->full_pixmap_path = msStrdup(msBuildPath(szPath, symbolset->map->mappath, filename));
377 } else {
378 symbol->full_pixmap_path = msStrdup(msBuildPath(szPath, NULL, filename));
379 }
380 symbol->imagepath = msStrdup(filename);
381 }
382 symbol->name = msStrdup(filename);
383 symbol->type = MS_SYMBOL_PIXMAP;

Callers 2

msDrawLegendIconFunction · 0.85
msGetSymbolIndexFunction · 0.85

Calls 9

msSetErrorFunction · 0.85
msGrowSymbolSetFunction · 0.85
strncasecmpFunction · 0.85
msTmpPathFunction · 0.85
msEncodeUrlFunction · 0.85
msBuildPathFunction · 0.85
msHTTPGetFileFunction · 0.85
msStrdupFunction · 0.85
msFreeFunction · 0.85

Tested by

no test coverage detected