Extract points from location on screen relative to center of screen which equals current location.

If the center of the screen was equal to your location, is it possible that tapping on the screen (or in the case of button watches perhaps using a set distance in projected location and the direction you are facing to select) on for example the top left part could result in extracting coords (say for a waypoint) and save them somewhere then set that waypoints location to the center of the screen thus allowing you to select multiple waypoints that then connect as a route?

Just wonderingnif that would be possible for non map devices.

Crude example:

 The birds eye map is just to give an idea of distance.

  • There are a few options. The easiest is the do nothing, draw it and let the watch deal with it. The watch will let you draw off the screen.

    When I draw my routes I find anything over 300 lines causes the watch to trip the timeout. You likely won't have this problem, but if you do you can use cohen sutherland (https://www.geeksforgeeks.org/line-clipping-set-1-cohen-sutherland-algorithm/) to filter out any lines which are entirely off screen. I have a monkey c version of this if you need it. As you move around you run the algorithm at intervals to check what's changed and filter those lines out. I keep a boolean array to say which I draw and which I don't 

    The middle ground is to say that anything more than, say 1000 pixels offscreen isn't relevant and you just don't draw those.

  • Wait so if I understand you correctly, doing nothing (my favourite option) when the watch is calculating things from lat and long back to screen coords, it can take a point very far away and (despite screen being say 240x240) draw it at say 500x500 offscreen? 

  • I got them to save! I could do with a bit of help in reversing the maths though, I imagine i’d have to do that in on update right so they can then be drawn? 

    dc.drawsomething(points, size of thing to draw)?

  • The display method is the reverse of the one you have for conversion to lat/long. Subtract the lat/long from your current lat long to find the difference and then multiply that by the number of pixels per degree. For example if the screen is 400 pixels wide and there's one degree of longitude on the screen, then the formula would be:

    var pixelsLong = (longMe - longPoint) * 400 / degreesPerPixel

    If the diff is 1/2 a degree and there was one degree on the screen, this is 0.5 * 400/1 = 200, which is 200 pixels to the left of your position, so the absolute position is 

    xDraw = pixelsMe - pixelsLong = 200 (me) - 200 (point) = 0, which is the left of the screen.

    Exactly the same for Lat, although you need to remember that Lat is positive UP and screen y is positive DOWN, so you need to invert the pixelsMe - pixelsLat to pixelsLat - pixelsMe so it's in the right direction.

    example(ish) code (untested):

    var screenWidthPixels = 200; //get this from the toybox screen size
    var screenHeightPixels=200; //get this from the toybox screen size
    
    var me = [screenWidthPixels/2,screenHeightPixels/2]; //your location (middle of screen)
    
    ....
    
    function transformCoordinate(lat, long){
    
      var pixelsLong = (longMe-long) * screenWidthDegrees / screenWidthPixels; //how many pixels away is the point
      var pixelsLat = (lat - latMe) * screenHeightDegrees / screenHeightPixels;
      
      var x = me[0]-pixelsLong;
      var y = me[1] - pixelsLat;
    
      return [x,y];
    
    }
    
    // points are [x1, y1, x2, y2, x3, y3...]
    
    function drawLine(dc, points){
    
       
       dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
       
       //iterate every two points
       for(var i =0; i < points.size(); i=i+2){
          var pointA = transformCoordinate(points[i], points[i+1]); //starts with x1, y1
          var pointB = transformCoordinate(points[i+2], points[i+3] /start with x2, y2
          dc.setPenWidth(8);
          dc.drawPoint(pointA[0],  pointA[1]); //draw the point at the start location
          dc.setPenWidth(3);
          dc.drawLine(pointA[0], pointA[1] ,  pointB[0], pointB[1]); // draw the line from PointA to pointB
       }
    
    }

    This could have some errors in but hopefully it gives you the idea. If you can't get it working, let me know and share what you have and I'll have a go at making it work.  The key thing is to work out the size of the screen in degrees from the zoom. If you only have one zoom this will obviously be a constant.

    Perhaps start by printing out the resulting lat/long and reverse screen coordinates as you click on the screen to check the numbers are in the right ballpark. You should be able to click on the screen, calculate the lat/long and then use transformCoordinate to convert back to pixels and end up with the same number (and the right place on the screen), 0,0 being the top left

  • That’s great thanks! One final question (maybe) is how I can extract the last saved lat lon to storage from the array and set it as my location. This is so in the course creation view the map adjusts it’s position so you can add destinations further away from your actual location.

  • If you don't want to use your current position, the last saved long/lat is at points[points.size()-2, points.size()-1].

    You then need to centre the map on the screen at that lat and long by working out how far that is in pixels from the top left of the large bitmap and then drawing that section centred on the screen. It's hard to advise exactly without seeing how it works.

  • The map already has the code to center it according to position as that came with the opensource code, all it needs is a position of some sort (in this case the lat and long).

  • Perfect,  then those coordinates are the ones you need