2013-06-13 6 views
6

में मैंने अपने एंड्रॉइड एप्लिकेशन में ओपन स्ट्रीट मैप्स शामिल किए हैं। मानचित्रदृश्य में, मानचित्र पूरी तरह से लोड होने के बाद उपयोगकर्ता स्क्रीन को कैप्चर करने में सक्षम होना चाहिए। लेकिन नक्शादृश्य अभी भी लोड होने पर भी उपयोगकर्ता छवि को कैप्चर कर सकता है। क्या कोई मुझे बता सकता है कि नक्शादृश्य पूरी तरह से लोड होने पर कैसे पता लगाया जाए?पता लगाएं कि ओएसएम मैप्यूव अभी भी लोड हो रहा है या नहीं, एंड्रॉइड

public class MainActivity extends Activity { 
    MapView mapView; 
    MyLocationOverlay myLocationOverlay = null; 
    ArrayList<OverlayItem> anotherOverlayItemArray; 
    protected ItemizedOverlayWithBubble<ExtendedOverlayItem> itineraryMarkers; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mapView = (MapView) findViewById(R.id.mapview); 

     final ArrayList<ExtendedOverlayItem> waypointsItems = new ArrayList<ExtendedOverlayItem>(); 
     itineraryMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, waypointsItems, mapView, new ViaPointInfoWindow(R.layout.itinerary_bubble, mapView)); 
     mapView.getOverlays().add(itineraryMarkers); 

     mapView.setTileSource(TileSourceFactory.MAPNIK); 
     mapView.setBuiltInZoomControls(true); 
     MapController mapController = mapView.getController(); 
     mapController.setZoom(1); 
     GeoPoint point2 = new GeoPoint(51496994, -134733); 
     mapController.setCenter(point2); 

     Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on); 
     GeoPoint myPoint1 = new GeoPoint(0*1000000, 0*1000000); 
     ExtendedOverlayItem overlayItem = new ExtendedOverlayItem("Title Test Loc", "Desc", myPoint1, this); 
     overlayItem.setMarkerHotspot(OverlayItem.HotspotPlace.BOTTOM_CENTER); 
     overlayItem.setMarker(marker); 
     overlayItem.setRelatedObject(0); 
     itineraryMarkers.addItem(overlayItem); 
     mapView.invalidate(); 



     myLocationOverlay = new MyLocationOverlay(this, mapView); 
     mapView.getOverlays().add(myLocationOverlay); 
     myLocationOverlay.enableMyLocation(); 

     myLocationOverlay.runOnFirstFix(new Runnable() { 
      public void run() { 
      mapView.getController().animateTo(myLocationOverlay.getMyLocation()); 
       } 
      }); 


    } 

    @Override 
    protected void onResume() { 
     // TODO Auto-generated method stub 
     super.onResume(); 
     myLocationOverlay.enableMyLocation(); 
     myLocationOverlay.enableCompass(); 
     myLocationOverlay.enableFollowLocation(); 
    } 

    @Override 
    protected void onPause() { 
     // TODO Auto-generated method stub 
     super.onPause(); 
     myLocationOverlay.disableMyLocation(); 
     myLocationOverlay.disableCompass(); 
     myLocationOverlay.disableFollowLocation(); 
    } 

उत्तर

1

मैं TilesOverlay बढ़ा कर एक वर्ग नाम "MyTileOverlay" बनाया है और वह इस वर्ग contins: जब MapView की स्थापना तब

https://code.google.com/p/osmdroid/source/browse/trunk/osmdroid-android/src/main/java/org/osmdroid/views/overlay/TilesOverlay.java?r=1086

, मैं यह कर:

this.mTilesOverlay = new MyTileOverlay(mProvider, this.getBaseContext()); 

निर्देश दिए के रूप में kurtzmarc द्वारा, मैंने यह जांचने के लिए हैंडलटाइल() का उपयोग किया है कि सभी टाइल्स लोड हो रहे हैं या नहीं:

