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

jerry 2015年11月26日 收藏

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

package com.pstreets.gisengine.demo.lwuit;

//--------------------------------- IMPORTS ------------------------------------
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.raster.MapType;

import com.pstreets.gisengine.demo.MapDemoLWUIT;
import com.sun.lwuit.Command;
import com.sun.lwuit.events.ActionEvent;
public class MapPanLWUIT extends MapDemoLWUIT{

    private Command mapUpCommand;
    private Command mapDownCommand;
    private Command mapLeftCommand;
    private Command mapRightCommand;

    public void startApp() {
        init();

        mapUpCommand=new Command("Up"){
            public void actionPerformed(ActionEvent evt) {
                map.panDirection(0, -32);
            }
        };

        mapDownCommand=new Command("Down"){
            public void actionPerformed(ActionEvent evt) {
                map.panDirection(0, 32);
            }
        };

        mapLeftCommand=new Command("Left"){
            public void actionPerformed(ActionEvent evt) {
                map.panDirection(-32, 0);

            }
        };

        mapRightCommand=new Command("Right"){
            public void actionPerformed(ActionEvent evt) {
                map.panDirection(32, 0);
            }
        };

        canvas.addCommand(mapUpCommand);
        canvas.addCommand(mapDownCommand);
        canvas.addCommand(mapLeftCommand);
        canvas.addCommand(mapRightCommand);
        GeoLatLng center =  new GeoLatLng(32.0616667, 118.7777778);
        map.setCenter(center, 13, MapType.MICROSOFTCHINA);

        canvas.show();
    }
  
}