2012年4月17日星期二

利用ditu.google.com制作出行地图

        ditu.google.com的特点是在于卫星图片上有道路标记,实质是道路图层和卫星照片图层的组合。制作离线地图软件是基于Java的Mobile Atlas Creator(MAC),MAC不带google这类的商业地图的地图源,但允许用户自定义,帮助文件README.HTM(位于安装目录)中有详细介绍。制作多图层的地图源可以参考模板:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customMultiLayerMapSource>
    <name>Custom OSM Mapnik with Hills (Ger)</name>
    <tileType>PNG</tileType>
    <layers>
        <customMapSource>
            <name>Custom OSM Mapnik</name>
            <minZoom>0</minZoom>
            <maxZoom>18</maxZoom>
            <tileType>PNG</tileType>
            <tileUpdate>None</tileUpdate>
            <url>http://tile.openstreetmap.org/{$z}/{$x}/{$y}.png</url>
            <backgroundColor>#000000</backgroundColor>
        </customMapSource>
        <customMapSource>
            <name>Custom transparent hillshade</name>
            <minZoom>0</minZoom>
            <maxZoom>18</maxZoom>
            <tileType>PNG</tileType>
            <tileUpdate>None</tileUpdate>
            <url>http://www.wanderreitkarte.de/hills/{$z}/{$x}/{$y}.png</url>
        </customMapSource>
    </layers>
</customMultiLayerMapSource>
<url>…</url>表示地图源路径,路径可以通过FireFox浏览器访问ditu.google.com得到,其中需要借助FireBug插件,效果如图所示:
图中红圈为地图源地址,如路径源地址:
http://mt1.google.cn/vt/imgtp=png32&lyrs=h@176000000&hl=zh-CN&gl=cn&src=app&x=419&y=195&z=9&s=Gali
和卫星照片源地址:
http://mt3.google.cn/vt/lyrs=s@108&hl=zh-CN&gl=cn&src=app&x=419&y=194&z=9&s=Gal
此时将x、y和z的值替换为{$x}、{$y}和{$z}并将地址中的“&”改为符合xml规范的“&amp;”否则打开MAC时会出如下错误:
        将获得的地图源地址带入模板并进行一定的完善可得到如下地图源文件代码:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customMultiLayerMapSource>
    <name>Google Ditu</name>
    <tileType>JPG</tileType>
    <layers>
        <customMapSource>
        <name>Satellite</name>
        <minZoom>0</minZoom>
        <maxZoom>19</maxZoom>
        <tileType>jpg</tileType>
        <tileUpdate>IfNoneMatch</tileUpdate>
        <url>http://{$serverpart}.google.cn/vt/lyrs=s@108&amp;gl=cn&amp;src=app&amp;host=ditu.google.com&amp;x={$x}&amp;y={$y}&amp;z={$z}</url>
        <backgroundColor>#000000</backgroundColor>
            <serverParts>mt0 mt1 mt2 mt3</serverParts>
        </customMapSource>
        <customMapSource>
            <name>Path</name>
            <minZoom>0</minZoom>
            <maxZoom>19</maxZoom>
            <tileType>PNG</tileType>
            <tileUpdate>IfNoneMatch</tileUpdate>
            <url>http://{$serverpart}.google.cn/vt/imgtp=png32&amp;lyrs=h@176000000&amp;hl=zh-CN&amp;gl=cn&amp;src=app&amp;x={$x}&amp;y={$y}&amp;z={$z}&amp;s=Galileo</url>
            <backgroundColor>#000000</backgroundColor>
            <serverParts>mt0 mt1 mt2 mt3</serverParts>
        </customMapSource>
    </layers>
</customMultiLayerMapSource>
各部分具体含义请参见README.HTM和MAC的Wiki,需要说明的是在利用FireBug获取Google地图源时需要关闭Google地图的MapsGL特性,否则通过路径源地址将获得到路径的矢量数据而非路径图片。
地图源文件存放在安装路径下的mapsources文件夹中,此类地图源的扩展名为xml。在软件中选用自制的地图源便可下载含路径的卫星地图。
        软件使用请参阅相关教程。

没有评论: