gt:                     if (layer.isValid() && layer instanceof ILayerView) {
context: /*
   * Project:  NextGIS Mobile
   * Purpose:  Mobile GIS for Android.
   * Author:   Dmitry Baryshnikov (aka Bishop), bishop.dev@gmail.com
   * Author:   NikitaFeodonit, nfeodonit@yandex.com
   * Author:   Stanislav Petriakov, becomeglory@gmail.com
   * *****************************************************************************
   * Copyright (c) 2012-2015. NextGIS, info@nextgis.com
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Lesser Public License for more details.
   *
   * You should have received a copy of the GNU Lesser Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  
  package com.nextgis.maplib.map;
  
  import android.content.Context;
  import android.database.sqlite.SQLiteDatabase;
  import android.text.TextUtils;
  import android.util.Log;
  import com.nextgis.maplib.api.ILayer;
  import com.nextgis.maplib.api.ILayerView;
  import com.nextgis.maplib.api.IRenderer;
  import com.nextgis.maplib.datasource.GeoEnvelope;
  import com.nextgis.maplib.datasource.GeoPoint;
  import com.nextgis.maplib.display.GISDisplay;
  import com.nextgis.maplib.util.Constants;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.io.File;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  import java.util.Random;
  
  import static com.nextgis.maplib.util.Constants.*;
  
  
  public class LayerGroup
          extends Layer
  {
      protected final List<ILayer> mLayers = new ArrayList<>();
      protected LayerFactory mLayerFactory;
      protected int          mLayerDrawIndex;
      protected GISDisplay   mDisplay;
      protected OnAllLayersAddedListener mOnAllLayersAddedListener;
  
  
      public interface OnAllLayersAddedListener
      {
          void onAllLayersAdded(List<ILayer> layers);
      }
  
  
      public LayerGroup(
              Context context,
              File path,
              LayerFactory layerFactory)
      {
          super(context, path);
  
          mLayerFactory = layerFactory;
  
          mLayerDrawIndex = 0;
  
          mLayerType = LAYERTYPE_GROUP;
      }
  
  
      /**
       * Get layer by identificator
       *
       * @param id
       *         Layer identificator
       *
       * @return Layer or null
       */
      public ILayer getLayerById(int id)
      {
          if (mId == id) {
              return this;
          }
  
          for (ILayer layer : mLayers) {
              if (layer.getId() == id) {
                  return layer;
              }
          }
          return null;
      }
  
  
      /**
       * search layer by it human readabler name
       * @param name Name to search
       * @return ILayer or null
       */
      public ILayer getLayerByName(String name)
      {
          if (mName.equals(name)) {
              return this;
          }
  
          for (ILayer layer : mLayers) {
              if (layer.getName().equals(name)) {
                  return layer;
              }
          }
          return null;
      }
  
      /**
       * Search layer by it folder name
       * @param name Name to search
       * @return ILayer or null
       */
      public ILayer getLayerByPathName(String name){
          if (getPath().getName().equals(name)) {
              return this;
          }
  
          for (ILayer layer : mLayers) {
              if (layer.getPath().getName().equals(name)) {
                  return layer;
              }
          }
          return null;
      }
  
  
      /**
       * Get a list of specified type layers
       *
       * @param layerGroup
       *         to inspect for layers
       * @param types
       *         A layer type
       * @param layerList
       *         A list to fill with find layers
       */
      public static void getLayersByType(
              LayerGroup layerGroup,
              int types,
              List<ILayer> layerList)
      {
          for (int i = 0; i < layerGroup.getLayerCount(); i++) {
              ILayer layer = layerGroup.getLayer(i);
  
              if (0 != (types & layer.getType())) {
                  layerList.add(layer);
              }
  
              if (layer instanceof LayerGroup) {
                  getLayersByType((LayerGroup) layer, types, layerList);
              }
          }
      }
  
  
      public static void getVectorLayersByType(
              LayerGroup layerGroup,
              int types,
              List<ILayer> layerList)
      {
          for (int i = 0; i < layerGroup.getLayerCount(); i++) {
              ILayer layer = layerGroup.getLayer(i);
  
              if (layer instanceof VectorLayer) {
                  VectorLayer vectorLayer = (VectorLayer) layer;
                  if (0 != (types & 1 << vectorLayer.getGeometryType())) {
                      layerList.add(0, layer);
                  }
              }
  
              if (layer instanceof LayerGroup) {
                  getVectorLayersByType((LayerGroup) layer, types, layerList);
              }
          }
      }
  
  
      /**
       * Create existed layer from path and add it to the map
       *
       * @param layer
       *         A layer object
       */
      public void addLayer(ILayer layer)
      {
          if (layer != null) {
              mLayers.add(layer);
              layer.setParent(this);
              onLayerAdded(layer);
          }
      }
  
  
      public void insertLayer(
              int index,
              ILayer layer)
      {
          if (layer != null) {
  
              mLayers.add(index, layer);
              layer.setParent(this);
              onLayerAdded(layer);
          }
      }
  
  
      public void moveLayer(
              int newPosition,
              ILayer layer)
      {
          if (layer != null) {
  
              synchronized (this) {
                  mLayers.remove(layer);
                  mLayers.add(newPosition, layer);
              }
              onLayersReordered();
          }
      }
  
  
      public int removeLayer(ILayer layer)
      {
          synchronized (this) {
              int result = mLayers.size() - 1;
  
              if (layer != null) {
                  result = mLayers.indexOf(layer);
                  onLayerDeleted(layer.getId());
              }
              return result;
          }
      }
  
  
      @Override
      public void runDraw(GISDisplay display)
      {
          if (null != display && mDisplay != display) {
              mDisplay = display;
          }
  
          if (mLayers.size() == 0) {
              return;
          }
  
          //synchronized (this) {
              for (ILayer layer : mLayers) {
                  if (Thread.currentThread().isInterrupted()) {
                      break;
                  }
  
                  if (layer instanceof LayerGroup) {
                      LayerGroup layerGroup = (LayerGroup) layer;
                      layerGroup.runDraw(mDisplay);
  
                  } else {
  
  