Search in sources :

Example 1 with KmlLayer

use of com.google.maps.android.data.kml.KmlLayer in project android-maps-utils by googlemaps.

the class KmlDemoActivity method retrieveFileFromResource.

private void retrieveFileFromResource() {
    try {
        KmlLayer kmlLayer = new KmlLayer(mMap, R.raw.campus, getApplicationContext());
        kmlLayer.addLayerToMap();
        moveCameraToKml(kmlLayer);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    }
}
Also used : KmlLayer(com.google.maps.android.data.kml.KmlLayer) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 2 with KmlLayer

use of com.google.maps.android.data.kml.KmlLayer in project android-maps-utils by googlemaps.

the class MultiLayerDemoActivity method startDemo.

@Override
protected void startDemo(boolean isRestore) {
    if (!isRestore) {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.403186, -0.126446), 10));
    }
    // Shared object managers - used to support multiple layer types on the map simultaneously
    MarkerManager markerManager = new MarkerManager(getMap());
    GroundOverlayManager groundOverlayManager = new GroundOverlayManager(getMap());
    PolygonManager polygonManager = new PolygonManager(getMap());
    PolylineManager polylineManager = new PolylineManager(getMap());
    // Add clustering
    ClusterManager<MyItem> clusterManager = new ClusterManager<>(this, getMap(), markerManager);
    getMap().setOnCameraIdleListener(clusterManager);
    addClusterItems(clusterManager);
    // Add GeoJSON from resource
    try {
        // GeoJSON polyline
        GeoJsonLayer geoJsonLineLayer = new GeoJsonLayer(getMap(), R.raw.south_london_line_geojson, this, markerManager, polygonManager, polylineManager, groundOverlayManager);
        // Make the line red
        GeoJsonLineStringStyle geoJsonLineStringStyle = new GeoJsonLineStringStyle();
        geoJsonLineStringStyle.setColor(Color.RED);
        for (GeoJsonFeature f : geoJsonLineLayer.getFeatures()) {
            f.setLineStringStyle(geoJsonLineStringStyle);
        }
        geoJsonLineLayer.addLayerToMap();
        geoJsonLineLayer.setOnFeatureClickListener((GeoJsonLayer.GeoJsonOnFeatureClickListener) feature -> Toast.makeText(MultiLayerDemoActivity.this, "GeoJSON polyline clicked: " + feature.getProperty("title"), Toast.LENGTH_SHORT).show());
        // GeoJSON polygon
        GeoJsonLayer geoJsonPolygonLayer = new GeoJsonLayer(getMap(), R.raw.south_london_square_geojson, this, markerManager, polygonManager, polylineManager, groundOverlayManager);
        // Fill it with red
        GeoJsonPolygonStyle geoJsonPolygonStyle = new GeoJsonPolygonStyle();
        geoJsonPolygonStyle.setFillColor(Color.RED);
        for (GeoJsonFeature f : geoJsonPolygonLayer.getFeatures()) {
            f.setPolygonStyle(geoJsonPolygonStyle);
        }
        geoJsonPolygonLayer.addLayerToMap();
        geoJsonPolygonLayer.setOnFeatureClickListener((GeoJsonLayer.GeoJsonOnFeatureClickListener) feature -> Toast.makeText(MultiLayerDemoActivity.this, "GeoJSON polygon clicked: " + feature.getProperty("title"), Toast.LENGTH_SHORT).show());
    } catch (IOException e) {
        Log.e(TAG, "GeoJSON file could not be read");
    } catch (JSONException e) {
        Log.e(TAG, "GeoJSON file could not be converted to a JSONObject");
    }
    // Add KMLs from resources
    try {
        // KML Polyline
        KmlLayer kmlPolylineLayer = new KmlLayer(getMap(), R.raw.south_london_line_kml, this, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
        kmlPolylineLayer.addLayerToMap();
        kmlPolylineLayer.setOnFeatureClickListener(feature -> Toast.makeText(MultiLayerDemoActivity.this, "KML polyline clicked: " + feature.getProperty("name"), Toast.LENGTH_SHORT).show());
        // KML Polygon
        KmlLayer kmlPolygonLayer = new KmlLayer(getMap(), R.raw.south_london_square_kml, this, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
        kmlPolygonLayer.addLayerToMap();
        kmlPolygonLayer.setOnFeatureClickListener(feature -> Toast.makeText(MultiLayerDemoActivity.this, "KML polygon clicked: " + feature.getProperty("name"), Toast.LENGTH_SHORT).show());
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Unclustered marker - instead of adding to the map directly, use the MarkerManager
    MarkerManager.Collection markerCollection = markerManager.newCollection();
    markerCollection.addMarker(new MarkerOptions().position(new LatLng(51.150000, -0.150032)).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)).title("Unclustered marker"));
    markerCollection.setOnMarkerClickListener(marker -> {
        Toast.makeText(MultiLayerDemoActivity.this, "Marker clicked: " + marker.getTitle(), Toast.LENGTH_SHORT).show();
        return false;
    });
}
Also used : GeoJsonFeature(com.google.maps.android.data.geojson.GeoJsonFeature) KmlLayer(com.google.maps.android.data.kml.KmlLayer) BitmapDescriptorFactory(com.google.android.libraries.maps.model.BitmapDescriptorFactory) MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) LatLng(com.google.android.libraries.maps.model.LatLng) IOException(java.io.IOException) ClusterManager(com.google.maps.android.clustering.ClusterManager) PolylineManager(com.google.maps.android.collections.PolylineManager) Color(android.graphics.Color) GeoJsonFeature(com.google.maps.android.data.geojson.GeoJsonFeature) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) MarkerManager(com.google.maps.android.collections.MarkerManager) JSONException(org.json.JSONException) List(java.util.List) Toast(android.widget.Toast) CameraUpdateFactory(com.google.android.libraries.maps.CameraUpdateFactory) GeoJsonLayer(com.google.maps.android.data.geojson.GeoJsonLayer) MyItem(com.google.maps.android.utils.demo.model.MyItem) GeoJsonPolygonStyle(com.google.maps.android.data.geojson.GeoJsonPolygonStyle) GroundOverlayManager(com.google.maps.android.collections.GroundOverlayManager) GeoJsonLineStringStyle(com.google.maps.android.data.geojson.GeoJsonLineStringStyle) Log(android.util.Log) PolygonManager(com.google.maps.android.collections.PolygonManager) InputStream(java.io.InputStream) KmlLayer(com.google.maps.android.data.kml.KmlLayer) GeoJsonLineStringStyle(com.google.maps.android.data.geojson.GeoJsonLineStringStyle) GroundOverlayManager(com.google.maps.android.collections.GroundOverlayManager) MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) GeoJsonPolygonStyle(com.google.maps.android.data.geojson.GeoJsonPolygonStyle) JSONException(org.json.JSONException) IOException(java.io.IOException) MyItem(com.google.maps.android.utils.demo.model.MyItem) GeoJsonLayer(com.google.maps.android.data.geojson.GeoJsonLayer) PolygonManager(com.google.maps.android.collections.PolygonManager) PolylineManager(com.google.maps.android.collections.PolylineManager) MarkerManager(com.google.maps.android.collections.MarkerManager) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) LatLng(com.google.android.libraries.maps.model.LatLng) ClusterManager(com.google.maps.android.clustering.ClusterManager)

