Java ME引路蜂地图开发示例:设置地图类型

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

创建RasterMap实例之后,可以对其进行放大,缩小,平移,设置地图类型等操作。

在第一个地图应用中,在调用RasterMap.setCenter 时可以指定地图类型,另外也可以使用RasterMap.setMapType来更改地图类型,地图开发包中定义了Google 地图,Google 中国地图,Bing 地图,Bing 卫星图等20多种地图类型,也就可设置自已定义地图类型。
下面的例子顺序显示Google 中国地图,MapAbc地图,Bing 中国地图

  1. //------------------------------------------------------------------------------
  2. //                         COPYRIGHT 2011 GUIDEBEE
  3. //                           ALL RIGHTS RESERVED.
  4. //                     GUIDEBEE CONFIDENTIAL PROPRIETARY
  5. ///////////////////////////////////// REVISIONS ////////////////////////////////
  6. // Date       Name                 Tracking #         Description
  7. // ---------  -------------------  ----------         --------------------------
  8. // 28JAN2011  James Shen                              Initial Creation
  9. ////////////////////////////////////////////////////////////////////////////////
  10. //--------------------------------- PACKAGE ------------------------------------
  11. package com.pstreets.gisengine.demo.midp;
  12.  
  13. //--------------------------------- IMPORTS ------------------------------------
  14. import com.mapdigit.gis.geometry.GeoLatLng;
  15. import com.mapdigit.gis.raster.MapType;
  16. import com.pstreets.gisengine.demo.MapDemoMIDP;
  17. import javax.microedition.lcdui.Command;
  18. import javax.microedition.lcdui.CommandListener;
  19. import javax.microedition.lcdui.Display;
  20. import javax.microedition.lcdui.Displayable;
  21.  
  22. //[------------------------------ MAIN CLASS ----------------------------------]
  23. //--------------------------------- REVISIONS ----------------------------------
  24. // Date       Name                 Tracking #         Description
  25. // --------   -------------------  -------------      --------------------------
  26. // 28JAN2011  James Shen                              Initial Creation
  27. ////////////////////////////////////////////////////////////////////////////////
  28. /**
  29.  *  map type demo for Guidebee Map API on MIDP platform.
  30.  * <hr><b>&copy; Copyright 2011 Guidebee, Inc. All Rights Reserved.</b>
  31.  * @version     1.00, 28/01/11
  32.  * @author      Guidebee Pty Ltd.
  33.  */
  34. public class MapTypeMIDP extends MapDemoMIDP implements CommandListener {
  35.  
  36.     private int mapType = 0;
  37.     private static final int[] mapTypes = {MapType.GOOGLECHINA,
  38.         MapType.MAPABCCHINA, MapType.MICROSOFTCHINA};
  39.     private Command mapTypeCommand = new Command("MapType", Command.OK, 1);
  40.  
  41.     public void startApp() {
  42.  
  43.         init();
  44.         canvas.addCommand(mapTypeCommand);
  45.         canvas.setCommandListener(this);
  46.         GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);
  47.         map.setCenter(center, 13, MapType.GOOGLECHINA);
  48.         Display.getDisplay(this).setCurrent(canvas);
  49.     }
  50.  
  51.     public void commandAction(Command c, Displayable d) {
  52.         if (c == mapTypeCommand) {
  53.             map.setMapType(mapTypes[mapType]);
  54.             mapType++;
  55.             mapType %= mapTypes.length;
  56.         }
  57.     }
  58. }