Created
January 30, 2014 18:38
-
-
Save nutiteq/8715686 to your computer and use it in GitHub Desktop.
Draw circle in Nutiteq SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// create layer and add a circle to it | |
GeometryLayer locationLayer = new GeometryLayer(mapView.getLayers().getBaseProjection()); | |
mapView.getComponents().layers.addLayer(locationLayer); | |
circle(-122.416667f, 37.766667f, 100, locationLayer); | |
} | |
// helper to draw a circle to given layer | |
private void circle(float lat, float lon, float circleRadius, GeometryLayer layer){ | |
// number of circle line points | |
int NR_OF_CIRCLE_VERTS = 18; | |
List<MapPos> circleVerts = new ArrayList<MapPos>(NR_OF_CIRCLE_VERTS); | |
MapPos circlePos = layer.getProjection().fromWgs84(lat, lon); | |
// width of map to scale circle | |
float projectionScale = (float) layer.getProjection().getBounds().getWidth(); | |
// convert radius from meters to map units | |
float circleScale = circleRadius / 7500000f * projectionScale; | |
for (float tsj = 0; tsj <= 360; tsj += 360 / NR_OF_CIRCLE_VERTS) { | |
MapPos mapPos = new MapPos(circleScale * Math.cos(tsj * Const.DEG_TO_RAD) + circlePos.x, circleScale * Math.sin(tsj * Const.DEG_TO_RAD) + circlePos.y); | |
circleVerts.add(mapPos); | |
} | |
LineStyle style = LineStyle.builder().setWidth(0.1f).setColor(Color.argb(192, 255, 255, 0)).build(); | |
Line circle = new Line(circleVerts, null, style, null); | |
layer.add(circle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function works on given latitudes only, there is "magic number" 7500000f in the calculations. Please use better one, which is independent from latitude: https://gist.github.com/jaakla/bd26bb02109f17e8135c