opensciencemap / vtm

a vector-tile map library written in java - running on android, desktop and within the browser
GNU Lesser General Public License v3.0
238 stars 176 forks source link

create custom shapes on map #105

Open stleusc opened 10 years ago

stleusc commented 10 years ago

How can I create something similar to this:

// Instantiates a new CircleOptions object and defines the center and radius
CircleOptions circleOptions = new CircleOptions()
    .center(new LatLng(37.4, -122.1))
    .radius(1000)); // In meters

// Get back the mutable Circle
Circle circle = myMap.addCircle(circleOptions);

Above code is Google Maps API V2. I did not find and easy way to create a layer that can draw circles with a radius given in meters/miles/feet around lat/lon

Any help???

Guti commented 10 years ago

maybe this can help you

https://github.com/opensciencemap/vtm-app/blob/master/src/org/oscim/app/location/LocationOverlay.java

stleusc commented 10 years ago

Well that code would/could render one (1) circle and not many. Basically I want a circle around each visible marker in an ItemizedLayer. Also, I'm not an OpenGL expert (actually, no clue about OpenGL) so I don't know how to extend from one circle to many. Maybe there is an easy way to add a circle around each visible Item in ItemizedLayer?

Guti commented 9 years ago
        GeoPoint position = new GeoPoint(40.689248,-74.044499);

        double distanceKm = 0.500;

        int lineWidth = 4;

        int lineColor = Color.parseColor("#990F98D0");

        // Radius
        PathLayer circleLayer = new PathLayer(mMap, lineColor, lineWidth);

        List<GeoPoint> pts = new ArrayList<GeoPoint>();
        for(int i=0; i<360; i++){
            pts.add(destinationPoint(position, i, distanceKm));
        }
        circleLayer.setPoints(pts);

        mMap.layers().add(circleLayer);
public GeoPoint destinationPoint(GeoPoint latlon, double brng, double distanceKm) {

    final double dist = distanceKm / 6371;
    final double bearingRad = Math.toRadians(brng);

    double lat1 = Math.toRadians(latlon.getLatitude());
    double lon1 = Math.toRadians(latlon.getLongitude());

    final double lat2 =
            Math.asin(
                    Math.sin(lat1) * Math.cos(dist) +
                            Math.cos(lat1) * Math.sin(dist) * Math.cos(bearingRad));
    double lon2 =
            lon1 +
                    Math.atan2(
                            Math.sin(bearingRad) * Math.sin(dist) * Math.cos(lat1),
                            Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2));
    lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI; 

    return new GeoPoint(Math.toDegrees(lat2), Math.toDegrees(lon2));
}
Guti commented 9 years ago

Get circle in meters:

    public List<GeoPoint> addCircle(GeoPoint latlon, double distance) {

        List<GeoPoint> pts = new ArrayList<GeoPoint>();
        for(int i=0; i<360; i++){
            pts.add(destinationPoint(latlon, i, distance/1000));
        }
        return pts;
    }