tillnagel / unfolding

A library to create interactive maps and geovisualizations in Processing and Java
http://unfoldingmaps.org
Other
477 stars 245 forks source link

getScreenPosition of a path made by SimpleLinesMarker #157

Closed Dazzid closed 6 years ago

Dazzid commented 6 years ago

Hi, I'm just trying to have the pixels coordinates of a path that was build by SimpleLinesMarker m = new SimpleLinesMarker(lineFeature.getLocations()). I'm using something like this:

    List<Marker> myMarker;
    myMarker = map.getMarkerManager(0).getMarkers();
    for (int i = 0; i < myMarker.size(); i++) {
      println(map.getScreenPosition(myMarker.get(i).getLocation()));
    }

But it is not the correct way to do so, it gives back far away pixel coordinates among many [0,0] return: [ 0.0, 0.0, 0.0 ] [ -8063.0, 195758.0, 0.0 ] [ 0.0, 0.0, 0.0 ] [ -10058.0, 247856.0, 0.0 ] [ 0.0, 0.0, 0.0 ] ...

tillnagel commented 6 years ago

Can you specify which Processing and Unfolding versions you are using? Also, which renderer do you use? (the one specified in size())

Dazzid commented 6 years ago

Hey Till, It is Processing 3.3.6 with Unfolding 0.9.9. And P2D

tillnagel commented 6 years ago

If you want to get the screen positions for all locations of a line marker you need to access the actual locations, like so:

    List<Marker> myMarkers = map.getMarkerManager(0).getMarkers();
    for (int i = 0; i < myMarkers.size(); i++) {
        SimpleLinesMarker myMarker = (SimpleLinesMarker) myMarkers.get(i);
        for (int j = 0; j < myMarker.getLocations().size(); j++) {
            println(map.getScreenPosition(myMarker.getLocation(j)));
        }
    }

The marker.getLocation() does return the centroid for all shape markers. This might be a bug for the SimpleLineMarker. Let me know if this centroid is what you are interested in.

(NB: In the above code snippet it is expected that all markers from the markerManager are SimpleLinesMarker. In an actual program you would need to cast more carefully.)

tillnagel commented 6 years ago

For getting the correct centroid, you can use this as a work-around:

    Location centroid = GeoUtils.getEuclideanCentroid(lineMarker.getLocations());
    ScreenPosition pos = map.getScreenPosition(centroid);
Dazzid commented 6 years ago

Now it make sense. Thanks!

tillnagel commented 6 years ago

Which was it you needed? Centroid? Or all locations?