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

jerry 2015年11月26日 收藏

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

  1. package com.pstreets.gisengine.demo.lwuit;
  2.  
  3. //--------------------------------- IMPORTS ------------------------------------
  4. import com.mapdigit.gis.geometry.GeoLatLng;
  5. import com.mapdigit.gis.raster.MapType;
  6.  
  7. import com.pstreets.gisengine.demo.MapDemoLWUIT;
  8. import com.sun.lwuit.Command;
  9. import com.sun.lwuit.events.ActionEvent;
  10. public class MapPanLWUIT extends MapDemoLWUIT{
  11.  
  12.     private Command mapUpCommand;
  13.     private Command mapDownCommand;
  14.     private Command mapLeftCommand;
  15.     private Command mapRightCommand;
  16.  
  17.     public void startApp() {
  18.         init();
  19.  
  20.         mapUpCommand=new Command("Up"){
  21.             public void actionPerformed(ActionEvent evt) {
  22.                 map.panDirection(0, -32);
  23.             }
  24.         };
  25.  
  26.         mapDownCommand=new Command("Down"){
  27.             public void actionPerformed(ActionEvent evt) {
  28.                 map.panDirection(0, 32);
  29.             }
  30.         };
  31.  
  32.         mapLeftCommand=new Command("Left"){
  33.             public void actionPerformed(ActionEvent evt) {
  34.                 map.panDirection(-32, 0);
  35.  
  36.             }
  37.         };
  38.  
  39.         mapRightCommand=new Command("Right"){
  40.             public void actionPerformed(ActionEvent evt) {
  41.                 map.panDirection(32, 0);
  42.             }
  43.         };
  44.  
  45.         canvas.addCommand(mapUpCommand);
  46.         canvas.addCommand(mapDownCommand);
  47.         canvas.addCommand(mapLeftCommand);
  48.         canvas.addCommand(mapRightCommand);
  49.         GeoLatLng center =  new GeoLatLng(32.0616667, 118.7777778);
  50.         map.setCenter(center, 13, MapType.MICROSOFTCHINA);
  51.  
  52.         canvas.show();
  53.     }
  54.   
  55. }