移植谷歌地图应用程序,以Osmdroid - 问题叠加 [英] Porting a Google Maps app to Osmdroid - problem with overlay

查看:157
本文介绍了移植谷歌地图应用程序,以Osmdroid - 问题叠加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为了使用OpenStreetMaps移植谷歌地图根据项目Osmdroid。该端口从加入我的覆盖它由若干直线和一些文字工作的行分开。在这两个项目中,我通过定时器线程的手段和处理程序调用redrawOverlay添加叠加。

I'm porting a Google Maps based project to Osmdroid in order to use OpenStreetMaps. The port is working OK apart from adding my overlay which consists of a number of straight lines and some text. In both projects I add the Overlay by means of a timer thread and handler calling redrawOverlay.

在OSM的项目我的叠加仅仅是一个灰色方块完全隐藏地图。如果我删除调用redrawOveraly的OSM瓦片显示确定。我已经减少了覆盖code到最低限度低于code样品在一个对角线的。它工作正常,在谷歌应用程序,覆盖了地图图块。该com.google.android.maps.Overlay有一个抽奖方式,OSM有一个OnDraw中,所以我在OSM版本:

In the OSM project my overlay is just a grey square completely hiding the map. If I remove the call to redrawOveraly, the OSM tiles are shown OK. I've reduced the overlay code to the bare minimum of a single diagonal line in the code samples below. It works fine in the Google app, overlaying the map tile. The com.google.android.maps.Overlay has a draw method, the OSM has an onDraw, so I have in the OSM version:

   private MapView mv;
   private MapOverlay mmapOverlay = null;

   private void redrawOverlay() {

   gPt = mv.getMapCenter();
   if (mmapOverlay == null)
      mmapOverlay = new MapOverlay(getApplicationContext());
      List<Overlay> listOfOverlays = mv.getOverlays();
      listOfOverlays.clear();
      listOfOverlays.add(mmapOverlay);
      mv.invalidate();
   }

   public class MapOverlay extends org.osmdroid.views.overlay.Overlay {

   public MapOverlay(Context ctx) {
      super(ctx);
      // TODO Auto-generated constructor stub
   }

      @Override
      public void onDraw(Canvas canvas, MapView mapView) {

      Paint lp3;
      lp3 = new Paint();
      lp3.setColor(Color.RED);
      lp3.setAntiAlias(true);
      lp3.setStyle(Style.STROKE);
      lp3.setStrokeWidth(1);
      lp3.setTextAlign(Paint.Align.LEFT);
      lp3.setTextSize(12);
      canvas.drawLine(10, 10, 150, 150, lp3);
   }

虽然在谷歌地图原来我有等价的:

Whilst in the Google maps original I have the equivalent :

  public class MapOverlay extends com.google.android.maps.Overlay {


   @Override
   public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
   long when) {
      super.draw(canvas, mapView, shadow);
      Paint lp3;
      lp3 = new Paint();
      .....etc.

redrawOverlay是除了覆盖的实例相同的只是:

redrawOverlay is the same except the instantiation of the overlay is just:

mmapOverlay = new MapOverlay();

所有的建议将受到欢迎。

All suggestions will be gratefully received

更新问题的kurtzmarc:

感谢您的帮助,到目前为止,我看你是Osmdroid的作者之一。我喜欢它做什么为止。我想晚饭preSS'跳转到并放大,你得到的双击。我想它什么也不做。我想这可能是打在你的源此位,做zoomInFixing:

Thanks for you help so far, I see that you are one of the authors of Osmdroid. I like what it's doing so far. I would like to suppress the 'jump to and zoom in' that you get on double tap. I'd like it to do nothing at all. I think it's probably hitting this bit in your source and doing the zoomInFixing:

private class MapViewDoubleClickListener implements GestureDetector.OnDoubleTapListener {
   @Override
   public boolean onDoubleTap(final MotionEvent e) {
   for (int i = mOverlays.size() - 1; i >= 0; i--)
      if (mOverlays.get(i).onDoubleTapUp(e, MapView.this))
         return true;

      final GeoPoint center = getProjection().fromPixels(e.getX(), e.getY());
      return zoomInFixing(center);
  }

这似乎并不认为我可以重写它。我使用的是3.0.1罐和相关的javadoc。我想知道如果的MapView的setTouchDelegate方法会有所帮助,但在Javadoc中没有提到它。你有什么建议吗?

It doesn't seem that I can override it. I'm using the 3.0.1 jar and the associated javadocs. I'm wondering if the Mapview's setTouchDelegate method would help, but there is no reference to it in the javadocs. Have you any suggestions please?

推荐答案

我不知道你在哪里调用redrawOverlay(),但如果你看看MinimapOverlay,你会看到一些被绘制在一个固定的例子位置在屏幕上。换句话说,你是画在屏幕地图坐标的坐标没有。

I'm not sure where you are calling redrawOverlay() from, but if you look at the MinimapOverlay you will see an example where something is drawn at a fixed location on the screen. In other words, you are drawing in screen coordinates not in map coordinates.

例如:

@Override
protected void onDraw(final Canvas pC, final MapView pOsmv) {
  // Calculate the half-world size
  final Rect viewportRect = new Rect();
  final Projection projection = pOsmv.getProjection();
  final int zoomLevel = projection.getZoomLevel();
  final int tileZoom = projection.getTileMapZoom();
  mWorldSize_2 = 1 << (zoomLevel + tileZoom - 1);

  // Find what's on the screen
  final BoundingBoxE6 boundingBox = projection.getBoundingBox();
  final Point upperLeft = org.osmdroid.views.util.Mercator
            .projectGeoPoint(boundingBox.getLatNorthE6(), boundingBox.getLonWestE6(),
            zoomLevel + tileZoom, null);
  final Point lowerRight = org.osmdroid.views.util.Mercator
     .projectGeoPoint(boundingBox.getLatSouthE6(), boundingBox.getLonEastE6(), zoomLevel
     + tileZoom, null);

  // Save the Mercator coordinates of what is on the screen
  viewportRect.set(upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y);

  // Offset into OSM coordinates
  viewportRect.offset(-mWorldSize_2, -mWorldSize_2);

  // Draw a line from one corner to the other
  canvas.drawLine(viewportRect.left, viewportRect.top, viewportRect.right, viewportRect.bottom);

从这里viewportRect重新presents左上方到屏幕的右下角。您可以使用此画​​在屏幕上的任何固定点。

From here viewportRect represents the upper left to the lower right of the screen. You can use this to draw at any fixed points on the screen.

更新:

要回答你的第二个问题 - 你需要做的是覆盖onDoubleTap在您的覆盖,并返回真。返回真指示给你消耗的事件,也没有进一步的处理应该发生的基类。看看小地图覆盖code的一个很好的例子:

To answer your second question - what you need to do is override onDoubleTap in your Overlay and return "true". Returning "true" indicates to the base class that you "consumed" the event and no further processing should take place. Take a look at the minimap overlay code for a good example:

<一个href="http://$c$c.google.com/p/osmdroid/source/browse/trunk/osmdroid-android/src/org/osmdroid/views/overlay/MinimapOverlay.java" rel="nofollow">http://$c$c.google.com/p/osmdroid/source/browse/trunk/osmdroid-android/src/org/osmdroid/views/overlay/MinimapOverlay.java

我们是正确的检修重叠的中间,所以其中一部分将被处理在不久的将来更好一点。例如,getOverlays()。明确的()的错误,你跑进也已在别处报道,我们已经从固定它。

We are right in the middle of overhauling the Overlays, so some of this will be handled a little better in the near future. For example, the getOverlays().clear() bug you ran into has also been reported elsewhere and we've since fixed it.

这篇关于移植谷歌地图应用程序,以Osmdroid - 问题叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