Ticket #2032: rfc24-mapandlayers-demo.patch
| File rfc24-mapandlayers-demo.patch, 152.9 kB (added by unicoletti, 2 years ago) |
|---|
-
mapcontext.c
old new 1145 1145 layerObj *layer; 1146 1146 1147 1147 /* Init new layer */ 1148 layer = &( map->layers[map->numlayers]);1148 layer = &(GET_LAYER(map, map->numlayers)); 1149 1149 initLayer(layer, map); 1150 1150 layer->map = (mapObj *)map; 1151 1151 layer->type = MS_LAYER_RASTER; 1152 1152 /* save the index */ 1153 map->layers[map->numlayers].index = map->numlayers;1153 GET_LAYER(map, map->numlayers)->index = map->numlayers; 1154 1154 map->layerorder[map->numlayers] = map->numlayers; 1155 1155 map->numlayers++; 1156 1156 … … 1919 1919 /* Loop on all layer */ 1920 1920 for(i=0; i<map->numlayers; i++) 1921 1921 { 1922 if( map->layers[i].status != MS_DELETE && map->layers[i].connectiontype == MS_WMS)1922 if(GET_LAYER(map, i)->status != MS_DELETE && GET_LAYER(map, i)->connectiontype == MS_WMS) 1923 1923 { 1924 if( map->layers[i].status == MS_OFF)1924 if(GET_LAYER(map, i)->status == MS_OFF) 1925 1925 nValue = 1; 1926 1926 else 1927 1927 nValue = 0; 1928 1928 msIO_fprintf(stream, " <Layer queryable=\"%d\" hidden=\"%d\">\n", 1929 msIsLayerQueryable(&( map->layers[i])), nValue);1929 msIsLayerQueryable(&(GET_LAYER(map, i))), nValue); 1930 1930 1931 1931 /* */ 1932 1932 /* Server definition */ 1933 1933 /* */ 1934 1934 if(nVersion <= OWS_1_0_0 ) 1935 msOWSPrintEncodeMetadata(stream, &( map->layers[i].metadata),1935 msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), 1936 1936 NULL, "wms_server_version", OWS_WARN, 1937 1937 " <Server service=\"WMS\" version=\"%s\" ", 1938 1938 "1.0.0"); 1939 1939 else 1940 msOWSPrintEncodeMetadata(stream, &( map->layers[i].metadata),1940 msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), 1941 1941 NULL, "wms_server_version", OWS_WARN, 1942 1942 " <Server service=\"OGC:WMS\" version=\"%s\" ", 1943 1943 "1.0.0"); 1944 if( map->layers[i].name)1945 msOWSPrintEncodeMetadata(stream, &( map->layers[i].metadata),1944 if(GET_LAYER(map, i)->name) 1945 msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), 1946 1946 NULL, "wms_title", OWS_NOERR, 1947 "title=\"%s\">\n", map->layers[i].name);1947 "title=\"%s\">\n", GET_LAYER(map, i)->name); 1948 1948 else 1949 1949 { 1950 msOWSPrintEncodeMetadata(stream, &( map->layers[i].metadata),1950 msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), 1951 1951 NULL, "wms_title", OWS_NOERR, 1952 1952 "title=\"%s\">\n", ""); 1953 1953 } 1954 1954 1955 1955 /* Get base url of the online resource to be the default value */ 1956 if( map->layers[i].connection)1957 pszValue = strdup( map->layers[i].connection );1956 if(GET_LAYER(map, i)->connection) 1957 pszValue = strdup( GET_LAYER(map, i)->connection ); 1958 1958 else 1959 1959 pszValue = strdup( "" ); 1960 1960 pszChar = strchr(pszValue, '?'); 1961 1961 if( pszChar ) 1962 1962 pszValue[pszChar - pszValue] = '\0'; 1963 if(msOWSPrintEncodeMetadata(stream, &( map->layers[i].metadata),1963 if(msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), 1964 1964 NULL, "wms_onlineresource", OWS_WARN, 1965 1965 " <OnlineResource xlink:type=\"simple\" xlink:href=\"%s\"/>\n", 1966 1966 pszValue) == OWS_WARN) … … 1973 1973 /* */ 1974 1974 /* Layer information */ 1975 1975 /* */ 1976 msOWSPrintEncodeMetadata(stream, &( map->layers[i].metadata),1976 msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), 1977 1977 NULL, "wms_name", OWS_WARN, 1978 1978 " <Name>%s</Name>\n", 1979 map->layers[i].name);1980 msOWSPrintEncodeMetadata(stream, &( map->layers[i].metadata),1979 GET_LAYER(map, i)->name); 1980 msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), 1981 1981 NULL, "wms_title", OWS_WARN, 1982 1982 " <Title>%s</Title>\n", 1983 map->layers[i].name);1984 msOWSPrintEncodeMetadata(stream, &( map->layers[i].metadata),1983 GET_LAYER(map, i)->name); 1984 msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), 1985 1985 NULL, "wms_abstract", OWS_NOERR, 1986 1986 " <Abstract>%s</Abstract>\n", 1987 1987 NULL); … … 1989 1989 /* DataURL */ 1990 1990 if(nVersion <= OWS_0_1_4) 1991 1991 { 1992 msOWSPrintEncodeMetadata(stream, &( map->layers[i].metadata),1992 msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), 1993 1993 NULL, "wms_dataurl", OWS_NOERR, 1994 1994 " <DataURL>%s</DataURL>\n", 1995 1995 NULL); … … 2002 2002 /* Note: in version 0.1.7 the width and height are not included */ 2003 2003 /* in the Context file, but they are included in the metadata for */ 2004 2004 /* for consistency with the URLType. */ 2005 msOWSPrintURLType(stream, &( map->layers[i].metadata), "MO",2005 msOWSPrintURLType(stream, &(GET_LAYER(map, i)->metadata), "MO", 2006 2006 "dataurl", OWS_NOERR, NULL, "DataURL", NULL, 2007 2007 " width=\"%s\"", " height=\"%s\"", 2008 2008 " format=\"%s\"", … … 2016 2016 /* The MetadataURL have a width, height, format and an URL */ 2017 2017 /* The metadata will be structured like this: */ 2018 2018 /* "width height format url" */ 2019 msOWSPrintURLType(stream, &( map->layers[i].metadata), "MO",2019 msOWSPrintURLType(stream, &(GET_LAYER(map, i)->metadata), "MO", 2020 2020 "metadataurl", OWS_NOERR, NULL, "MetadataURL",NULL, 2021 2021 " width=\"%s\"", " height=\"%s\""," format=\"%s\"", 2022 2022 " <OnlineResource xlink:type=\"simple\"" … … 2025 2025 MS_TRUE, NULL, NULL, NULL, NULL, NULL, " "); 2026 2026 2027 2027 /* MinScale && MaxScale */ 2028 if(nVersion >= OWS_1_1_0 && map->layers[i].minscale > 0)2028 if(nVersion >= OWS_1_1_0 && GET_LAYER(map, i)->minscale > 0) 2029 2029 msIO_fprintf(stream, 2030 2030 " <sld:MinScaleDenominator>%g</sld:MinScaleDenominator>\n", 2031 map->layers[i].minscale);2032 if(nVersion >= OWS_1_1_0 && map->layers[i].maxscale > 0)2031 GET_LAYER(map, i)->minscale); 2032 if(nVersion >= OWS_1_1_0 && GET_LAYER(map, i)->maxscale > 0) 2033 2033 msIO_fprintf(stream, 2034 2034 " <sld:MaxScaleDenominator>%g</sld:MaxScaleDenominator>\n", 2035 map->layers[i].maxscale);2035 GET_LAYER(map, i)->maxscale); 2036 2036 2037 2037 /* Layer SRS */ 2038 pszValue = (char*)msOWSGetEPSGProj(&( map->layers[i].projection),2039 &( map->layers[i].metadata),2038 pszValue = (char*)msOWSGetEPSGProj(&(GET_LAYER(map, i)->projection), 2039 &(GET_LAYER(map, i)->metadata), 2040 2040 "MO", MS_FALSE); 2041 2041 if(pszValue && (strcasecmp(pszValue, "(null)") != 0)) 2042 2042 { … … 2046 2046 } 2047 2047 2048 2048 /* Format */ 2049 if(msLookupHashTable(&( map->layers[i].metadata),"wms_formatlist")==NULL &&2050 msLookupHashTable(&( map->layers[i].metadata),"wms_format")==NULL)2049 if(msLookupHashTable(&(GET_LAYER(map, i)->metadata),"wms_formatlist")==NULL && 2050 msLookupHashTable(&(GET_LAYER(map, i)->metadata),"wms_format")==NULL) 2051 2051 { 2052 2052 pszURL = NULL; 2053 if( map->layers[i].connection)2054 pszURL = strdup( map->layers[i].connection );2053 if(GET_LAYER(map, i)->connection) 2054 pszURL = strdup( GET_LAYER(map, i)->connection ); 2055 2055 else 2056 2056 pszURL = strdup( "" ); 2057 2057 pszValue = pszURL; … … 2079 2079 char **papszFormats; 2080 2080 int numFormats, nForm; 2081 2081 2082 pszValue = msLookupHashTable(&( map->layers[i].metadata),2082 pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2083 2083 "wms_formatlist"); 2084 2084 if(!pszValue) 2085 pszValue = msLookupHashTable(&( map->layers[i].metadata),2085 pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2086 2086 "wms_format"); 2087 pszCurrent = msLookupHashTable(&( map->layers[i].metadata),2087 pszCurrent = msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2088 2088 "wms_format"); 2089 2089 2090 2090 papszFormats = split(pszValue, ',', &numFormats); … … 2111 2111 } 2112 2112 /* Style */ 2113 2113 /* First check the stylelist */ 2114 pszValue = msLookupHashTable(&( map->layers[i].metadata),2114 pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2115 2115 "wms_stylelist"); 2116 2116 if(pszValue == NULL || strlen(trimLeft(pszValue)) < 1) 2117 2117 { 2118 2118 /* Check if the style is in the connection URL */ 2119 2119 pszURL = ""; 2120 if( map->layers[i].connection)2121 pszURL = strdup( map->layers[i].connection );2120 if(GET_LAYER(map, i)->connection) 2121 pszURL = strdup( GET_LAYER(map, i)->connection ); 2122 2122 else 2123 2123 pszURL = strdup( "" ); 2124 2124 pszValue = pszURL; … … 2132 2132 pszValue[pszChar - pszValue] = '\0'; 2133 2133 2134 2134 /* Check the SLD string from the URL */ 2135 if( map->layers[i].connection)2136 pszSLD2 = strdup( map->layers[i].connection);2135 if(GET_LAYER(map, i)->connection) 2136 pszSLD2 = strdup(GET_LAYER(map, i)->connection); 2137 2137 else 2138 2138 pszSLD2 = strdup( "" ); 2139 2139 if(pszSLD2) … … 2215 2215 { 2216 2216 /* If the style information is not in the connection URL, */ 2217 2217 /* read the metadata. */ 2218 pszValue = msLookupHashTable(&( map->layers[i].metadata),2218 pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2219 2219 "wms_stylelist"); 2220 pszCurrent = msLookupHashTable(&( map->layers[i].metadata),2220 pszCurrent = msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2221 2221 "wms_style"); 2222 2222 msIO_fprintf( stream, " <StyleList>\n"); 2223 2223 /* Loop in each style in the style list */ … … 2238 2238 /* Write SLDURL if it is in the metadata */ 2239 2239 pszStyleItem = (char*)malloc(strlen(pszStyle)+10+10); 2240 2240 sprintf(pszStyleItem, "wms_style_%s_sld", pszStyle); 2241 if(msLookupHashTable(&( map->layers[i].metadata),2241 if(msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2242 2242 pszStyleItem) != NULL) 2243 2243 { 2244 2244 msIO_fprintf(stream, " <SLD>\n"); 2245 2245 msOWSPrintEncodeMetadata(stream, 2246 &( map->layers[i].metadata),2246 &(GET_LAYER(map, i)->metadata), 2247 2247 NULL, pszStyleItem, 2248 2248 OWS_NOERR, 2249 2249 " <OnlineResource xlink:type=\"simple\" xlink:href=\"%s\"/>\n", … … 2255 2255 { 2256 2256 /* If the URL is not there, check for SLDBody */ 2257 2257 sprintf(pszStyleItem, "wms_style_%s_sld_body", pszStyle); 2258 if(msLookupHashTable(&( map->layers[i].metadata),2258 if(msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2259 2259 pszStyleItem) != NULL) 2260 2260 { 2261 2261 msIO_fprintf(stream, " <SLD>\n"); 2262 msOWSPrintMetadata(stream,&( map->layers[i].metadata),2262 msOWSPrintMetadata(stream,&(GET_LAYER(map, i)->metadata), 2263 2263 NULL, pszStyleItem, OWS_NOERR, 2264 2264 " %s\n", NULL); 2265 2265 msIO_fprintf(stream, " </SLD>\n"); … … 2279 2279 sprintf(pszStyleItem, "wms_style_%s_title",pszStyle); 2280 2280 /* Title */ 2281 2281 msOWSPrintEncodeMetadata(stream, 2282 &( map->layers[i].metadata),2282 &(GET_LAYER(map, i)->metadata), 2283 2283 NULL, pszStyleItem, 2284 2284 OWS_NOERR, 2285 2285 " <Title>%s</Title>\n", … … 2290 2290 pszStyleItem = (char*)malloc(strlen(pszStyle)+10+20); 2291 2291 sprintf(pszStyleItem, "style_%s_legendurl", 2292 2292 pszStyle); 2293 msOWSPrintURLType(stream, &( map->layers[i].metadata),2293 msOWSPrintURLType(stream, &(GET_LAYER(map, i)->metadata), 2294 2294 "M", pszStyleItem, OWS_NOERR, NULL, 2295 2295 "LegendURL", NULL, " width=\"%s\"", 2296 2296 " height=\"%s\""," format=\"%s\"", … … 2317 2317 /* Dimension element */; 2318 2318 pszCurrent = NULL; 2319 2319 2320 pszValue = msLookupHashTable(&( map->layers[i].metadata),2320 pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2321 2321 "wms_dimensionlist"); 2322 pszCurrent = msLookupHashTable(&( map->layers[i].metadata),2322 pszCurrent = msLookupHashTable(&(GET_LAYER(map, i)->metadata), 2323 2323 "wms_dimension"); 2324 2324 while(pszValue != NULL) 2325 2325 { … … 2338 2338 } 2339 2339 2340 2340 /* From the dimension list, extract the required dimension */ 2341 msOWSGetDimensionInfo(&( map->layers[i]), pszDimension,2341 msOWSGetDimensionInfo(&(GET_LAYER(map, i)), pszDimension, 2342 2342 &pszDimUserValue, &pszDimUnits, 2343 2343 &pszDimDefault, &pszDimNearValue, 2344 2344 &pszDimUnitSymbol, &pszDimMultiValue); -
mapcopy.c
old new 878 878 MS_COPYSTELEM(numlayers); 879 879 880 880 for (i = 0; i < dst->numlayers; i++) { 881 initLayer( &(dst->layers[i]), dst);881 initLayer((GET_LAYER(dst, i)), dst); 882 882 883 return_value = msCopyLayer( &(dst->layers[i]), &(src->layers[i]));883 return_value = msCopyLayer((GET_LAYER(dst, i)), (GET_LAYER(src, i))); 884 884 if (return_value != MS_SUCCESS) { 885 885 msSetError(MS_MEMERR, "Failed to copy layer.", "msCopyMap()"); 886 886 return MS_FAILURE; -
mapdraw.c
old new 217 217 int i; 218 218 219 219 for(i=0; i<map->numlayers; i++) 220 msClearLayerPenValues( &(map->layers[i]));220 msClearLayerPenValues((GET_LAYER(map, i))); 221 221 222 222 msClearLegendPenValues(&(map->legend)); 223 223 msClearScalebarPenValues(&(map->scalebar)); … … 360 360 361 361 /* compute layer scale factors now */ 362 362 for(i=0;i<map->numlayers; i++) { 363 if( map->layers[i].sizeunits != MS_PIXELS)364 map->layers[i].scalefactor = (msInchesPerUnit(map->layers[i].sizeunits,0)/msInchesPerUnit(map->units,0)) / geo_cellsize;365 else if( map->layers[i].symbolscale > 0 && map->scale > 0)366 map->layers[i].scalefactor = map->layers[i].symbolscale/map->scale;363 if(GET_LAYER(map, i)->sizeunits != MS_PIXELS) 364 GET_LAYER(map, i)->scalefactor = (msInchesPerUnit(GET_LAYER(map, i)->sizeunits,0)/msInchesPerUnit(map->units,0)) / geo_cellsize; 365 else if(GET_LAYER(map, i)->symbolscale > 0 && map->scale > 0) 366 GET_LAYER(map, i)->scalefactor = GET_LAYER(map, i)->symbolscale/map->scale; 367 367 else 368 map->layers[i].scalefactor = 1;368 GET_LAYER(map, i)->scalefactor = 1; 369 369 } 370 370 371 371 return image; … … 421 421 for(i=0; i<map->numlayers; i++) 422 422 { 423 423 if (map->layerorder[i] == -1 || 424 !msLayerIsVisible(map, &( map->layers[map->layerorder[i]])))424 !msLayerIsVisible(map, &(GET_LAYER(map, map->layerorder[i])))) 425 425 continue; 426 426 427 lp = &( map->layers[ map->layerorder[i]]);427 lp = &(GET_LAYER(map, map->layerorder[i])); 428 428 429 429 #ifdef USE_WMS_LYR 430 430 if (lp->connectiontype == MS_WMS) … … 473 473 for(i=0; i<map->numlayers; i++) { 474 474 475 475 if (map->layerorder[i] != -1) { 476 lp = &(map->layers[ map->layerorder[i]]);476 lp = (GET_LAYER(map, map->layerorder[i])); 477 477 478 478 if(lp->postlabelcache) /* wait to draw */ 479 479 continue; … … 602 602 603 603 for(i=0; i<map->numlayers; i++) { /* for each layer, check for postlabelcache layers */ 604 604 605 lp = &(map->layers[map->layerorder[i]]);605 lp = (GET_LAYER(map, map->layerorder[i])); 606 606 607 607 if(!lp->postlabelcache) 608 608 continue; … … 734 734 735 735 /* compute layer scale factors now */ 736 736 for(i=0;i<map->numlayers; i++) { 737 if( map->layers[i].sizeunits != MS_PIXELS)738 map->layers[i].scalefactor = (msInchesPerUnit(map->layers[i].sizeunits,0)/msInchesPerUnit(map->units,0)) / map->cellsize;739 else if( map->layers[i].symbolscale > 0 && map->scale > 0)740 map->layers[i].scalefactor = map->layers[i].symbolscale/map->scale;737 if(GET_LAYER(map, i)->sizeunits != MS_PIXELS) 738 GET_LAYER(map, i)->scalefactor = (msInchesPerUnit(GET_LAYER(map, i)->sizeunits,0)/msInchesPerUnit(map->units,0)) / map->cellsize; 739 else if(GET_LAYER(map, i)->symbolscale > 0 && map->scale > 0) 740 GET_LAYER(map, i)->scalefactor = GET_LAYER(map, i)->symbolscale/map->scale; 741 741 else 742 map->layers[i].scalefactor = 1;742 GET_LAYER(map, i)->scalefactor = 1; 743 743 } 744 744 745 745 for(i=0; i<map->numlayers; i++) { 746 lp = &(map->layers[ map->layerorder[i]]);746 lp = (GET_LAYER(map, map->layerorder[i])); 747 747 748 748 if(lp->postlabelcache) /* wait to draw */ 749 749 continue; … … 762 762 return(NULL); 763 763 764 764 for(i=0; i<map->numlayers; i++) { /* for each layer, check for postlabelcache layers */ 765 lp = &(map->layers[ map->layerorder[i]]);765 lp = (GET_LAYER(map, map->layerorder[i])); 766 766 767 767 if(!lp->postlabelcache) 768 768 continue; -
maperror.h
old new 96 96 #define MS_TIMEERR 35 97 97 #define MS_GMLERR 36 98 98 #define MS_SOSERR 37 99 #define MS_NUMERRORCODES 38 99 #define MS_NULLPARENTERR 38 100 #define MS_NUMERRORCODES 39 100 101 101 102 #define MESSAGELENGTH 2048 102 103 #define ROUTINELENGTH 64 -
mapfile.c
old new 471 471 if(!name) return(-1); 472 472 473 473 for(i=0;i<map->numlayers; i++) { 474 if(! map->layers[i].name) /* skip it */474 if(!GET_LAYER(map, i)->name) /* skip it */ 475 475 continue; 476 if(strcmp(name, map->layers[i].name) == 0)476 if(strcmp(name, GET_LAYER(map, i)->name) == 0) 477 477 return(i); 478 478 } 479 479 return(-1); … … 2440 2440 */ 2441 2441 int initLayer(layerObj *layer, mapObj *map) 2442 2442 { 2443 if (layer==NULL) { 2444 msSetError(MS_MEMERR, "Layer is null", "initLayer()"); 2445 return(-1); 2446 } 2443 2447 layer->debug = MS_OFF; 2448 MS_REFCNT_INIT(layer); 2444 2449 2445 2450 layer->numclasses = 0; 2446 2451 if((layer->class = (classObj *)malloc(sizeof(classObj)*MS_MAXCLASSES)) == NULL) { … … 2550 2555 return(0); 2551 2556 } 2552 2557 2553 voidfreeLayer(layerObj *layer) {2558 int freeLayer(layerObj *layer) { 2554 2559 int i; 2560 if (!layer) return MS_FAILURE; 2561 if( MS_REFCNT_IS_NOT_ZERO(layer) ) { return MS_FAILURE; } 2562 if (layer->debug) 2563 msDebug("freeLayer(): freeing layer at %p.",layer); 2555 2564 2556 2565 msFree(layer->name); 2557 2566 msFree(layer->group); … … 2571 2580 msFree(layer->connection); 2572 2581 msFree(layer->vtable); 2573 2582 2574 2575 2583 msFreeProjection(&(layer->projection)); 2576 2584 2577 2585 for(i=0;i<layer->numclasses;i++) … … 2601 2609 freeJoin(&(layer->joins[i])); 2602 2610 msFree(layer->joins); 2603 2611 layer->numjoins = 0; 2612 2613 return MS_SUCCESS; 2604 2614 } 2605 2615 2606 2616 int loadLayer(layerObj *layer, mapObj *map) … … 4336 4346 */ 4337 4347 int initMap(mapObj *map) 4338 4348 { 4349 int i=0; 4350 MS_REFCNT_INIT(map); 4339 4351 map->numlayers = 0; 4340 if((map->layers = (layerObj * )malloc(sizeof(layerObj)*MS_MAXLAYERS)) == NULL) {4352 if((map->layers = (layerObj **)malloc(sizeof(layerObj*)*MS_MAXLAYERS)) == NULL) { 4341 4353 msSetError(MS_MEMERR, NULL, "initMap()"); 4342 4354 return(-1); 4343 4355 } 4356 for (i=0;i<MS_MAXLAYERS;i++) { 4357 map->layers[i]=NULL; 4358 } 4344 4359 4345 4360 map->debug = MS_OFF; 4346 4361 map->status = MS_ON; … … 4553 4568 4554 4569 for(i=0; i<map->numlayers; i++) 4555 4570 { 4556 writeLayer( &(map->layers[map->layerorder[i]]), stream);4557 /* writeLayer(&( map->layers[i]), stream); */4571 writeLayer((GET_LAYER(map, map->layerorder[i])), stream); 4572 /* writeLayer(&(GET_LAYER(map, i)), stream); */ 4558 4573 } 4559 4574 4560 4575 fprintf(stream, "END\n"); … … 4660 4675 4661 4676 /* step through layers and classes to resolve symbol names */ 4662 4677 for(i=0; i<map->numlayers; i++) { 4663 for(j=0; j< map->layers[i].numclasses; j++){4664 for(k=0; k< map->layers[i].class[j].numstyles; k++) {4665 if( map->layers[i].class[j].styles[k].symbolname) {4666 if(( map->layers[i].class[j].styles[k].symbol = msGetSymbolIndex(&(map->symbolset), map->layers[i].class[j].styles[k].symbolname, MS_TRUE)) == -1) {4667 msSetError(MS_MISCERR, "Undefined overlay symbol \"%s\" in class %d, style %d of layer %s.", "msLoadMap()", map->layers[i].class[j].styles[k].symbolname, j, k, map->layers[i].name);4678 for(j=0; j<GET_LAYER(map, i)->numclasses; j++){ 4679 for(k=0; k<GET_LAYER(map, i)->class[j].numstyles; k++) { 4680 if(GET_LAYER(map, i)->class[j].styles[k].symbolname) { 4681 if((GET_LAYER(map, i)->class[j].styles[k].symbol = msGetSymbolIndex(&(map->symbolset), GET_LAYER(map, i)->class[j].styles[k].symbolname, MS_TRUE)) == -1) { 4682 msSetError(MS_MISCERR, "Undefined overlay symbol \"%s\" in class %d, style %d of layer %s.", "msLoadMap()", GET_LAYER(map, i)->class[j].styles[k].symbolname, j, k, GET_LAYER(map, i)->name); 4668 4683 return(NULL); 4669 4684 } 4670 4685 } … … 4730 4745 msSetError(MS_IDENTERR, "Maximum number of layers reached.", "msLoadMap()"); 4731 4746 return(NULL); 4732 4747 } 4733 if(loadLayer(&(map->layers[map->numlayers]), map) == -1) return(NULL); 4734 map->layers[map->numlayers].index = map->numlayers; /* save the index */ 4748 //printf("New layer=%d %p\n",map->numlayers,map->layers[map->numlayers]); 4749 map->layers[map->numlayers]=(layerObj*)malloc(sizeof(layerObj)); 4750 //printf("After new layer=%d %p\n",map->numlayers,map->layers[map->numlayers]); 4751 if (GET_LAYER(map, map->numlayers) == NULL) { 4752 msSetError(MS_MEMERR, "Malloc of a new layer failed.", "msLoadMap()"); 4753 return(NULL); 4754 } 4755 if(loadLayer((GET_LAYER(map, map->numlayers)), map) == -1) return(NULL); 4756 GET_LAYER(map, map->numlayers)->index = map->numlayers; /* save the index */ 4735 4757 /* Update the layer order list with the layer's index. */ 4736 4758 map->layerorder[map->numlayers] = map->numlayers; 4737 4759 map->numlayers++; … … 4917 4939 case(LAYER): 4918 4940 if(getInteger(&i) == -1) break; 4919 4941 if(i>=map->numlayers || i<0) break; 4920 loadLayerString(map, &(map->layers[i]), value);4942 loadLayerString(map, (GET_LAYER(map, i)), value); 4921 4943 break; 4922 4944 case(LEGEND): 4923 4945 loadLegendString(map, &(map->legend), value); … … 4962 4984 case(MS_STRING): 4963 4985 i = msGetLayerIndex(map, msyytext); 4964 4986 if(i>=map->numlayers || i<0) break; 4965 loadLayerString(map, &(map->layers[i]), value);4987 loadLayerString(map, (GET_LAYER(map, i)), value); 4966 4988 break; 4967 4989 case(TRANSPARENT): 4968 4990 msyystate = 2; msyystring = value; … … 5114 5136 layerObj *lp; 5115 5137 5116 5138 for (i=0;i<map->numlayers;i++) { 5117 lp = &(map->layers[i]);5139 lp = (GET_LAYER(map, i)); 5118 5140 5119 5141 /* If the vtable is null, then the layer is never accessed or used -> skip it 5120 5142 */ -
mapgd.c
old new 184 184 if(gdImageTrueColor(image->img.gd)) return; 185 185 186 186 for(i=0; i<map->numlayers; i++) { 187 lp = &(map->layers[i]);187 lp = (GET_LAYER(map, i)); 188 188 if(lp->status == MS_ON || lp->status == MS_DEFAULT) { 189 189 for(j=0; j<lp->numclasses; j++) { 190 190 cp = &(lp->class[j]); … … 3249 3249 3250 3250 cachePtr = &(map->labelcache.labels[l]); /* point to right spot in the label cache */ 3251 3251 3252 layerPtr = &(map->layers[cachePtr->layerindex]); /* set a couple of other pointers, avoids nasty references */3252 layerPtr = (GET_LAYER(map, cachePtr->layerindex)); /* set a couple of other pointers, avoids nasty references */ 3253 3253 labelPtr = &(cachePtr->label); 3254 3254 3255 3255 if(!cachePtr->text || strlen(cachePtr->text) == 0) -
mapgml.c
old new 1424 1424 1425 1425 /* step through the layers looking for query results */ 1426 1426 for(i=0; i<map->numlayers; i++) { 1427 lp = &(map->layers[map->layerorder[i]]);1427 lp = (GET_LAYER(map, map->layerorder[i])); 1428 1428 1429 1429 if(lp->dump == MS_TRUE && lp->resultcache && lp->resultcache->numresults > 0) { /* found results */ 1430 1430 … … 1575 1575 /* step through the layers looking for query results */ 1576 1576 for(i=0; i<map->numlayers; i++) { 1577 1577 1578 lp = &( map->layers[map->layerorder[i]]);1578 lp = &(GET_LAYER(map, map->layerorder[i])); 1579 1579 1580 1580 if(lp->dump == MS_TRUE && lp->resultcache && lp->resultcache->numresults > 0) { /* found results */ 1581 1581 char *layerName; -
mapgraticule.c
old new 200 200 int iAxisTickCount = 0; 201 201 rectObj rectMapCoordinates; 202 202 203 if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE ) 204 return MS_FAILURE; 205 203 206 pInfo->dstartlatitude = rect.miny; 204 207 pInfo->dstartlongitude = rect.minx; 205 208 pInfo->dendlatitude = rect.maxy; … … 686 689 msSetError(MS_MISCERR, "Assertion failed: Null shape or layerinfo!, ", "_AdjustLabelPosition()"); 687 690 return MS_FAILURE; 688 691 } 692 if ( msCheckParentPointer(pLayer->map,"map")==MS_FAILURE ) 693 return MS_FAILURE; 689 694 690 695 ptPoint = pShape->line->point[0]; 691 696 -
map.h
old new 403 403 404 404 #define MS_ENCRYPTION_KEY_SIZE 16 /* Key size: 128 bits = 16 bytes */ 405 405 406 #define GET_LAYER(map, pos) map->layers[pos] 407 #define MS_REFCNT_INCR(obj) obj->refcount++ 408 #define MS_REFCNT_DECR(obj) obj->refcount-- 409 #define MS_REFCNT_INIT(obj) obj->refcount=1 410 #define MS_REFCNT_IS_NOT_ZERO(obj) (MS_REFCNT_DECR(obj))>0 411 #define MS_REFCNT_IS_ZERO(obj) (MS_REFCNT_DECR(obj))<=0 412 406 413 #endif 407 414 408 415 /* General enumerated types - needed by scripts */ … … 995 1002 #ifdef SWIG 996 1003 %immutable; 997 1004 #endif /* SWIG */ 1005 /* reference counting, RFC24 */ 1006 int refcount; 998 1007 int numclasses; 999 1008 int index; 1000 1009 struct map_obj *map; … … 1133 1142 int maxsize; 1134 1143 1135 1144 #ifndef SWIG 1136 layerObj * layers;1145 layerObj **layers; 1137 1146 #endif /* SWIG */ 1138 1147 1139 1148 #ifdef SWIG 1140 1149 %immutable; 1141 1150 #endif /* SWIG */ 1151 /* reference counting, RFC24 */ 1152 int refcount; 1142 1153 int numlayers; /* number of layers in mapfile */ 1143 1154 1144 1155 symbolSetObj symbolset; … … 1346 1357 MS_DLL_EXPORT void initSymbol(symbolObj *s); 1347 1358 MS_DLL_EXPORT int initMap(mapObj *map); 1348 1359 MS_DLL_EXPORT int initLayer(layerObj *layer, mapObj *map); 1349 MS_DLL_EXPORT voidfreeLayer( layerObj * );1360 MS_DLL_EXPORT int freeLayer( layerObj * ); 1350 1361 MS_DLL_EXPORT int initClass(classObj *_class); 1351 1362 MS_DLL_EXPORT void freeClass( classObj * ); 1352 1363 MS_DLL_EXPORT void initLabel(labelObj *label); … … 1853 1864 1854 1865 MS_DLL_EXPORT int msAlphaBlend (int dst, int src); 1855 1866 1867 MS_DLL_EXPORT int msCheckParentPointer(void* p, char* objname); 1868 1856 1869 1857 1870 /* ==================================================================== */ 1858 1871 /* End of prototypes for functions in maputil.c */ -
mapimagemap.c
old new 1877 1877 1878 1878 cachePtr = &(map->labelcache.labels[l]); /* point to right spot in the label cache */ 1879 1879 1880 layerPtr = &(map->layers[cachePtr->layerindex]); /* set a couple of other pointers, avoids nasty references */1880 layerPtr = (GET_LAYER(map, cachePtr->layerindex)); /* set a couple of other pointers, avoids nasty references */ 1881 1881 labelPtr = &(cachePtr->label); 1882 1882 1883 1883 if(!cachePtr->text || strlen(cachePtr->text) == 0) -
mapjoin.c
old new 188 188 msDBFJoinInfo *joininfo; 189 189 190 190 if(join->joininfo) return(MS_SUCCESS); /* already open */ 191 192 if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE ) 193 return MS_FAILURE; 194 191 195 192 196 /* allocate a msDBFJoinInfo struct */ 193 197 joininfo = (msDBFJoinInfo *) malloc(sizeof(msDBFJoinInfo)); … … 345 349 char buffer[MS_BUFFER_LENGTH]; 346 350 347 351 if(join->joininfo) return(MS_SUCCESS); /* already open */ 352 if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE ) 353 return MS_FAILURE; 354 348 355 349 356 /* allocate a msCSVJoinInfo struct */ 350 357 if((joininfo = (msCSVJoinInfo *) malloc(sizeof(msCSVJoinInfo))) == NULL) { -
maplabel.c
old new 105 105 } 106 106 107 107 cachePtr = &(map->labelcache.labels[map->labelcache.numlabels]); /* set up a few pointers for clarity */ 108 layerPtr = &(map->layers[layerindex]);109 classPtr = &( map->layers[layerindex].class[classindex]);108 layerPtr = (GET_LAYER(map, layerindex)); 109 classPtr = &(GET_LAYER(map, layerindex)->class[classindex]); 110 110 111 111 if( label == NULL ) 112 112 label = &(classPtr->label); -
maplegend.c
old new 289 289 ** allocate heights array 290 290 */ 291 291 for(i=0; i<map->numlayers; i++) { 292 lp = &(map->layers[map->layerorder[i]]);292 lp = (GET_LAYER(map, map->layerorder[i])); 293 293 294 294 if((lp->status == MS_OFF) || (lp->type == MS_LAYER_QUERY)) /* skip it */ 295 295 continue; … … 310 310 */ 311 311 n=0; 312 312 for(i=0; i<map->numlayers; i++) { /* Need to find the longest legend label string */ 313 lp = &(map->layers[map->layerorder[i]]);313 lp = (GET_LAYER(map, map->layerorder[i])); 314 314 315 315 if((lp->status == MS_OFF) || (lp->type == MS_LAYER_QUERY)) /* skip it */ 316 316 continue; … … 375 375 376 376 /* for(i=0; i<map->numlayers; i++) { */ 377 377 for(i=map->numlayers-1; i>=0; i--) { 378 lp = &(map->layers[map->layerorder[i]]); /* for brevity */378 lp = (GET_LAYER(map, map->layerorder[i])); /* for brevity */ 379 379 380 380 if((lp->numclasses == 0) || (lp->status == MS_OFF) || (lp->type == MS_LAYER_QUERY)) 381 381 continue; /* skip this layer */ … … 490 490 l = map->numlayers; 491 491 map->numlayers++; 492 492 493 if(initLayer( &(map->layers[l]), map) == -1) return(-1);494 map->layers[l].name = strdup("__embed__legend");495 map->layers[l].type = MS_LAYER_ANNOTATION;493 if(initLayer((GET_LAYER(map, l)), map) == -1) return(-1); 494 GET_LAYER(map, l)->name = strdup("__embed__legend"); 495 GET_LAYER(map, l)->type = MS_LAYER_ANNOTATION; 496 496 497 if(initClass(&( map->layers[l].class[0])) == -1) return(-1);498 map->layers[l].numclasses = 1; /* so we make sure to free it */497 if(initClass(&(GET_LAYER(map, l)->class[0])) == -1) return(-1); 498 GET_LAYER(map, l)->numclasses = 1; /* so we make sure to free it */ 499 499 500 500 /* update the layer order list with the layer's index. */ 501 501 map->layerorder[l] = l; 502 502 } 503 503 504 map->layers[l].status = MS_ON;504 GET_LAYER(map, l)->status = MS_ON; 505 505 506 map->layers[l].class[0].numstyles = 1;507 map->layers[l].class[0].styles[0].symbol = s;508 map->layers[l].class[0].styles[0].color.pen = -1;509 map->layers[l].class[0].label.force = MS_TRUE;510 map->layers[l].class[0].label.size = MS_MEDIUM; /* must set a size to have a valid label definition */506 GET_LAYER(map, l)->class[0].numstyles = 1; 507 GET_LAYER(map, l)->class[0].styles[0].symbol = s; 508 GET_LAYER(map, l)->class[0].styles[0].color.pen = -1; 509 GET_LAYER(map, l)->class[0].label.force = MS_TRUE; 510 GET_LAYER(map, l)->class[0].label.size = MS_MEDIUM; /* must set a size to have a valid label definition */ 511 511 512 512 if(map->legend.postlabelcache) /* add it directly to the image */ 513 msDrawMarkerSymbolGD(&map->symbolset, img, &point, &( map->layers[l].class[0].styles[0]), 1.0);513 msDrawMarkerSymbolGD(&map->symbolset, img, &point, &(GET_LAYER(map, l)->class[0].styles[0]), 1.0); 514 514 else 515 515 msAddLabel(map, l, 0, -1, -1, &point, NULL, " ", 1.0, NULL); 516 516 517 517 /* Mark layer as deleted so that it doesn't interfere with html legends or */ 518 518 /* with saving maps */ 519 map->layers[l].status = MS_DELETE;519 GET_LAYER(map, l)->status = MS_DELETE; 520 520 521 521 return(0); 522 522 } -
mapmygis.c
old new 341 341 342 342 /* TODO: there is an issue with layer order since it's possible that layers to be rendered out of order */ 343 343 for (i=0;i<layer->index;i++) { /* check all layers previous to this one */ 344 lp = &( layer->map->layers[i]);344 lp = &(GET_LAYER(layer->map, i)); 345 345 346 346 if (lp == layer) continue; 347 347 -
mapobject.c
old new 169 169 int i; 170 170 171 171 if(!map) return; 172 173 if ( MS_REFCNT_IS_NOT_ZERO(map) ) { return; } 174 if (map->debug) 175 msDebug("msFreeMap(): freeing map at %p.",map); 176 172 177 msCloseConnections(map); 173 178 174 179 msFree(map->name); … … 203 208 freeReferenceMap(&(map->reference)); 204 209 freeLegend(&(map->legend)); 205 210 206 for(i=0; i<map->numlayers; i++) 207 freeLayer(&(map->layers[i])); 211 //for(i=0; i<map->numlayers; i++) 212 for(i=0; i<MS_MAXLAYERS; i++) { 213 if (GET_LAYER(map, i)!=NULL) { 214 GET_LAYER(map, i)->map=NULL; 215 if ( freeLayer((GET_LAYER(map, i))) == MS_SUCCESS) { 216 free(GET_LAYER(map, i)); 217 } 218 } 219 } 208 220 msFree(map->layers); 209 221 210 222 if (map->layerorder) … … 475 487 map->projection.gt.geotransform[5] *= -1; 476 488 477 489 for(i=0; i<map->numlayers; i++) 478 map->layers[i].project = MS_TRUE;490 GET_LAYER(map, i)->project = MS_TRUE; 479 491 480 492 return InvGeoTransform( map->projection.gt.geotransform, 481 493 map->projection.gt.invgeotransform ); … … 524 536 return -1; 525 537 } 526 538 else if (nIndex < 0) { /* Insert at the end by default */ 527 initLayer(&(map->layers[map->numlayers]), map);528 msCopyLayer(&(map->layers[map->numlayers]), layer);539 //initLayer((GET_LAYER(map, map->numlayers)), map); 540 //msCopyLayer((GET_LAYER(map, map->numlayers)), layer); 529 541 map->layerorder[map->numlayers] = map->numlayers; 530 map->layers[map->numlayers].index = map->numlayers; 542 GET_LAYER(map, map->numlayers) = layer; 543 GET_LAYER(map, map->numlayers)->index = map->numlayers; 544 MS_REFCNT_INCR(layer); 531 545 map->numlayers++; 532 546 return map->numlayers-1; 533 547 } … … 536 550
