有人知道如何将GMap静态JSON转换为HTML网址? [英] Someone knows how to convert GMap Static JSON to a HTML url?
问题描述
我已经从下载了示例风格的地图。我尝试转换为网址,例如 http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=512x512&zoom=15&center=芝加哥,但我做得不好。我试图改变下面的例子:
JSON看起来像这样:
$ b {featureType:poi,stylers:[{visibility:off}]},{stylers:[{saturation :-70},{ 亮度 :37},{ 伽马 :1.15}]},{ 的ElementType : 标签, 造型器:[{ 伽马:0.26},{ 能见度 :off}}},
{featureType:road,stylers:[{lightness:0},{saturation:0},{hue :#ffffff},{gamma:0}]},
{featureType:road,elementType:labels.text.stroke,stylers: [{visibility:off}]},
{featureType:road.arterial,elementType:geometry,stylers:[{lightness: 20}]},
{featureType:road.highway,elementType:geometry,stylers:[{lightness:50},{saturation 0},{hue:#ffffff}]},
{featureType:administrative.province,stylers:[{visibility:on {lightness: - 50}]},
{featureType:administrative.province,elementType:labels.text.stroke,stylers:[{visibility:off}]},
{featureType:administrative.province,elementType:labels.text,stylers:[{lightness:20}]}
pre>
我改变了下一个,但它不起作用,我做错了什么! :S
http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=512x512&变焦= 15&安培;中心=芝加哥&安培;格式= PNG&安培;式=特征:POI%7Cvisibility:关%7Csaturation:-70%7Clightness:37%7Cgamma:1.15%7Celement:标签%7Cgamma:0.26%7Cvisibility:关闭&安培;式=道路%7Clightness:0%7Csaturation:0%7Chue:#FFFFFF%7Cgamma:0&安培;式=道路%7Celement:labels.text.stroke%7Cvisibility:关闭&安培;式= road.arterial%7Celement:几何%7Clightness:20安培;式= road.highway%7Celement:几何%7Clightness:50%7Csaturation:0%7Chue:#FFFFFF&安培;式= administrative.province%7Cvisibility:上%7Clightness:-50安培;式= administrative.province%7Celement:labels.text.stroke% 7Cvisibility:off& style = administrative.province%7Celement:labels.text%7Clightness:20
可以给我一个建议,我会很感激。 你应该阅读静态地图API指南中的样式化地图部分。
定制的样式地图由一个或多个指定样式组成,每个样式都通过静态地图请求URL中的样式参数指示。 其他样式是通过传递其他样式参数来指定的。
所以你需要传递多个
& style =
添加到URL中。 (每个要素/元素的元素)
(您已经这样做了)
对于需要使用
0xRRGGBB
语法的颜色。
另外在您的示例中,JSON中的第一行包含三个组。第二个指的是地图的全局样式,第三个指向地图中的所有标签,而不是特征:poi
。因此,您需要另一种针对feature:all 的样式,另一种针对 元素:labels
您链接的时髦地图示例会翻译成类似于(并非所有样式都包含在内)
-
& style = feature:poi | visibility:off
-
& style = feature:all | saturation:-70 | lightness:37 | gamma:1.15
-
& style = element:labels | visibility :off
-
& style = feature:road | lightness:0 | saturation:0 | hue:0xffffff | gamma:0
-
& style = feature:road.highway | element:geometry | lightness:50 | saturation:0 | hue:0xffffff
(请记住,当设置可见性
到 off
操作该特性/元素的任何其他属性没有意义)
当添加到网址时,您将获得
以下是将snazzymap json转换为Google Static Map urls的小工具。
工具位于 http://jsfiddle.net/gaby/s6Dyp/
I have downloaded an example styled map from snazzymaps.com. I try to transform to an url like http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=512x512&zoom=15¢er=Chicago but I'm not doing it well. I'm trying to transform the next example:
Example Google Map Styled Static
The JSON looks like that:
styles: [
{"featureType":"poi","stylers":[{"visibility":"off"}]},{"stylers":[{"saturation":-70},{"lightness":37},{"gamma":1.15}]},{"elementType":"labels","stylers":[{"gamma":0.26},{"visibility":"off"}]},
{"featureType":"road","stylers":[{"lightness":0},{"saturation":0},{"hue":"#ffffff"},{"gamma":0}]},
{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"visibility":"off"}]},
{"featureType":"road.arterial","elementType":"geometry","stylers":[{"lightness":20}]},
{"featureType":"road.highway","elementType":"geometry","stylers":[{"lightness":50},{"saturation":0},{"hue":"#ffffff"}]},
{"featureType":"administrative.province","stylers":[{"visibility":"on"},{"lightness":-50}]},
{"featureType":"administrative.province","elementType":"labels.text.stroke","stylers":[{"visibility":"off"}]},
{"featureType":"administrative.province","elementType":"labels.text","stylers":[{"lightness":20}]}
I have transformed the next, but It doesn't work, I'm doing something wrong!! :S
http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=512x512&zoom=15¢er=Chicago&format=png&style=feature:poi%7Cvisibility:off%7Csaturation:-70%7Clightness:37%7Cgamma:1.15%7Celement:labels%7Cgamma:0.26%7Cvisibility:off&style=road%7Clightness:0%7Csaturation:0%7Chue:#ffffff%7Cgamma:0&style=road%7Celement:labels.text.stroke%7Cvisibility:off&style=road.arterial%7Celement:geometry%7Clightness:20&style=road.highway%7Celement:geometry%7Clightness:50%7Csaturation:0%7Chue:#ffffff&style=administrative.province%7Cvisibility:on%7Clightness:-50&style=administrative.province%7Celement:labels.text.stroke%7Cvisibility:off&style=administrative.province%7Celement:labels.text%7Clightness:20
If someone can send me an advice, I would be gratefully.
You should read the styled maps section of the Static Maps API Guide.
A customized "styled" map consists of one or more specified styles, each indicated through a style parameter within the Static Map request URL. Additional styles are specified by passing additional style parameters.
So you need to pass multiple &style=
to the URL. (one for each feature/element you style)
(You already do that)
For the colors you need to use the 0xRRGGBB
syntax.
Also in your example the first line in your JSON holds threee groups. The second refers to the global styling of the map and the third to all the labels in the map, not to the feature:poi
. So you need another style for that which targets feature:all
and one for element:labels
The snazzymap example you linked to would translate to something like (not all styles are included)
&style=feature:poi|visibility:off
&style=feature:all|saturation:-70|lightness:37|gamma:1.15
&style=element:labels|visibility:off
&style=feature:road|lightness:0|saturation:0|hue:0xffffff|gamma:0
&style=feature:road.highway|element:geometry|lightness:50|saturation:0|hue:0xffffff
(keep in mind that when setting visibility
to off
there is no point in manipulating any other property of that feature/element)
And when added to the url, you would get
And here is little tool to convert snazzymap json to Google Static Map urls..
Tool at http://jsfiddle.net/gaby/s6Dyp/
这篇关于有人知道如何将GMap静态JSON转换为HTML网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!