dd

Java ME引路蜂地图开发示例:离线地图示例

jerry 地图开发 2015年11月26日 收藏

在手机上,离线地图包一般放在SD卡上,然后通过文件读取。这里为简单起见,将离线放在例子的资源目录中和应用编译在一起。实际应用中请单独存放这些地图包。引路蜂地图开发包支持同时读取多个地图包,这是通过MapTiledZone类和MapTileStreamReader类来完成的。每个地图包对应于一个MapTiledZone,地图包对每张地图建立的索引以加速图片检索将记录地图包存放的区域和缩放级别。而类MapTileStreamReader提供了管理这些地图包的方法.

//------------------------------------------------------------------------------
//                         COPYRIGHT 2010 GUIDEBEE
//                           ALL RIGHTS RESERVED.
//                     GUIDEBEE CONFIDENTIAL PROPRIETARY
///////////////////////////////////// REVISIONS ////////////////////////////////
// Date       Name                 Tracking #         Description
// ---------  -------------------  ----------         --------------------------
// 16SEP2010  James Shen                 	          Initial Creation
////////////////////////////////////////////////////////////////////////////////
//--------------------------------- PACKAGE ------------------------------------
package com.pstreets.gisengine.demo.midp;

//--------------------------------- IMPORTS ------------------------------------
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.raster.MapTileStreamReader;
import com.mapdigit.gis.raster.MapTiledZone;
import com.mapdigit.gis.raster.MapType;
import com.pstreets.gisengine.demo.MapDemoMIDP;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Display;

//[------------------------------ MAIN CLASS ----------------------------------]
//--------------------------------- REVISIONS ----------------------------------
// Date       Name                 Tracking #         Description
// --------   -------------------  -------------      --------------------------
// 16SEP2010  James Shen                 	          Initial Creation
////////////////////////////////////////////////////////////////////////////////
/**
 *  stored map demo for Guidebee Map API on MIDP platform.
 * <hr><b>&copy; Copyright 2010 Guidebee, Inc. All Rights Reserved.</b>
 * @version     1.00, 16/09/10
 * @author      Guidebee Pty Ltd.
 */
public class StoredMapMIDP extends MapDemoMIDP {

    MapTileStreamReader localMapTileFileReader;

    public void startApp() {

        init();

        InputStream is = this.getClass().getResourceAsStream("/world03.map");
        byte[] buffer = null;
        try {
            buffer = new byte[is.available()];
            is.read(buffer);
            is.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
        MapTiledZone mapTiledZone = new MapTiledZone(new DataInputStream(bais));

        localMapTileFileReader
                = mapTileDownloadManager.getInteralMapTileStreamReader();
        localMapTileFileReader.addZone(mapTiledZone);
        //you can add more store map package here use addZone

        localMapTileFileReader.open();
        GeoLatLng center = new GeoLatLng(-31.948275, 115.857562);
        map.setCenter(center, 3, MapType.GOOGLEMAP);
        Display.getDisplay(this).setCurrent(canvas);
    }

    public void destroyApp(boolean unconditional) {
        localMapTileFileReader.close();
    }
}

World03.map 存放了1-4级世界地图。MapTileManager 内部定义一个MapTileStreamReader ,如果设置了本地地图,MapTileManager会先从本地读取,如果本地没有需要图片,然后再从地图服务器上下载。可以使用MapTileStreamReader的addZone 方法添加多个地图包,地图包可以有重叠的区域,这时添加的先后顺序对结果就会影响,如果有多个,则取第一个。

离线地图工具参见: 和

dd