Aggregations

KmlLayer (com.google.maps.android.data.kml.KmlLayer)2 IOException (java.io.IOException)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 Color (android.graphics.Color)1 Log (android.util.Log)1 Toast (android.widget.Toast)1 CameraUpdateFactory (com.google.android.libraries.maps.CameraUpdateFactory)1 BitmapDescriptorFactory (com.google.android.libraries.maps.model.BitmapDescriptorFactory)1 LatLng (com.google.android.libraries.maps.model.LatLng)1 MarkerOptions (com.google.android.libraries.maps.model.MarkerOptions)1 ClusterManager (com.google.maps.android.clustering.ClusterManager)1 GroundOverlayManager (com.google.maps.android.collections.GroundOverlayManager)1 MarkerManager (com.google.maps.android.collections.MarkerManager)1 PolygonManager (com.google.maps.android.collections.PolygonManager)1 PolylineManager (com.google.maps.android.collections.PolylineManager)1 GeoJsonFeature (com.google.maps.android.data.geojson.GeoJsonFeature)1 GeoJsonLayer (com.google.maps.android.data.geojson.GeoJsonLayer)1 GeoJsonLineStringStyle (com.google.maps.android.data.geojson.GeoJsonLineStringStyle)1 GeoJsonPolygonStyle (com.google.maps.android.data.geojson.GeoJsonPolygonStyle)1 MyItem (com.google.maps.android.utils.demo.model.MyItem)1