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();
}
}
本文介绍了一个使用RasterMap API实现地图平移的Java示例。通过四个方向按钮,可以轻松地向上、下、左、右平移地图。示例代码展示了如何利用panDirection方法实现地图的像素级平移。
637

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



