Skip to content

Commit

Permalink
MVT: Sets correct media type of Mapbox vector tiles output (#6331)
Browse files Browse the repository at this point in the history
The correct media type is defined as "vnd.mapbox-vector-tile" (see http://www.iana.org/assignments/media-types/media-types.xhtml). Use that by default, but also keep application/x-protobuf as a possibility (e.g. it will still be advertised in GetCapabilities response).
  • Loading branch information
ravhed committed May 20, 2021
1 parent c862b04 commit 2c3767a
Show file tree
Hide file tree
Showing 48 changed files with 62 additions and 19 deletions.
2 changes: 1 addition & 1 deletion maperror.c
Expand Up @@ -422,7 +422,7 @@ void msWriteErrorImage(mapObj *map, char *filename, int blank)

/* Default to GIF if no suitable GD output format set */
if (format == NULL || !MS_RENDERER_PLUGIN(format))
format = msCreateDefaultOutputFormat( NULL, "AGG/PNG8", "png" );
format = msCreateDefaultOutputFormat( NULL, "AGG/PNG8", "png", NULL );

if(!format->transparent) {
if(map && MS_VALID_COLOR(map->imagecolor)) {
Expand Down
2 changes: 1 addition & 1 deletion mapfile.c
Expand Up @@ -4931,7 +4931,7 @@ static int loadOutputFormat(mapObj *map)
goto load_output_error;
}

format = msCreateDefaultOutputFormat( map, driver, name );
format = msCreateDefaultOutputFormat( map, driver, name, NULL );
if( format == NULL ) {
msSetError(MS_MISCERR,
"OUTPUTFORMAT (%s) clause references driver (%s), but this driver isn't configured.",
Expand Down
4 changes: 2 additions & 2 deletions mapmvt.c
Expand Up @@ -544,8 +544,8 @@ int msMVTWriteTile( mapObj *map, int sendheaders ) {
if( sendheaders ) {
msIO_fprintf( stdout,
"Content-Length: %d\r\n"
"Content-Type: application/x-protobuf\r\n\r\n",
len);
"Content-Type: %s\r\n\r\n",
len, MS_IMAGE_MIME_TYPE(map->outputformat));
}
msIO_fwrite(buf,len,1,stdout);
msFree(buf);
Expand Down
19 changes: 14 additions & 5 deletions mapoutput.c
Expand Up @@ -121,6 +121,9 @@ struct defaultOutputFormatEntry defaultoutputformats[] = {
#endif
#ifdef USE_PBF
{"mvt","MVT","application/vnd.mapbox-vector-tile"},
// The following format is added to keep backward compatibility
// for the application/x-protobuf media type
{"mvtxprotobuf","MVT","application/x-protobuf"},
#endif
{"json","UTFGrid","application/json"},
{NULL,NULL,NULL}
Expand Down Expand Up @@ -164,13 +167,14 @@ int msPostMapParseOutputFormatSetup( mapObj *map )

outputFormatObj *msCreateDefaultOutputFormat( mapObj *map,
const char *driver,
const char *name )
const char *name,
const char *mimetype )

{

outputFormatObj *format = NULL;
if( strncasecmp(driver,"GD/",3) == 0 ) {
return msCreateDefaultOutputFormat( map, "AGG/PNG8", name );
return msCreateDefaultOutputFormat( map, "AGG/PNG8", name, mimetype );
}

if( strcasecmp(driver,"UTFGRID") == 0 ) {
Expand Down Expand Up @@ -214,7 +218,12 @@ outputFormatObj *msCreateDefaultOutputFormat( mapObj *map,
else if( strcasecmp(driver,"MVT") == 0 ) {
if(!name) name="mvt";
format = msAllocOutputFormat( map, name, driver );
format->mimetype = msStrdup("application/x-protobuf");
if (mimetype) {
format->mimetype = msStrdup(mimetype);
} else {
format->mimetype = msStrdup("application/vnd.mapbox-vector-tile");
}

format->imagemode = MS_IMAGEMODE_FEATURE;
format->extension = msStrdup("pbf");
format->renderer = MS_RENDER_WITH_MVT;
Expand Down Expand Up @@ -410,7 +419,7 @@ void msApplyDefaultOutputFormats( mapObj *map )
defEntry = defaultoutputformats;
while(defEntry->name) {
if( msSelectOutputFormat( map, defEntry->name ) == NULL )
msCreateDefaultOutputFormat( map, defEntry->driver, defEntry->name );
msCreateDefaultOutputFormat( map, defEntry->driver, defEntry->name, defEntry->mimetype );
defEntry++;
}
if( map->imagetype != NULL )
Expand Down Expand Up @@ -609,7 +618,7 @@ outputFormatObj *msSelectOutputFormat( mapObj *map,
struct defaultOutputFormatEntry *formatEntry = defaultoutputformats;
while(formatEntry->name) {
if(!strcasecmp(imagetype,formatEntry->name) || !strcasecmp(imagetype,formatEntry->mimetype)) {
format = msCreateDefaultOutputFormat( map, formatEntry->driver, formatEntry->name );
format = msCreateDefaultOutputFormat( map, formatEntry->driver, formatEntry->name, formatEntry->mimetype );
break;
}
formatEntry++;
Expand Down
4 changes: 2 additions & 2 deletions mapscript/php/mapscript_i.c
Expand Up @@ -1988,7 +1988,7 @@ outputFormatObj* outputFormatObj_new(const char *driver, char *name)
{
outputFormatObj *format;

format = msCreateDefaultOutputFormat(NULL, driver, name);
format = msCreateDefaultOutputFormat(NULL, driver, name, NULL);

/* in the case of unsupported formats, msCreateDefaultOutputFormat
should return NULL */
Expand Down Expand Up @@ -2029,7 +2029,7 @@ imageObj *symbolObj_getImage(symbolObj *self, outputFormatObj *input_format)
if (input_format) {
format = input_format;
} else {
format = msCreateDefaultOutputFormat(NULL, "AGG/PNG", "png");
format = msCreateDefaultOutputFormat(NULL, "AGG/PNG", "png", NULL);

if (format)
msInitializeRendererVTable(format);
Expand Down
2 changes: 1 addition & 1 deletion mapscript/swiginc/image.i
Expand Up @@ -49,7 +49,7 @@
format = input_format;
}
else {
format = msCreateDefaultOutputFormat(NULL, "AGG/PNG", "aggpng");
format = msCreateDefaultOutputFormat(NULL, "AGG/PNG", "aggpng", NULL);
if (format)
msInitializeRendererVTable(format);
}
Expand Down
2 changes: 1 addition & 1 deletion mapscript/swiginc/outputformat.i
Expand Up @@ -34,7 +34,7 @@
{
outputFormatObj *format;

format = msCreateDefaultOutputFormat(NULL, driver, name);
format = msCreateDefaultOutputFormat(NULL, driver, name, NULL);

/* in the case of unsupported formats, msCreateDefaultOutputFormat
should return NULL */
Expand Down
2 changes: 1 addition & 1 deletion mapscript/swiginc/symbol.i
Expand Up @@ -106,7 +106,7 @@
}
else
{
format = msCreateDefaultOutputFormat(NULL, "AGG/PNG", "aggpng");
format = msCreateDefaultOutputFormat(NULL, "AGG/PNG", "aggpng", NULL);
if (format)
msInitializeRendererVTable(format);
}
Expand Down
2 changes: 1 addition & 1 deletion mapserver.h
Expand Up @@ -2807,7 +2807,7 @@ extern "C" {
MS_DLL_EXPORT outputFormatObj *msSelectOutputFormat( mapObj *map, const char *imagetype );
MS_DLL_EXPORT void msApplyOutputFormat( outputFormatObj **target, outputFormatObj *format, int transparent, int interlaced, int imagequality );
MS_DLL_EXPORT const char *msGetOutputFormatOption( outputFormatObj *format, const char *optionkey, const char *defaultresult );
MS_DLL_EXPORT outputFormatObj *msCreateDefaultOutputFormat( mapObj *map, const char *driver, const char *name );
MS_DLL_EXPORT outputFormatObj *msCreateDefaultOutputFormat( mapObj *map, const char *driver, const char *name, const char *mimetype );
MS_DLL_EXPORT int msPostMapParseOutputFormatSetup( mapObj *map );
MS_DLL_EXPORT void msSetOutputFormatOption( outputFormatObj *format, const char *key, const char *value );
MS_DLL_EXPORT void msGetOutputFormatMimeList( mapObj *map, char **mime_list, int max_mime );
Expand Down
2 changes: 1 addition & 1 deletion mapservutil.c
Expand Up @@ -1530,7 +1530,7 @@ int msCGIDispatchImageRequest(mapservObj *mapserv)
case TILE:
msTileSetExtent(mapserv);

if(!strcmp(MS_IMAGE_MIME_TYPE(mapserv->map->outputformat), "application/x-protobuf")) {
if(!strcmp(MS_IMAGE_MIME_TYPE(mapserv->map->outputformat), "application/vnd.mapbox-vector-tile") || !strcmp(MS_IMAGE_MIME_TYPE(mapserv->map->outputformat), "application/x-protobuf")) {
if(msMVTWriteTile(mapserv->map, mapserv->sendheaders) != MS_SUCCESS) return MS_FAILURE;
return MS_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion mapwms.cpp
Expand Up @@ -3770,7 +3770,7 @@ int msWMSGetMap(mapObj *map, int nVersion, char **names, char **values, int nume
} else {

/* intercept requests for Mapbox vector tiles */
if(!strcmp(MS_IMAGE_MIME_TYPE(map->outputformat), "application/x-protobuf")) {
if(!strcmp(MS_IMAGE_MIME_TYPE(map->outputformat), "application/vnd.mapbox-vector-tile") || !strcmp(MS_IMAGE_MIME_TYPE(map->outputformat), "application/x-protobuf")) {
int status=0;
if((status = msMVTWriteTile(map, MS_TRUE)) != MS_SUCCESS) return MS_FAILURE;
return MS_SUCCESS;
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/ows_all_wms_capabilities.xml
Expand Up @@ -61,6 +61,7 @@ Content-Type: text/xml; charset=UTF-8
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/ows_all_wms_capabilities_post.xml
Expand Up @@ -61,6 +61,7 @@ Content-Type: text/xml; charset=UTF-8
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -64,6 +64,7 @@ Content-Type: application/vnd.ogc.wms_xml; charset=UTF-8
<Format>image/svg+xml</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -61,6 +61,7 @@ Content-Type: text/xml; charset=UTF-8
<Format>image/svg+xml</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/ows_wms_capabilities.xml
Expand Up @@ -36,6 +36,7 @@ Content-Type: text/xml; charset=UTF-8
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -36,6 +36,7 @@ Content-Type: text/xml; charset=UTF-8
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -36,6 +36,7 @@ Content-Type: text/xml; charset=UTF-8
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms111_test_xml_escaping.xml
Expand Up @@ -58,6 +58,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms130_test_xml_escaping.xml
Expand Up @@ -55,6 +55,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_dimension_cap.xml
Expand Up @@ -39,6 +39,7 @@ Content-Type: application/vnd.ogc.wms_xml; charset=UTF-8
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_dimension_cap130.xml
Expand Up @@ -36,6 +36,7 @@ Content-Type: text/xml; charset=UTF-8
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_empty_cap111.xml
Expand Up @@ -36,6 +36,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_empty_cap130.xml
Expand Up @@ -33,6 +33,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_empty_cap_latestversion.xml
Expand Up @@ -33,6 +33,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -38,6 +38,7 @@ Content-Type: application/vnd.ogc.wms_xml; charset=UTF-8
<Format>image/svg+xml</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_inspire_cap.xml
Expand Up @@ -57,6 +57,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_inspire_cap_111.xml
Expand Up @@ -58,6 +58,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_inspire_cap_111_eng.xml
Expand Up @@ -58,6 +58,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_inspire_cap_111_ger.xml
Expand Up @@ -58,6 +58,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_inspire_cap_eng.xml
Expand Up @@ -57,6 +57,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_inspire_cap_ger.xml
Expand Up @@ -57,6 +57,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_inspire_scenario1_cap130.xml
Expand Up @@ -55,6 +55,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -55,6 +55,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -55,6 +55,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_inspire_scenario2_cap111.xml
Expand Up @@ -57,6 +57,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -57,6 +57,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -57,6 +57,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
1 change: 1 addition & 0 deletions msautotest/wxs/expected/wms_inspire_scenario2_cap130.xml
Expand Up @@ -55,6 +55,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -55,6 +55,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down
Expand Up @@ -55,6 +55,7 @@
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
Expand Down

0 comments on commit 2c3767a

Please sign in to comment.