@Override 
     public void handleTile(final Canvas pCanvas, final int pTileSizePx, 
       final MapTile pTile, final int pX, final int pY) { 
      Drawable currentMapTile = mTileProvider.getMapTile(pTile); 
      if (currentMapTile == null) { 
       currentMapTile = getLoadingTile(); 
       Log.d("Tile Null", "Null"); 
      } else { 

       Log.d("Tile Not Null", "Not Null"); 
      } 

      if (currentMapTile != null) { 
       mTileRect.set(pX * pTileSizePx, pY * pTileSizePx, pX 
         * pTileSizePx + pTileSizePx, pY * pTileSizePx 
         + pTileSizePx); 
       onTileReadyToDraw(pCanvas, currentMapTile, mTileRect); 
      } 

      if (DEBUGMODE) { 
       mTileRect.set(pX * pTileSizePx, pY * pTileSizePx, pX 
         * pTileSizePx + pTileSizePx, pY * pTileSizePx 
         + pTileSizePx); 
       mTileRect.offset(-mWorldSize_2, -mWorldSize_2); 
       pCanvas.drawText(pTile.toString(), mTileRect.left + 1, 
         mTileRect.top + mDebugPaint.getTextSize(), 
         mDebugPaint); 
       pCanvas.drawLine(mTileRect.left, mTileRect.top, 
         mTileRect.right, mTileRect.top, mDebugPaint); 
       pCanvas.drawLine(mTileRect.left, mTileRect.top, 
         mTileRect.left, mTileRect.bottom, mDebugPaint); 
      } 
     } 

इस विधि सुनिश्चित करता है लोडिंग प्रक्रिया या अंतिम रूप दे दिया गया है या नहीं नहीं:

@Override 
      public void finaliseLoop() { 
       Log.d("Loop Finalized", "Finalized"); 
      } 

मैं भी इस विधि का उपयोग कर सकते हैं की पहचान करने के लिए सभी टाइल अपलोड कर दिया गया है या नहीं,:

public int getLoadingBackgroundColor() { 
      return mLoadingBackgroundColor; 
     } 

आशा इस मदद किसी को !

4

TilesOverlay पर एक नज़र और TileLooper कार्यान्वयन लें:

नीचे MapView लोड करने के लिए मेरे कोड है। यह हम लोड करने के लिए उपयोग करते हैं और फिर स्क्रीन पर प्रत्येक टाइल खींचते हैं। handleTile(...) में हम टाइल प्रदाता mTileProvider.getMapTile(pTile) से टाइल प्राप्त करने का प्रयास करते हैं। यदि वह Drawable देता है तो टाइल लोड हो जाती है, अगर नहीं तो यह null लौटाएगी।

यह करने के लिए एक आसान तरीका TilesOverlay का विस्तार, drawTiles(...) ओवरराइड और कॉल करने के लिए है अपने स्वयं के TileLoopersuper.drawTiles(...) है कि अगर सभी टाइल कि handleTile(...) के लिए पारित करने के रिक्त नहीं हैं देखने के लिए जाँच करेगा कॉल करने से पहले। अपने टाइल्स ओवरले कॉल mMapView.getOverlayManager().setTilesOverlay(myTilesOverlay) का उपयोग करने के लिए।

+0

बहुत बहुत धन्यवाद, क्या आप इसके लिए कुछ नमूना कोड प्रदान कर सकते हैं? – TharakaNirmana

+0

मैं इस तरह कोड का एक सेट आने के लिए सक्षम था: सार्वजनिक वर्ग टाइलें फैली TilesOverlay { \t सार्वजनिक टाइलें (MapTileProviderBase aTileProvider, प्रसंग aContext) { \t \t सुपर (aTileProvider, aContext); \t \t // TODO स्वत: निर्मित निर्माता \t} \t \t ठूंठ @Override \t सार्वजनिक शून्य drawTiles (कैनवास ग, पूर्णांक zoomLevel, पूर्णांक tileSizePx, रेक्ट व्यूपोर्ट) { \t \t // TODO स्वत: निर्मित विधि ठूंठ \t \t टाइललूपर टाइललोप; \t \t tileloop.handleTile (arg0, arg1, arg2, arg3, arg4) \t सुपर।drawTiles (सी, ज़ूमलेवल, टाइल साइजपीएक्स, व्यूपोर्ट); \t} } कृपया मुझे आगे बढ़ने के बारे में बताएं। धन्यवाद! – TharakaNirmana

संबंधित मुद्दे