当前位置:编程学习 > wap >>

LWUIT引路蜂地图开发示例:第一个地图应用

依旧采用NetBean作为开发IDE,创建一个LwuitGISEngineTutorial项目,将引路蜂地图开发包libgisengine.jar 和LWUIT开发包 LWUIT.jar复制到lib子目录下,并作为外部Jar库文件添加到项目中。将LWUITTheme.res 和 Licence文件guidebee.lic 放在res 子目录下,并将res目录添加到项目中。

 

 \

为避免重复,就示例共用的代码设计一个基类,MapDemoLWUIT,并从LWUIT库的Form派生一个子类MapCanvas用来显示地图

[java] 
//------------------------------------------------------------------------------  
//                         COPYRIGHT 2011 GUIDEBEE  
//                           ALL RIGHTS RESERVED.  
//                     GUIDEBEE CONFIDENTIAL PROPRIETARY  
///////////////////////////////////// REVISIONS ////////////////////////////////  
// Date       Name                 Tracking #         Description  
// ---------  -------------------  ----------         --------------------------  
// 11FEB2011  James Shen                          Initial Creation  
////////////////////////////////////////////////////////////////////////////////  
//--------------------------------- PACKAGE ------------------------------------  
package com.pstreets.gisengine.demo; 
 
//--------------------------------- IMPORTS ------------------------------------  
import java.io.IOException; 
import javax.microedition.midlet.MIDlet; 
 
import com.sun.lwuit.Display; 
import com.sun.lwuit.Form; 
import com.sun.lwuit.Image; 
import com.sun.lwuit.plaf.UIManager; 
import com.sun.lwuit.util.Resources; 
import com.sun.lwuit.Graphics; 
 
import com.mapdigit.gis.MapLayer; 
import com.mapdigit.gis.drawing.IGraphics; 
import com.mapdigit.gis.drawing.IImage; 
import com.mapdigit.gis.raster.IMapDrawingListener; 
import com.mapdigit.gis.raster.IReaderListener; 
import com.mapdigit.gis.raster.MapClient; 
import com.mapdigit.gis.raster.MapTileDownloadManager; 
import com.mapdigit.licence.LicenceManager; 
 
import com.pstreets.gisengine.demo.lwuit.drawing.LWUITGraphicsFactory; 
import com.sun.lwuit.Painter; 
import com.sun.lwuit.geom.Rectangle; 
 
 
//[------------------------------ MAIN CLASS ----------------------------------]  
//--------------------------------- REVISIONS ----------------------------------  
// Date       Name                 Tracking #         Description  
// --------   -------------------  -------------      --------------------------  
// 11FEB2011  James Shen                          Initial Creation  
////////////////////////////////////////////////////////////////////////////////  
/**
 * Base class for all Map Demos on LWUIT.
 * <hr><b>© Copyright 2011 Guidebee, Inc. All Rights Reserved.</b>
 * @version     1.00, 11/02/11
 * @author      Guidebee Pty Ltd.
 */ 
public abstract class MapDemoLWUIT extends MIDlet implements IReaderListener, 
        IMapDrawingListener { 
 
    protected MapClient map; 
    protected MapTileDownloadManager mapTileDownloadManager; 
    protected IImage mapImage; 
    protected IGraphics mapGraphics; 
    protected MapCanvas canvas; 
 
    public MapDemoLWUIT() { 
        try { 
            LicenceManager licenceManager = LicenceManager.getInstance(); 
            long keys[] = {0x34ba283b8daeb659L, -0x53c811f9da86e998L, 
            -0x34ba25c3c581521eL, 0xf15df9fc7e45628L, 0x6a4ece44296c0287L, 
            0x4ab0cff532902b1cL,}; 
            licenceManager.addLicence("GuidebeeMap_JavaME", keys); 
        } catch (Exception ex) { 
            ex.printStackTrace(); 
        } 
    } 
 
    protected void init() { 
        Display.init(this); 
        try { 
            Resources r = Resources.open("/javaTheme.res"); 
            UIManager.getInstance().setThemeProps( 
                    r.getTheme(r.getThemeResourceNames()[0])); 
        } catch (IOException ex) { 
            ex.printStackTrace(); 
        } 
        //set the graphics factory  
        MapLayer.setAbstractGraphicsFactory(LWUITGraphicsFactory.getInstance()); 
        mapImage = MapLayer.getAbstractGraphicsFactory() 
                .createImage(Display.getInstance().getDisplayWidth(), 
                Display.getInstance().getDisplayHeight()); 
        mapGraphics = mapImage.getGraphics(); 
        //Create the Digital Map objects.  
        mapTileDownloadManager = new MapTileDownloadManager(this); 
        map = new MapClient(1024, 1024, mapTileDownloadManager); 
  &nb

补充:移动开发 , 其他 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,