public SpatialiteTextLayer(
     Projection projection,
     CustomSpatialiteLayer layer,
     String[] userColumns,
     StyleSet<TextStyle> styleSet) {
   super(projection);
   this.spatialiteLayer = layer;
   this.userColumns = userColumns;
   this.styleSet = styleSet;
   if (styleSet != null) {
     this.minZoom = styleSet.getFirstNonNullZoomStyleZoom();
   }
 }
  /**
   * Vector datasource connector, based on general query
   *
   * @param proj layer projection. NB! data must be in the same projection
   * @param pointStyleSet styleset for point objects
   * @param lineStyleSet styleset for line objects
   * @param polygonStyleSet styleset for polygon objects
   * @throws IOException file not found or other problem opening OGR datasource
   */
  public OnlineVectorLayer(
      Projection proj,
      StyleSet<PointStyle> pointStyleSet,
      StyleSet<LineStyle> lineStyleSet,
      StyleSet<PolygonStyle> polygonStyleSet,
      int maxObjects) {
    super(proj);
    this.pointStyleSet = pointStyleSet;
    this.lineStyleSet = lineStyleSet;
    this.polygonStyleSet = polygonStyleSet;
    this.maxObjects = maxObjects;

    if (pointStyleSet != null) {
      minZoom = Math.min(minZoom, pointStyleSet.getFirstNonNullZoomStyleZoom());
    }
    if (lineStyleSet != null) {
      minZoom = Math.min(minZoom, lineStyleSet.getFirstNonNullZoomStyleZoom());
    }
    if (polygonStyleSet != null) {
      minZoom = Math.min(minZoom, polygonStyleSet.getFirstNonNullZoomStyleZoom());
    }
    Log.debug("OnlineVectorLayer minZoom = " + minZoom);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // spinner in status bar, for progress indication
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.main);

    // enable logging for troubleshooting - optional
    Log.enableAll();
    Log.setTag("nml3d");

    // 1. Get the MapView from the Layout xml - mandatory
    mapView = (MapView) findViewById(R.id.mapView);

    // Optional, but very useful: restore map state during device rotation,
    // it is saved in onRetainNonConfigurationInstance() below
    Components retainObject = (Components) getLastNonConfigurationInstance();
    if (retainObject != null) {
      // just restore configuration, skip other initializations
      mapView.setComponents(retainObject);
      mapView.startMapping();
      return;
    } else {
      // 2. create and set MapView components - mandatory
      Components components = new Components();
      // set stereo view: works if you rotate to landscape and device has HTC 3D or LG Real3D
      mapView.setComponents(components);
    }

    // 3. Define map layer for basemap - mandatory.

    TMSMapLayer mapLayer =
        new TMSMapLayer(
            new EPSG3857(), 5, 18, 0, "http://otile1.mqcdn.com/tiles/1.0.0/osm/", "/", ".png");
    mapView.getLayers().setBaseLayer(mapLayer);

    // define style for 3D to define minimum zoom = 14
    ModelStyle modelStyle = ModelStyle.builder().build();
    StyleSet<ModelStyle> modelStyleSet = new StyleSet<ModelStyle>(null);
    modelStyleSet.setZoomStyle(14, modelStyle);

    // ** 3D Model layer
    try {
      Bundle b = getIntent().getExtras();
      String mapFile = b.getString("selectedFile");

      NMLModelDbLayer modelLayer = new NMLModelDbLayer(new EPSG3857(), mapFile, modelStyleSet);
      modelLayer.setMemoryLimit(20 * 1024 * 1024);
      mapView.getLayers().addLayer(modelLayer);

      // set initial map view camera from database
      Envelope extent = modelLayer.getDataExtent();

      DisplayMetrics metrics = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(metrics);
      int screenHeight = metrics.heightPixels;
      int screenWidth = metrics.widthPixels;

      double zoom =
          Math.log(
                  (screenWidth * (Math.PI * 6378137.0f * 2.0f))
                      / ((extent.maxX - extent.minX) * 256.0))
              / Math.log(2);

      MapPos centerPoint =
          new MapPos((extent.maxX + extent.minX) / 2, (extent.maxY + extent.minY) / 2);
      Log.debug("found extent " + extent + ", zoom " + zoom + ", centerPoint " + centerPoint);

      mapView.setZoom((float) zoom);
      mapView.setFocusPoint(centerPoint);

    } catch (IOException e) {
      e.printStackTrace();
      return;
    }

    // rotation - 0 = north-up
    mapView.setRotation(0f);
    // tilt means perspective view. Default is 90 degrees for "normal" 2D map view, minimum allowed
    // is 30 degrees.
    mapView.setTilt(90.0f);

    // Activate some mapview options to make it smoother - optional
    mapView.getOptions().setPreloading(false);
    mapView.getOptions().setSeamlessHorizontalPan(true);
    mapView.getOptions().setTileFading(false);
    mapView.getOptions().setKineticPanning(true);
    mapView.getOptions().setDoubleClickZoomIn(true);
    mapView.getOptions().setDualClickZoomOut(true);

    // set sky bitmap - optional, default - white
    mapView.getOptions().setSkyDrawMode(Options.DRAW_BITMAP);
    mapView.getOptions().setSkyOffset(4.86f);
    mapView
        .getOptions()
        .setSkyBitmap(UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.sky_small));

    // Map background, visible if no map tiles loaded - optional, default - white
    mapView.getOptions().setBackgroundPlaneDrawMode(Options.DRAW_BITMAP);
    mapView
        .getOptions()
        .setBackgroundPlaneBitmap(
            UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.background_plane));
    mapView.getOptions().setClearColor(Color.WHITE);

    // configure texture caching - optional, suggested
    mapView.getOptions().setTextureMemoryCacheSize(20 * 1024 * 1024);
    mapView.getOptions().setCompressedMemoryCacheSize(8 * 1024 * 1024);

    // define online map persistent caching - optional, suggested. Default - no caching
    mapView.getOptions().setPersistentCachePath(this.getDatabasePath("mapcache").getPath());
    // set persistent raster cache limit to 100MB
    mapView.getOptions().setPersistentCacheSize(100 * 1024 * 1024);

    // 4. Start the map - mandatory
    mapView.startMapping();

    // 5. zoom buttons using Android widgets - optional
    // get the zoomcontrols that was defined in main.xml
    ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
    // set zoomcontrols listeners to enable zooming
    zoomControls.setOnZoomInClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            mapView.zoomIn();
          }
        });
    zoomControls.setOnZoomOutClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            mapView.zoomOut();
          }
        });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    // enable logging for troubleshooting - optional
    Log.enableAll();
    Log.setTag("online3d");

    // 1. Get the MapView from the Layout xml - mandatory
    mapView = (MapView) findViewById(R.id.mapView);

    // Optional, but very useful: restore map state during device rotation,
    // it is saved in onRetainNonConfigurationInstance() below
    Components retainObject = (Components) getLastNonConfigurationInstance();
    if (retainObject != null) {
      // just restore configuration, skip other initializations
      mapView.setComponents(retainObject);
      mapView.startMapping();
      return;
    } else {
      // 2. create and set MapView components - mandatory
      Components components = new Components();
      // set stereo view: works if you rotate to landscape and device has HTC 3D or LG Real3D
      mapView.setComponents(components);
    }

    // 3. Define map layer for basemap - mandatory.

    TMSMapLayer mapLayer =
        new TMSMapLayer(
            new EPSG3857(), 0, 18, 2, "http://otile1.mqcdn.com/tiles/1.0.0/osm/", "/", ".png");
    mapView.getLayers().setBaseLayer(mapLayer);

    // define style for 3D to define minimum zoom = 14
    ModelStyle modelStyle = ModelStyle.builder().build();
    StyleSet<ModelStyle> modelStyleSet = new StyleSet<ModelStyle>(null);
    modelStyleSet.setZoomStyle(14, modelStyle);

    // ** Online 3D Model layer

    NMLModelOnlineLayer modelLayer =
        new NMLModelOnlineLayer(
            new EPSG3857(),
            "http://aws-lb.nutiteq.ee/nml/nmlserver2.php?data=demo&",
            modelStyleSet);

    modelLayer.setMemoryLimit(20 * 1024 * 1024);

    modelLayer.setPersistentCacheSize(30 * 1024 * 1024);
    modelLayer.setPersistentCachePath(this.getDatabasePath("nmlcache").getPath());

    modelLayer.setLODResolutionFactor(0.3f);
    getMapView().getLayers().addLayer(modelLayer);

    // Tallinn
    mapView.setFocusPoint(new MapPos(2753845.7830863246f, 8275045.674995658f));

    // San Francisco
    // mapView.setFocusPoint(mapView.getLayers().getBaseLayer().getProjection().fromWgs84(-122.41666666667f, 37.76666666666f));

    mapView.setZoom(17.0f);

    // rotation - 0 = north-up
    mapView.setRotation(-96.140175f);
    // tilt means perspective view. Default is 90 degrees for "normal" 2D map view, minimum allowed
    // is 30 degrees.
    mapView.setTilt(30.0f);

    // Activate some mapview options to make it smoother - optional
    mapView.getOptions().setPreloading(false);
    mapView.getOptions().setSeamlessHorizontalPan(true);
    mapView.getOptions().setTileFading(false);
    mapView.getOptions().setKineticPanning(true);
    mapView.getOptions().setDoubleClickZoomIn(true);
    mapView.getOptions().setDualClickZoomOut(true);

    // set sky bitmap - optional, default - white
    mapView.getOptions().setSkyDrawMode(Options.DRAW_BITMAP);
    mapView.getOptions().setSkyOffset(4.86f);
    mapView
        .getOptions()
        .setSkyBitmap(UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.sky_small));

    // Map background, visible if no map tiles loaded - optional, default - white
    mapView.getOptions().setBackgroundPlaneDrawMode(Options.DRAW_BITMAP);
    mapView
        .getOptions()
        .setBackgroundPlaneBitmap(
            UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.background_plane));
    mapView.getOptions().setClearColor(Color.WHITE);

    // configure texture caching - optional, suggested
    mapView.getOptions().setTextureMemoryCacheSize(20 * 1024 * 1024);
    mapView.getOptions().setCompressedMemoryCacheSize(8 * 1024 * 1024);

    // define online map persistent caching - optional, suggested. Default - no caching
    mapView.getOptions().setPersistentCachePath(this.getDatabasePath("mapcache").getPath());
    // set persistent raster cache limit to 100MB
    mapView.getOptions().setPersistentCacheSize(100 * 1024 * 1024);

    // 4. Start the map - mandatory
    mapView.startMapping();

    // 5. zoom buttons using Android widgets - optional
    // get the zoomcontrols that was defined in main.xml
    ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
    // set zoomcontrols listeners to enable zooming
    zoomControls.setOnZoomInClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            mapView.zoomIn();
          }
        });
    zoomControls.setOnZoomOutClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            mapView.zoomOut();
          }
        });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    // enable logging for troubleshooting - optional
    Log.enableAll();
    Log.setTag("cartodb");

    // 1. Get the MapView from the Layout xml - mandatory
    mapView = (MapView) findViewById(R.id.mapView);

    // Optional, but very useful: restore map state during device rotation,
    // it is saved in onRetainNonConfigurationInstance() below
    Components retainObject = (Components) getLastNonConfigurationInstance();
    if (retainObject != null) {
      // just restore configuration, skip other initializations
      mapView.setComponents(retainObject);
      mapView.startMapping();
      return;
    } else {
      // 2. create and set MapView components - mandatory
      Components components = new Components();
      // set stereo view: works if you rotate to landscape and device has HTC 3D or LG Real3D
      mapView.setComponents(components);
    }

    // 3. Define map layer for basemap - mandatory.
    TMSMapLayer mapLayer =
        new TMSMapLayer(
            new EPSG3857(),
            0,
            18,
            3,
            //				"http://nutiteq.cartodb.com/tiles/tm_world_borders/", "/", ".png");
            "http://otile1.mqcdn.com/tiles/1.0.0/osm/",
            "/",
            ".png");

    mapView.getLayers().setBaseLayer(mapLayer);

    // set initial map view camera - optional. "World view" is default
    // Location: Estonia
    // mapView.setFocusPoint(mapView.getLayers().getBaseLayer().getProjection().fromWgs84(24.5f,
    // 58.3f));
    mapView.setFocusPoint(new MapPos(2745202.3f, 8269676.0f));
    // rotation - 0 = north-up
    mapView.setRotation(0f);
    // zoom - 0 = world, like on most web maps
    mapView.setZoom(9.0f);
    // tilt means perspective view. Default is 90 degrees for "normal" 2D map view, minimum allowed
    // is 30 degrees.
    mapView.setTilt(90.0f);

    // Activate some mapview options to make it smoother - optional
    mapView.getOptions().setPreloading(false);
    mapView.getOptions().setSeamlessHorizontalPan(true);
    mapView.getOptions().setTileFading(false);
    mapView.getOptions().setKineticPanning(true);
    mapView.getOptions().setDoubleClickZoomIn(true);
    mapView.getOptions().setDualClickZoomOut(true);

    // set sky bitmap - optional, default - white
    mapView.getOptions().setSkyDrawMode(Options.DRAW_BITMAP);
    mapView.getOptions().setSkyOffset(4.86f);
    mapView
        .getOptions()
        .setSkyBitmap(UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.sky_small));

    // Map background, visible if no map tiles loaded - optional, default - white
    mapView.getOptions().setBackgroundPlaneDrawMode(Options.DRAW_BITMAP);
    mapView
        .getOptions()
        .setBackgroundPlaneBitmap(
            UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.background_plane));
    mapView.getOptions().setClearColor(Color.WHITE);

    // configure texture caching - optional, suggested
    mapView.getOptions().setTextureMemoryCacheSize(20 * 1024 * 1024);
    mapView.getOptions().setCompressedMemoryCacheSize(8 * 1024 * 1024);

    // define online map persistent caching - optional, suggested. Default - no caching
    mapView.getOptions().setPersistentCachePath(this.getDatabasePath("mapcache").getPath());
    // set persistent raster cache limit to 100MB
    mapView.getOptions().setPersistentCacheSize(100 * 1024 * 1024);

    // 4. zoom buttons using Android widgets - optional
    // get the zoomcontrols that was defined in main.xml
    ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
    // set zoomcontrols listeners to enable zooming
    zoomControls.setOnZoomInClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            mapView.zoomIn();
          }
        });
    zoomControls.setOnZoomOutClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            mapView.zoomOut();
          }
        });

    // 5. Add CartoDB vector layer to map

    //  5.1 Define styles for all possible geometry types

    int minZoom = 5;
    int color = Color.BLUE;

    StyleSet<PointStyle> pointStyleSet = new StyleSet<PointStyle>();
    Bitmap pointMarker = UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.point);
    PointStyle pointStyle =
        PointStyle.builder()
            .setBitmap(pointMarker)
            .setSize(0.05f)
            .setColor(color)
            .setPickingSize(0.2f)
            .build();
    pointStyleSet.setZoomStyle(minZoom, pointStyle);

    StyleSet<LineStyle> lineStyleSet = new StyleSet<LineStyle>();
    LineStyle lineStyle = LineStyle.builder().setWidth(0.04f).setColor(Color.WHITE).build();
    lineStyleSet.setZoomStyle(minZoom, lineStyle);

    PolygonStyle polygonStyle =
        PolygonStyle.builder().setColor(0xFFFF6600 & 0x80FFFFFF).setLineStyle(lineStyle).build();
    StyleSet<PolygonStyle> polygonStyleSet = new StyleSet<PolygonStyle>(null);
    polygonStyleSet.setZoomStyle(minZoom, polygonStyle);

    StyleSet<LineStyle> roadLineStyleSet =
        new StyleSet<LineStyle>(LineStyle.builder().setWidth(0.07f).setColor(0xFFAAAAAA).build());

    //  5.2 Define layer and add to map

    String account = "nutiteq";
    String table = "tm_world_borders"; // kihelkonnad_1897, maakond_20120701
    String columns =
        "name,iso2,pop2005,area,"
            + CartoDbVectorLayer.TAG_WEBMERCATOR; // NB! always include the_geom_webmercator
    int limit = 5000; // max number of objects
    String sql =
        "SELECT "
            + columns
            + " FROM "
            + table
            + " WHERE "
            + CartoDbVectorLayer.TAG_WEBMERCATOR
            + " && ST_SetSRID('BOX3D(!bbox!)'::box3d, 3857) LIMIT "
            + limit;

    //      String sql2 = "SELECT name, type, oneway, osm_id, the_geom_webmercator FROM osm_roads
    // WHERE type in ('trunk','primary') AND the_geom_webmercator &&
    // ST_SetSRID('BOX3D(!bbox!)'::box3d, 3857) LIMIT 500";
    //      String sql2 = "SELECT name, type, oneway, osm_id, the_geom_webmercator FROM osm_roads
    // WHERE the_geom_webmercator && ST_SetSRID('BOX3D(!bbox!)'::box3d, 3857) LIMIT 500";
    CartoDbVectorLayer cartoLayerTrunk =
        new CartoDbVectorLayer(
            mapView.getLayers().getBaseLayer().getProjection(),
            account,
            sql,
            pointStyleSet,
            lineStyleSet,
            polygonStyleSet);
    mapView.getLayers().addLayer(cartoLayerTrunk);

    //		CartoDbVectorLayer cartoLayer = new
    // CartoDbVectorLayer(mapView.getLayers().getBaseLayer().getProjection(), account, sql,
    // pointStyleSet, lineStyleSet, polygonStyleSet);

    //      OnlineVectorLayer vectorLayer = new
    // OnlineVectorLayer(mapView.getLayers().getBaseLayer().getProjection(), pointStyleSet,
    // lineStyleSet, polygonStyleSet,2000);
    //		mapView.getLayers().addLayer(vectorLayer);
  }