Merge pull request #280 from mapbox/custom-params

Allow custom map parameters
This commit is contained in:
Tom MacWright 2013-06-17 06:16:50 -07:00
commit 84e0628a8e
4 changed files with 24 additions and 1 deletions

View File

@ -162,6 +162,11 @@ carto.Renderer.prototype.render = function render(m, callback) {
if (!v && v !== 0) return memo;
switch (k) {
// Known skippable properties.
case 'srs':
case 'Layer':
case 'Stylesheet':
break;
// Non URL-bound TileJSON properties.
case 'bounds':
case 'center':
@ -187,6 +192,16 @@ carto.Renderer.prototype.render = function render(m, callback) {
memo.push(' <Parameter name="interactivity_layer">' + v.layer + '</Parameter>');
memo.push(' <Parameter name="interactivity_fields">' + v.fields + '</Parameter>');
break;
// Support any additional scalar properties.
default:
if ('string' === typeof v) {
memo.push(' <Parameter name="' + k + '"><![CDATA[' + v + ']]></Parameter>');
} else if ('number' === typeof v) {
memo.push(' <Parameter name="' + k + '">' + v + '</Parameter>');
} else if ('boolean' === typeof v) {
memo.push(' <Parameter name="' + k + '">' + v + '</Parameter>');
}
break;
}
return memo;
}, []);

View File

@ -8,6 +8,8 @@
<Parameter name="format">png</Parameter>
<Parameter name="minzoom">0</Parameter>
<Parameter name="maxzoom">22</Parameter>
<Parameter name="scale">1</Parameter>
<Parameter name="metatile">2</Parameter>
</Parameters>

View File

@ -15,7 +15,10 @@
"layer": "world",
"fields": ["NAME"]
},
"omitted": "Omitted property.",
"customString": "Hello world",
"customNumber": 5,
"customBoolean": true,
"customOmitted": { "foo": "bar" },
"Stylesheet": [],
"Layer": [{
"name": "world",

View File

@ -15,6 +15,9 @@
<Parameter name="format">png</Parameter>
<Parameter name="interactivity_layer">world</Parameter>
<Parameter name="interactivity_fields">NAME</Parameter>
<Parameter name="customString"><![CDATA[Hello world]]></Parameter>
<Parameter name="customNumber">5</Parameter>
<Parameter name="customBoolean">true</Parameter>
</Parameters>
</Map>