Skip to content

Commit

Permalink
For #100 - updated radius calculation with formula taken from mailing…
Browse files Browse the repository at this point in the history
… list
  • Loading branch information
vitalidze committed Mar 28, 2015
1 parent b51fc4b commit 55f4ed3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/org/traccar/web/client/view/GeoFenceRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public void removeGeoFence(GeoFence geoFence) {

private void drawCircle(GeoFence circle, boolean drawTitle) {
GeoFence.LonLat center = circle.points().get(0);
float radius = circle.getRadius() * 1.78143299863f;
Polygon circleShape = Polygon.createRegularPolygon(mapView.createPoint(center.lon, center.lat), radius, 100, 0f);
Polygon circleShape = Polygon.createRegularPolygon(mapView.createPoint(center.lon, center.lat), applyMercatorScale(center.lat, circle.getRadius()), 100, 0f);

Style st = new Style();
st.setFillOpacity(0.3);
Expand Down Expand Up @@ -122,7 +121,7 @@ private void drawLine(GeoFence line, boolean drawTitle) {

LineString lineString = new LineString(linePoints);
VectorFeature lineFeature = new VectorFeature(lineString);
lineFeature.getAttributes().setAttribute("widthInMeters", line.getRadius() * 1.78143299863f);
lineFeature.getAttributes().setAttribute("widthInMeters", applyMercatorScale(lonLats.get(0).lat, line.getRadius()));
lineFeature.getAttributes().setAttribute("lineColor", '#' + line.getColor());

getVectorLayer().addFeature(lineFeature);
Expand All @@ -133,6 +132,16 @@ private void drawLine(GeoFence line, boolean drawTitle) {
}
}

/**
* Applies scale to specified radius in meters so it is precisely drawn on map
*
* @see <a href="http://osdir.com/ml/openlayers-users-gis/2012-09/msg00034.html">http://osdir.com/ml/openlayers-users-gis/2012-09/msg00034.html</a>
* @see <a href="http://osdir.com/ml/openlayers-users-gis/2012-09/msg00036.html">http://osdir.com/ml/openlayers-users-gis/2012-09/msg00036.html</a>
*/
private float applyMercatorScale(double latitude, float radius) {
return (float) (radius / Math.cos(latitude * Math.PI / 180));
}

private VectorFeature drawName(String name, Point point) {
org.gwtopenmaps.openlayers.client.Style st = new org.gwtopenmaps.openlayers.client.Style();
st.setLabel(name);
Expand Down

0 comments on commit 55f4ed3

Please sign in to comment.