Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions worldwind-examples/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
android:noHistory="true"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".MGRSGraticuleActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_mgrs_graticule"
android:launchMode="singleInstance"
android:noHistory="true"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".MultiGlobeActivity"
android:configChanges="orientation|screenSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ public boolean onNavigationItemSelected(MenuItem item) {
case R.id.nav_general_globe_activity:
startActivity(new Intent(getApplicationContext(), GeneralGlobeActivity.class));
break;
case R.id.nav_mgrs_graticule_activity:
startActivity(new Intent(getApplicationContext(), MGRSGraticuleActivity.class));
break;
case R.id.nav_multi_globe_activity:
startActivity(new Intent(getApplicationContext(), MultiGlobeActivity.class));
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gov.nasa.worldwindx;

import android.os.Bundle;

import gov.nasa.worldwind.layer.graticule.MGRSGraticuleLayer;

public class MGRSGraticuleActivity extends GeneralGlobeActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

this.wwd.getLayers().addLayer(new MGRSGraticuleLayer());
}

}
4 changes: 4 additions & 0 deletions worldwind-examples/src/main/res/menu/activity_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
android:id="@+id/nav_multi_globe_activity"
android:icon="@android:drawable/ic_menu_compass"
android:title="@string/title_multi_globe"/>
<item
android:id="@+id/nav_mgrs_graticule_activity"
android:icon="@android:drawable/ic_menu_compass"
android:title="@string/title_mgrs_graticule"/>
<item
android:id="@+id/nav_placemarks_demo_activity"
android:icon="@android:drawable/ic_menu_myplaces"
Expand Down
1 change: 1 addition & 0 deletions worldwind-examples/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string name="title_basic_stress_test">Basic Stress Test</string>
<string name="title_day_night_cycle">Day and Night Cycle</string>
<string name="title_general_globe">General Purpose Globe</string>
<string name="title_mgrs_graticule">MGRS graticule Demonstration</string>
<string name="title_multi_globe">Multi-Globe Demonstration</string>
<string name="title_movable_line_of_sight">Movable Line of Sight</string>
<string name="title_paths_example">Paths Example</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gov.nasa.worldwind.geom.coords;

public enum Hemisphere {
N, S
}
117 changes: 117 additions & 0 deletions worldwind/src/main/java/gov/nasa/worldwind/geom/coords/MGRSCoord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (C) 2011 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwind.geom.coords;

import android.support.annotation.NonNull;

/**
* This class holds an immutable MGRS coordinate string along with
* the corresponding latitude and longitude.
*
* @author Patrick Murris
* @version $Id$
*/

public class MGRSCoord {
private final String MGRSString;
private final double latitude;
private final double longitude;

/**
* Create a WGS84 MGRS coordinate from a pair of latitude and longitude <code>double</code>
* with the maximum precision of five digits (one meter).
*
* @param latitude the latitude <code>double</code>.
* @param longitude the longitude <code>double</code>.
* @return the corresponding <code>MGRSCoord</code>.
* @throws IllegalArgumentException if <code>latitude</code> or <code>longitude</code> is null,
* or the conversion to MGRS coordinates fails.
*/
public static MGRSCoord fromLatLon(double latitude, double longitude) {
return fromLatLon(latitude, longitude, 5);
}

/**
* Create a MGRS coordinate from a pair of latitude and longitude <code>double</code>
* with the given precision or number of digits (1 to 5).
*
* @param latitude the latitude <code>double</code>.
* @param longitude the longitude <code>double</code>.
* @param precision the number of digits used for easting and northing (1 to 5).
* @return the corresponding <code>MGRSCoord</code>.
* @throws IllegalArgumentException if <code>latitude</code> or <code>longitude</code> is null,
* or the conversion to MGRS coordinates fails.
*/
public static MGRSCoord fromLatLon(double latitude, double longitude, int precision) {
final MGRSCoordConverter converter = new MGRSCoordConverter();
long err = converter.convertGeodeticToMGRS(Math.toRadians(latitude), Math.toRadians(longitude), precision);

if (err != MGRSCoordConverter.MGRS_NO_ERROR) {
throw new IllegalArgumentException("MGRS Conversion Error");
}

return new MGRSCoord(latitude, longitude, converter.getMGRSString());
}

/**
* Create a MGRS coordinate from a standard MGRS coordinate text string.
* <p>
* The string will be converted to uppercase and stripped of all spaces before being evaluated.
* </p>
* <p>Valid examples:<br />
* 32TLP5626635418<br />
* 32 T LP 56266 35418<br />
* 11S KU 528 111<br />
* </p>
* @param MGRSString the MGRS coordinate text string.
* @return the corresponding <code>MGRSCoord</code>.
* @throws IllegalArgumentException if the <code>MGRSString</code> is null or empty,
* the <code>globe</code> is null, or the conversion to geodetic coordinates fails (invalid coordinate string).
*/
public static MGRSCoord fromString(String MGRSString) {
MGRSString = MGRSString.toUpperCase().replaceAll(" ", "");

final MGRSCoordConverter converter = new MGRSCoordConverter();
long err = converter.convertMGRSToGeodetic(MGRSString);

if (err != MGRSCoordConverter.MGRS_NO_ERROR) {
throw new IllegalArgumentException("MGRS Conversion Error");
}

return new MGRSCoord(Math.toDegrees(converter.getLatitude()), Math.toDegrees(converter.getLongitude()), MGRSString);
}

/**
* Create an arbitrary MGRS coordinate from a pair of latitude-longitude <code>double</code>
* and the corresponding MGRS coordinate string.
*
* @param latitude the latitude <code>double</code>.
* @param longitude the longitude <code>double</code>.
* @param MGRSString the corresponding MGRS coordinate string.
* @throws IllegalArgumentException if <code>latitude</code> or <code>longitude</code> is null,
* or the MGRSString is null or empty.
*/
public MGRSCoord(double latitude, double longitude, String MGRSString) {
this.latitude = latitude;
this.longitude = longitude;
this.MGRSString = MGRSString;
}

public double getLatitude() {
return this.latitude;
}

public double getLongitude() {
return this.longitude;
}

@NonNull
@Override
public String toString() {
return this.MGRSString;
}

}
Loading