Esempio n. 1
0
  public void loadData(Envelope envelope, int zoom) {

    long timeStart = System.currentTimeMillis();

    // TODO: use fromInternal(Envelope) here
    MapPos minPos = projection.fromInternal(envelope.getMinX(), envelope.getMinY());
    MapPos maxPos = projection.fromInternal(envelope.getMaxX(), envelope.getMaxY());

    String sqlBbox = "" + minPos.x + "," + minPos.y + "," + maxPos.x + "," + maxPos.y;

    // load geometries
    List<Geometry> newVisibleElementsList = new LinkedList<Geometry>();

    try {
      Uri.Builder uri =
          Uri.parse("http://kaart.maakaart.ee/poiexport/roads.php?output=gpoly&").buildUpon();
      uri.appendQueryParameter("bbox", sqlBbox);
      uri.appendQueryParameter("max", String.valueOf(maxObjects));
      Log.debug("Vector API url:" + uri.build().toString());

      JSONObject jsonData = NetUtils.getJSONFromUrl(uri.build().toString());

      if (jsonData == null) {
        Log.debug("No CartoDB data");
        return;
      }

      JSONArray rows = jsonData.getJSONArray("res");

      for (int i = 0; i < rows.length(); i++) {
        JSONObject row = rows.getJSONObject(i);

        String the_geom_encoded = row.getString("g");
        String name = row.getString("n");
        String type = row.getString("t");

        Vector<MapPos> mapPos = GeoUtils.decompress(the_geom_encoded, 5, projection);

        Geometry newObject = new Line(mapPos, new DefaultLabel(name, type), lineStyleSet, null);

        newObject.attachToLayer(this);
        newObject.setActiveStyle(zoom);
        newVisibleElementsList.add(newObject);
      }
    } catch (ParseException e) {
      Log.error("Error parsing data " + e.toString());
    } catch (JSONException e) {
      Log.error("Error parsing JSON data " + e.toString());
    }

    long timeEnd = System.currentTimeMillis();
    Log.debug(
        "OnlineVector loaded N:"
            + newVisibleElementsList.size()
            + " time ms:"
            + (timeEnd - timeStart));
    setVisibleElements(newVisibleElementsList);
  }
  public void createElementsInLayer(
      int zoom, Vector<Geometry> objectTemp, Vector<Geometry> objects, GeometryData.Type dataType) {

    // apply styles, create new objects for these
    for (Geometry object : objectTemp) {

      Geometry newObject = null;
      String[] userData = (String[]) object.userData;
      GeometryStyle style = getGeometryStyle(object, userData[0]);
      GeometryData geomData = new GeometryData(userData[0], dataType, userData[1], style, layerId);

      if (hideGeometryList.contains(geomData.id)) continue;

      if (object instanceof Point) {
        newObject =
            new Point(((Point) object).getMapPos(), null, style.toPointStyleSet(), geomData);
      } else if (object instanceof Line) {
        newObject =
            new Line(((Line) object).getVertexList(), null, style.toLineStyleSet(), geomData);
      } else if (object instanceof Polygon) {
        newObject =
            new Polygon(
                ((Polygon) object).getVertexList(),
                ((Polygon) object).getHolePolygonList(),
                null,
                style.toPolygonStyleSet(),
                geomData);
      }

      Geometry transformedObject = GeometryUtil.convertGeometryFromWgs84(newObject);

      transformedObject.attachToLayer(this);
      transformedObject.setActiveStyle(zoom);

      objects.add(transformedObject);
    }
  }