use of com.google.android.gms.maps.model.LatLngBounds in project android-maps-utils by googlemaps.
the class GeoJsonParser method parseFeature.
/**
* Parses a single GeoJSON feature which contains a geometry and properties member both of
* which can be null. Also parses the bounding box and id members of the feature if they exist.
*
* @param geoJsonFeature feature to parse
* @return GeoJsonFeature object
*/
private static GeoJsonFeature parseFeature(JSONObject geoJsonFeature) {
String id = null;
LatLngBounds boundingBox = null;
Geometry geometry = null;
HashMap<String, String> properties = new HashMap<String, String>();
try {
if (geoJsonFeature.has(FEATURE_ID)) {
id = geoJsonFeature.getString(FEATURE_ID);
}
if (geoJsonFeature.has(BOUNDING_BOX)) {
boundingBox = parseBoundingBox(geoJsonFeature.getJSONArray(BOUNDING_BOX));
}
if (geoJsonFeature.has(FEATURE_GEOMETRY) && !geoJsonFeature.isNull(FEATURE_GEOMETRY)) {
geometry = parseGeometry(geoJsonFeature.getJSONObject(FEATURE_GEOMETRY));
}
if (geoJsonFeature.has(PROPERTIES) && !geoJsonFeature.isNull(PROPERTIES)) {
properties = parseProperties(geoJsonFeature.getJSONObject("properties"));
}
} catch (JSONException e) {
Log.w(LOG_TAG, "Feature could not be successfully parsed " + geoJsonFeature.toString());
return null;
}
return new GeoJsonFeature(geometry, id, properties, boundingBox);
}
use of com.google.android.gms.maps.model.LatLngBounds in project android-maps-utils by googlemaps.
the class KmlFeatureParser method createLatLngBounds.
/**
* Given a set of four latLng coordinates, creates a LatLng Bound
*
* @param north North coordinate of the bounding box
* @param south South coordinate of the bounding box
* @param east East coordinate of the bounding box
* @param west West coordinate of the bounding box
*/
private static LatLngBounds createLatLngBounds(Double north, Double south, Double east, Double west) {
LatLng southWest = new LatLng(south, west);
LatLng northEast = new LatLng(north, east);
return new LatLngBounds(southWest, northEast);
}
use of com.google.android.gms.maps.model.LatLngBounds in project android-maps-utils by googlemaps.
the class KmlFeatureParser method createGroundOverlay.
/**
* Creates a new GroundOverlay object (created if a GroundOverlay tag is read by the
* XmlPullParser) and assigns specific elements read from the parser to the GroundOverlay
*/
/* package */
static KmlGroundOverlay createGroundOverlay(XmlPullParser parser) throws IOException, XmlPullParserException {
float drawOrder = 0.0f;
float rotation = 0.0f;
int visibility = 1;
String imageUrl = null;
LatLngBounds latLonBox;
HashMap<String, String> properties = new HashMap<String, String>();
HashMap<String, Double> compassPoints = new HashMap<String, Double>();
int eventType = parser.getEventType();
while (!(eventType == END_TAG && parser.getName().equals("GroundOverlay"))) {
if (eventType == START_TAG) {
if (parser.getName().equals("Icon")) {
imageUrl = getImageUrl(parser);
} else if (parser.getName().equals("drawOrder")) {
drawOrder = Float.parseFloat(parser.nextText());
} else if (parser.getName().equals("visibility")) {
visibility = Integer.parseInt(parser.nextText());
} else if (parser.getName().equals("ExtendedData")) {
properties.putAll(setExtendedDataProperties(parser));
} else if (parser.getName().equals("rotation")) {
rotation = getRotation(parser);
} else if (parser.getName().matches(PROPERTY_REGEX) || parser.getName().equals("color")) {
properties.put(parser.getName(), parser.nextText());
} else if (parser.getName().matches(COMPASS_REGEX)) {
compassPoints.put(parser.getName(), Double.parseDouble(parser.nextText()));
}
}
eventType = parser.next();
}
latLonBox = createLatLngBounds(compassPoints.get("north"), compassPoints.get("south"), compassPoints.get("east"), compassPoints.get("west"));
return new KmlGroundOverlay(imageUrl, latLonBox, drawOrder, visibility, properties, rotation);
}
use of com.google.android.gms.maps.model.LatLngBounds in project android-maps-utils by googlemaps.
the class GeoJsonFeatureTest method testGetBoundingBox.
@Test
public void testGetBoundingBox() {
GeoJsonFeature feature = new GeoJsonFeature(null, null, null, null);
assertNull(feature.getBoundingBox());
LatLngBounds boundingBox = new LatLngBounds(new LatLng(-20, -20), new LatLng(50, 50));
feature = new GeoJsonFeature(null, null, null, boundingBox);
assertEquals(boundingBox, feature.getBoundingBox());
}
use of com.google.android.gms.maps.model.LatLngBounds in project collect by opendatakit.
the class GoogleMapFragment method expandBounds.
private LatLngBounds expandBounds(LatLngBounds bounds, double factor) {
double north = bounds.northeast.latitude;
double south = bounds.southwest.latitude;
double latCenter = (north + south) / 2;
double latRadius = ((north - south) / 2) * factor;
north = Math.min(90, latCenter + latRadius);
south = Math.max(-90, latCenter - latRadius);
double east = bounds.northeast.longitude;
double west = bounds.southwest.longitude;
while (east < west) {
east += 360;
}
double lonCenter = (east + west) / 2;
double lonRadius = Math.min(180 - 1e-6, ((east - west) / 2) * factor);
east = lonCenter + lonRadius;
west = lonCenter - lonRadius;
return new LatLngBounds(new LatLng(south, west), new LatLng(north, east));
}
Aggregations