map.getScreenPosition does not work as expected with unfolding maps

Hi. The following is the code:

// Import Unfolding Maps
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.core.*;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.events.*;
import de.fhpotsdam.unfolding.geo.*;
import de.fhpotsdam.unfolding.interactions.*;
import de.fhpotsdam.unfolding.mapdisplay.*;
import de.fhpotsdam.unfolding.mapdisplay.shaders.*;
import de.fhpotsdam.unfolding.marker.*;
import de.fhpotsdam.unfolding.providers.*;
import de.fhpotsdam.unfolding.texture.*;
import de.fhpotsdam.unfolding.tiles.*;
import de.fhpotsdam.unfolding.ui.*;
import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.utils.*;

// Import some Java utilities
import java.util.Date;
import java.text.SimpleDateFormat;
UnfoldingMap map;

Location center = new Location(63, 20);
Integer zoom_start = 9;

void setup() {
 size(1000, 1000, P3D);
 smooth();
 map = new UnfoldingMap(this);
MapUtils.createDefaultEventDispatcher(this, map);
map.zoomAndPanTo(zoom_start, center);
}

void draw(){

map.draw();
fill(0,20);
rect(0,0,width,height);

Location loc = new Location(67,17);
ScreenPosition screenPos = map.getScreenPosition(loc);
println(screenPos);
}

When I run it, the screenposition I got is like (-687.0, -2279.0); it is outside of the screen area. I was wondering, is there anyway to improve this?

1 Like

I don‘t see your problem… it works exactly how it should… it converts a location to a position on your screen. Try using a value very close to your Center Location and you‘ll see that it will return a value between 0, 0 and 1000, 1000 (the extent of your screen).

Is there anyway to adjust the screen coordinate to accommodate the specific screen position then?

I‘m not sure what you mean by that? What do you intend to do exactly?

I’d like to do an animation of markers on the screen. Now, the markers even do not show up, because the left upper corner is (0,0) in the coordinate system and the marker I intended to draw has position (-687.0, -2279.0). So I might need to try it out by updating the latitude and longitude of the center of the map and also the size of the map. I was wondering, is there any other way around instead of trying out. Thank you for your reply.

You can just move the map so that -600, -2200 is the Center. That should solve your problem… i think.

2 Likes

Not fully sure I understand what you are trying to achieve. But you could start by simply zooming out, either interactively, or use a zoom_start of e.g. 3 so the location of 67,17 is within the visible map area.

If you want to ensure the locations are on the visible map area, you could also create a Marker with that location and then use map.zoomAndPanToFit(myMarker) or, if multiple markers, map.zoomAndPanToFitMarkers(myMarkersList).

2 Likes