RasterMap 有两个方法可以用于平移地图,panTo 将地图移动到指定经纬度坐标,panDirection(dx,dy) 将地图从当前位置平移dx,dy 个象素。
下列示例可以上,下,左,右平移地图。
package com.pstreets.gisengine.demo.midp;
//--------------------------------- IMPORTS ------------------------------------
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.raster.MapType;
import com.pstreets.gisengine.demo.MapDemoMIDP;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
//[------------------------------ MAIN CLASS ----------------------------------]
//--------------------------------- REVISIONS ----------------------------------
// Date Name Tracking # Description
// -------- ------------------- ------------- --------------------------
// 28JAN2011 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////////
/**
* map pan demo for Guidebee Map API on MIDP platform.
*/
public class MapPanMIDP extends MapDemoMIDP implements CommandListener {
private Command mapUpCommand = new Command("Up", Command.OK, 1);
private Command mapDownCommand = new Command("Down", Command.ITEM, 1);
private Command mapLeftCommand = new Command("Left", Command.ITEM, 1);
private Command mapRightCommand = new Command("Right", Command.ITEM, 1);
public void startApp() {
init();
canvas.addCommand(mapUpCommand);
canvas.addCommand(mapDownCommand);
canvas.addCommand(mapLeftCommand);
canvas.addCommand(mapRightCommand);
canvas.setCommandListener(this);
GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);
map.setCenter(center, 13, MapType.MICROSOFTCHINA);
Display.getDisplay(this).setCurrent(canvas);
}
public void commandAction(Command c, Displayable d) {
if (c == mapUpCommand) {
map.panDirection(0, -32);
} else if (c == mapDownCommand) {
map.panDirection(0, 32);
} else if (c == mapLeftCommand) {
map.panDirection(-32, 0);
} else if (c == mapRightCommand) {
map.panDirection(32, 0);
}
}
}

本文介绍了一个使用RasterMap API在MIDP平台上实现地图平移的示例。通过定义四个命令,用户可以轻松地控制地图向上、向下、向左或向右平移。此示例展示了如何利用panDirection方法来改变地图的显示位置。
3205

被折叠的 条评论
为什么被折叠?



