您需要做的就是扩展AnalyticSurface
和实现Movable
,然后您可以使用BasicDragger
而不是编写自己的选择侦听器。
public class DraggableAnalyticSurface extends AnalyticSurface implements Movable {
@Override
public Position getReferencePosition() {
return this.referencePos;
}
@Override
public void move(Position position) {
// not needed by BasicDragger
}
@Override
public void moveTo(Position position) {
final double latDelta = this.referencePos.getLatitude().degrees
- position.getLatitude().degrees;
final double lonDelta = this.referencePos.getLongitude().degrees
- position.getLongitude().degrees;
final double newMinLat = this.sector.getMinLatitude().degrees - latDelta;
final double newMinLon = this.sector.getMinLongitude().degrees - lonDelta;
final double newMaxLat = this.sector.getMaxLatitude().degrees - latDelta;
final double newMaxLon = this.sector.getMaxLongitude().degrees - lonDelta;
this.setSector(Sector.fromDegrees(newMinLat, newMaxLat, newMinLon, newMaxLon));
}
}