private static LatLngBounds getSearchBoundsAsLatLngBounds(double radius) {

    CoordinateBounds bounds = getSearchBounds(radius);

    LatLngBounds b = LatLngBounds.newInstance();
    b.extend(LatLng.newInstance(bounds.getMinLat(), bounds.getMinLon()));
    b.extend(LatLng.newInstance(bounds.getMaxLat(), bounds.getMaxLon()));
    return b;
  }
    public void handleUpdate(TimedRegionModel model) {

      clear();

      double maxTime = model.getMaxTime();

      LatLngBounds bounds = LatLngBounds.newInstance();

      for (TimedRegion region : model.getRegions()) {

        String color = getColorForTime(region.getTime(), maxTime);

        LatLngBounds regionBounds = region.getBounds();
        PatchMarker marker = new PatchMarker(regionBounds);
        Style style = marker.getStyle();
        style.setProperty("backgroundColor", color);
        marker.addStyleName("patch");

        // _overlays.add(marker);
        _mapOverlayManager.addOverlay(marker, 10, 15);

        bounds.extend(regionBounds.getNorthEast());
        bounds.extend(regionBounds.getSouthWest());
      }

      if (!bounds.isEmpty()) {
        MapWidget map = _mapOverlayManager.getMapWidget();
        int zoom = map.getBoundsZoomLevel(bounds);
        map.setCenter(bounds.getCenter(), zoom);
      }
    }
    public void handleUpdate(TimedPolygonModel model) {

      clear();

      LatLngBounds bounds = LatLngBounds.newInstance();

      double maxTime = model.getMaxTime();

      for (TimedPolygon tp : model.getPolygons()) {

        Polygon poly = tp.getPolyline();

        String color = getColorForTime(tp.getTime(), maxTime);
        double opacity = getOpacityForTime(tp.getTime(), maxTime);

        poly.setFillStyle(PolyStyleOptions.newInstance(color, 1, opacity));
        poly.setStrokeStyle(PolyStyleOptions.newInstance(color, 1, opacity));

        _mapOverlayManager.addOverlay(poly);
        _overlays.add(poly);
        LatLngBounds b = poly.getBounds();
        bounds.extend(b.getNorthEast());
        bounds.extend(b.getSouthWest());
      }

      if (!bounds.isEmpty()) {
        MapWidget map = _mapOverlayManager.getMapWidget();
        if (model.isComplete()) {
          int zoom = map.getBoundsZoomLevel(bounds);
          map.setCenter(bounds.getCenter(), zoom);

          List<String> colors = new ArrayList<String>();
          for (int i = 0; i <= 6; i++) {
            double ratio = i / 6.0;
            colors.add(_colormap.getColor(ratio));
          }
          String fromLabel = "0 mins";
          String toLabel = model.getMaxTime() + " mins";
          _colorGradientControl.setGradient(colors, fromLabel, toLabel);
        } else {
          map.setCenter(_queryModel.getLocation());
        }
      }
    }
  private void tstLoadData() {
    // simple add and finish adding of new item
    map.clearOverlays();
    mapAddOverlayEvents.clear();
    mapRemoveOverlayEvents.clear();

    MapControllerT mc = new MapControllerT(map, service);
    randomData = new ArrayList<MapItem>();
    int iterator = 0;
    for (; iterator < 20; iterator++) {
      MapItem mi = RandomGenerator.genMapItem(false);
      mi.setId(iterator); // init ids
      randomData.add(mi);
    }

    service.setOnGetListener(
        new MockDataServiceAsync.OnGetListener() {
          @Override
          public void get(
              String className, String filters, boolean deep, AsyncCallback<List<?>> callback) {}

          @Override
          public void get(
              String className,
              double x1,
              double x2,
              double y1,
              double y2,
              boolean deep,
              AsyncCallback<List<?>> callback) {
            callback.onSuccess(randomData);
          }

          @Override
          public void get(String className, AsyncCallback<List<?>> callback) {}
        });

    // simulate map drag move
    LatLngBounds llb =
        LatLngBounds.newInstance(LatLng.newInstance(0, 0), LatLng.newInstance(80, 80));
    mc.loadIcons(12, llb); // just ensure about good zoom limit
    assertTrue(mc.calledOnLoad); // should becalled
    mc.calledOnLoad = false;
    assertEquals(randomData.size(), mc.mCurrentVisibleMapItems.size()); // this icons should be here
    assertEquals(randomData.size(), mapAddOverlayEvents.size());

    // call again, no new icon should be added into map
    mc.loadIcons(12, llb); //
    assertTrue(mc.calledOnLoad); // should becalled
    mc.calledOnLoad = false;
    assertEquals(randomData.size(), mc.mCurrentVisibleMapItems.size()); // this icons should be here
    assertEquals(randomData.size(), mapAddOverlayEvents.size());

    // add 10 new icons into database simulates different db result depending on latlngbounds
    for (; iterator < 30; iterator++) {
      MapItem mi = RandomGenerator.genMapItem(false);
      mi.setId(iterator); // init ids
      randomData.add(mi);
    }

    // call again, only 10 news icon should be added into map
    mc.loadIcons(12, llb); //
    assertTrue(mc.calledOnLoad); // should becalled
    mc.calledOnLoad = false;
    assertEquals(randomData.size(), mc.mCurrentVisibleMapItems.size()); // this icons should be here
    assertEquals(randomData.size(), mapAddOverlayEvents.size());

    for (int i = 0; i < iterator; i++) {
      long l = i;
      // check added data, should be same
      assertTrue(mc.mCurrentVisibleMapItems.containsKey(l));
      MapItemOverlay<MapItem> mi =
          (MapItemOverlay<MapItem>) mapAddOverlayEvents.get(i).getOverlay();
      DataComparator.assertEquals(randomData.get(i), mi.getMapItem(), true);
      DataComparator.assertEquals(randomData.get(i), mi.getMapItem(), true);
    }
  }