Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's some code that should get you going on the correct path. I've taken it from a project of mine that had some special requirements, so there could be some remnants of that left in there inadvertently. There will be some undefined variables in there -- they're member variables that are declared in the class and should all start with an underscore. This is also part of a class that extends <code>MapField</code>, so you would have to create a custom map class and then use that rather than the default.</p> <pre class="lang-java prettyprint-override"><code>protected boolean touchEvent(TouchEvent message) { boolean ret = super.touchEvent(message); //mark that we're starting to interact if(message.getEvent() == TouchEvent.DOWN) { _startTouchTracking = true; _clicking = true; _touchX = message.getX(1); _touchY = message.getY(1); } //user is wanting to move the map else if(message.getEvent() == TouchEvent.MOVE) { int dx = _touchX - message.getX(1); int dy = _touchY - message.getY(1); _clicking = false; _touchX = message.getX(1); _touchY = message.getY(1); //perform checks to make sure we don't move outside of the map's range int lat = getLatitude() - dy*(int)MathUtilities.pow(2, (double)getZoom()); if(lat &lt; -9000000) { lat = -9000000; } else if (lat &gt; 9000000) { lat = 9000000; } int lon = getLongitude() + dx*(int)MathUtilities.pow(2, (double)getZoom()); if(lon &lt; -18000000) { lon = -18000000; } else if (lon &gt; 18000000) { lon = 18000000; } moveTo(lat, lon); } //if the person just touches and releases, we want to move to that spot else if (message.getEvent() == TouchEvent.UNCLICK &amp;&amp; _clicking) { int dx = message.getX(1) - getWidth()/2; int dy = message.getY(1) - getHeight()/2; move(dx, dy); _clicking = false; } //touch has been released else if (message.getEvent() == TouchEvent.UP) { _startTouchTracking = false; } //we handled the click return true; } </code></pre> <p>As said, this might need tweaking for your use, but in general should get you started. The <code>MathUtilities.pow()</code> calls were my way of coming up with an appropriate amount of motion depending on the zoom level.</p> <p><strong>Edit for Comments</strong></p> <p>Letting a Bitmap move with the map:</p> <pre class="lang-java prettyprint-override"><code>protected Coordinates _bitmapCoordinates; protected Bitmap _bitmap; public YourMapField() { //we're going to put the bitmap at -38.43, 20.32 _bitmapCoordinates = new Coordinates(-38.43, 20.32, 0.0); _bitmap = YOUR_CODE_TO_GET_THE_BITMAP; } protected void paint(Graphics g) { super.paint(g); XYPoint placeToPaintBitmap = new XYPoint(); convertWorldToField(_bitmapCoordinates, placeToPaintBitmap); //perform a check here to make sure that field will be seen. This code would depend //on how you're painting the image. Just check the placeToPaintBitmap.x and placeToPaintBitmap.y //against 0 and the map's width and height, along with some adjustment for how you paint if(bitmap will be visible on the screen) { //The code I have here is drawing the bitmap from the top left of the image, but if //you need to draw from some other place you may have to offset the x and y g.drawBitmap(placeToPaintBitmap.x, placeToPaintBitmap.y, _bitmap.getWidth(), _bitmap.getHeight(), 0, 0); } } </code></pre> <p>I didn't test any of that code, so it might be buggy but should give you the general idea.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload