Java ME引路蜂地图开发示例:地图平移

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

RasterMap 有两个方法可以用于平移地图,panTo 将地图移动到指定经纬度坐标,panDirection(dx,dy) 将地图从当前位置平移dx,dy 个象素。
下列示例可以上,下,左,右平移地图。

  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. //[------------------------------ MAIN CLASS ----------------------------------]
  22. //--------------------------------- REVISIONS ----------------------------------
  23. // Date       Name                 Tracking #         Description
  24. // --------   -------------------  -------------      --------------------------
  25. // 28JAN2011  James Shen                              Initial Creation
  26. ////////////////////////////////////////////////////////////////////////////////
  27. /**
  28.  *  map pan demo for Guidebee Map API on MIDP platform.
  29.  * <hr><b>&copy; Copyright 2011 Guidebee, Inc. All Rights Reserved.</b>
  30.  * @version     1.00, 28/01/11
  31.  * @author      Guidebee Pty Ltd.
  32.  */
  33. public class MapPanMIDP extends MapDemoMIDP implements CommandListener {
  34.  
  35.     private Command mapUpCommand = new Command("Up", Command.OK, 1);
  36.     private Command mapDownCommand = new Command("Down", Command.ITEM, 1);
  37.     private Command mapLeftCommand = new Command("Left", Command.ITEM, 1);
  38.     private Command mapRightCommand = new Command("Right", Command.ITEM, 1);
  39.  
  40.     public void startApp() {
  41.  
  42.         init();
  43.         canvas.addCommand(mapUpCommand);
  44.         canvas.addCommand(mapDownCommand);
  45.         canvas.addCommand(mapLeftCommand);
  46.         canvas.addCommand(mapRightCommand);
  47.         canvas.setCommandListener(this);
  48.         GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);
  49.         map.setCenter(center, 13, MapType.MICROSOFTCHINA);
  50.         Display.getDisplay(this).setCurrent(canvas);
  51.     }
  52.  
  53.     public void commandAction(Command c, Displayable d) {
  54.         if (c == mapUpCommand) {
  55.             map.panDirection(0, -32);
  56.  
  57.         } else if (c == mapDownCommand) {
  58.             map.panDirection(0, 32);
  59.         } else if (c == mapLeftCommand) {
  60.             map.panDirection(-32, 0);
  61.         } else if (c == mapRightCommand) {
  62.             map.panDirection(32, 0);
  63.         }
  64.  
  65.     }
  66. }