public void clear() {

    for (Polygon marker : _overlays) {
      marker.setVisible(false);
      _mapOverlayManager.removeOverlay(marker);
    }
    _overlays.clear();
  }
    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 createEnvironment(
      String name, int floors, Polygon outline, final List<ExtSensor> sensors) {

    // create GPS outline String
    String gpsOutline = "";
    for (int i = 0; i < outline.getVertexCount(); i++) {
      LatLng vertex = outline.getVertex(i);
      gpsOutline += vertex.toUrlValue() + ";";
    }
    gpsOutline = gpsOutline.substring(0, gpsOutline.length() - 1);

    // create GPS position String
    String position = outline.getBounds().getCenter().toUrlValue();

    // prepare request properties
    final Method method = RequestBuilder.POST;
    final UrlBuilder urlBuilder =
        new UrlBuilder()
            .setProtocol(CommonSenseClient.Urls.PROTOCOL)
            .setHost(CommonSenseClient.Urls.HOST);
    urlBuilder.setPath(Urls.PATH_ENVIRONMENTS + ".json");
    final String url = urlBuilder.buildString();
    final String sessionId = SessionManager.getSessionId();

    String body = "{\"environment\":{";
    body += "\"" + ExtEnvironment.NAME + "\":\"" + name + "\",";
    body += "\"" + ExtEnvironment.FLOORS + "\":" + floors + ",";
    body += "\"" + ExtEnvironment.OUTLINE + "\":\"" + gpsOutline + "\",";
    body += "\"" + ExtEnvironment.POSITION + "\":\"" + position + "\"}";
    body += "}";

    // prepare request callback
    RequestCallback reqCallback =
        new RequestCallback() {

          @Override
          public void onError(Request request, Throwable exception) {
            LOG.warning("POST environments onError callback: " + exception.getMessage());
            onCreateEnvironmentFailure();
          }

          @Override
          public void onResponseReceived(Request request, Response response) {
            LOG.finest("POST environments response received: " + response.getStatusText());
            int statusCode = response.getStatusCode();
            if (Response.SC_CREATED == statusCode) {
              onCreateEnvironmentSuccess(response.getText(), sensors);
            } else {
              LOG.warning("POST environments returned incorrect status: " + statusCode);
              onCreateEnvironmentFailure();
            }
          }
        };

    // send request
    try {
      RequestBuilder builder = new RequestBuilder(method, url);
      builder.setHeader("X-SESSION_ID", sessionId);
      builder.setHeader("Content-Type", "application/json");
      builder.sendRequest(body, reqCallback);
    } catch (Exception e) {
      LOG.warning("POST environments request threw exception: " + e.getMessage());
      reqCallback.onError(null, e);
    }
  }
 public void setVisible(boolean visible) {
   for (Polygon marker : _overlays) marker.setVisible(visible);
 }