Beispiel #1
0
  @Override
  public void createLayers() {
    mMap.setMapPosition(53.08, 8.83, 1 << 14);

    // TileSource tileSource = new OSciMap4TileSource();

    MapFileTileSource tileSource = new MapFileTileSource();
    // tileSource.setMapFile("/home/jeff/src/vtm/Freizeitkarte_DEU_NW.map");
    tileSource.setMapFile("/home/jeff/germany.map");

    VectorTileLayer l = mMap.setBaseMap(tileSource);
    mapLayer = l;

    // mMap.getLayers().add(new BuildingLayer(mMap, l.getTileLayer()));
    mMap.layers().add(new LabelLayer(mMap, l));

    try {
      IRenderTheme theme = ThemeLoader.load("themes/freizeitkarte/theme.xml");
      // IRenderTheme theme =
      // ThemeLoader.load("themes/elevate/theme.xml");
      // IRenderTheme theme = ThemeLoader.load("themes/vmap/theme.xml");
      l.setRenderTheme(theme);
      MapRenderer.setBackgroundColor(theme.getMapBackground());
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    // mMap.getLayers().add(new GenericLayer(mMap, new MeshRenderer()));
    // mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer()));
  }
Beispiel #2
0
  @Override
  public void createLayers() {
    MapRenderer.setBackgroundColor(0xf0f0f0);

    TileSource ts = new OSciMap4TileSource();
    VectorTileLayer l = mMap.setBaseMap(ts);

    mMap.setTheme(VtmThemes.DEFAULT);
    RenderTheme t = (RenderTheme) l.getTheme();
    mTheme = t;
    // t.traverseRules(new DesaturateAreaStyles());
    // t.traverseRules(new DesaturateLineStyles());
    t.traverseRules(new SaturateLineStyles(0.5, true, true, true));
    t.updateStyles();

    // mMap.setMapPosition(7.707, 81.689, 1 << 16);

    mMap.setMapPosition(53.08, 8.82, 1 << 16);
  }
Beispiel #3
0
  @Override
  protected boolean onKeyDown(int keycode) {
    VectorTileLayer l = (VectorTileLayer) mMap.layers().get(1);
    RenderTheme t = (RenderTheme) l.getTheme();

    if (keycode == Input.Keys.NUM_1) {
      mSaturation += 0.1;
      t.traverseRules(new SaturateLineStyles(mSaturation, true, true, true));
      t.updateStyles();
      mMap.render();
      return true;
    }
    if (keycode == Input.Keys.NUM_2) {
      mSaturation -= 0.1;
      t.traverseRules(new SaturateLineStyles(mSaturation, true, true, true));
      t.updateStyles();
      mMap.render();
      return true;
    }

    return super.onKeyDown(keycode);
  }
Beispiel #4
0
  @Override
  protected boolean onKeyDown(int keycode) {
    String name = null;
    if (keycode == Input.Keys.NUM_1) name = "themes/freizeitkarte/theme.xml";
    if (keycode == Input.Keys.NUM_2) name = "themes/elevate/theme.xml";
    if (keycode == Input.Keys.NUM_3) name = "themes/vmap/theme.xml";

    if (name == null) return false;

    try {
      IRenderTheme theme = ThemeLoader.load(name);
      mapLayer.setRenderTheme(theme);
      MapRenderer.setBackgroundColor(theme.getMapBackground());
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    mMap.clearMap();
    mMap.updateMap(true);
    return true;
  }
Beispiel #5
0
  public Poi3DLayer(Map map, VectorTileLayer tileLayer) {
    super(map);
    tileLayer.addHook(
        new TileLoaderProcessHook() {

          @Override
          public boolean process(MapTile tile, ElementLayers layers, MapElement element) {

            if (!element.tags.contains(TREE_TAG)) return false;

            Poi3DTileData td = get(tile);
            PointF p = element.getPoint(0);
            SymbolItem s = SymbolItem.pool.get();
            s.x = p.x;
            s.y = p.y;
            td.symbols.push(s);

            return true;
          }
        });
    mTileLayer = tileLayer;

    mRenderer = g3d = new GdxRenderer3D(mMap);

    // Material mat = new
    // Material(ColorAttribute.createDiffuse(Color.BLUE));
    // ModelBuilder modelBuilder = new ModelBuilder();
    // long attributes = Usage.Position | Usage.Normal |
    // Usage.TextureCoordinates;

    // mModel = modelBuilder.createSphere(10f, 10f, 10f, 12, 12,
    // mat, attributes);

    assets = new AssetManager();
    assets.load("data/g3d/treeA.g3dj", Model.class);
    loading = true;
  }
Beispiel #6
0
 public void setTheme(MapzenStyle.Theme theme) {
   IRenderTheme t = ThemeLoader.load(theme);
   baseLayer.setRenderTheme(t);
   MapRenderer.setBackgroundColor(t.getMapBackground());
   getMap().clearMap();
 }
Beispiel #7
0
  @Override
  public void onMapEvent(Event ev, MapPosition pos) {

    if (ev == Map.CLEAR_EVENT) {
      mTileSet = new TileSet();
      mPrevTiles = new TileSet();
      mTileMap = new LinkedHashMap<Tile, Array<SharedModel>>();
      synchronized (g3d) {
        g3d.instances.clear();
      }
    }

    if (loading && assets.update()) {
      doneLoading();
      // Renderable renderable = new Renderable();
      // new SharedModel(mModel).getRenderable(renderable);
      // Shader shader = new DefaultShader(renderable, true, false,
      // false, false, 1, 0, 0, 0);
    }
    if (loading) return;

    // log.debug("update");

    mTileLayer.tileRenderer().getVisibleTiles(mTileSet);

    if (mTileSet.cnt == 0) {
      mTileSet.releaseTiles();
      return;
    }

    boolean changed = false;

    Array<SharedModel> added = new Array<SharedModel>();
    Array<SharedModel> removed = new Array<SharedModel>();

    for (int i = 0; i < mTileSet.cnt; i++) {
      MapTile t = mTileSet.tiles[i];
      if (mPrevTiles.contains(t)) continue;

      Array<SharedModel> instances = new Array<SharedModel>();

      Poi3DTileData ld = (Poi3DTileData) t.getData(POI_DATA);
      if (ld == null) continue;

      for (SymbolItem it : ld.symbols) {

        SharedModel inst = new SharedModel(mModel);
        inst.userData = it;
        // float r = 0.5f + 0.5f * (float) Math.random();
        // float g = 0.5f + 0.5f * (float) Math.random();
        // float b = 0.5f + 0.5f * (float) Math.random();

        // inst.transform.setTranslation(new Vector3(it.x, it.y,
        // 10));
        // inst.materials.get(0).set(ColorAttribute.createDiffuse(r,
        // g, b, 0.8f));
        instances.add(inst);
        added.add(inst);
      }

      if (instances.size == 0) continue;

      log.debug("add " + t + " " + instances.size);

      changed = true;

      mTileMap.put(t, instances);
    }

    for (int i = 0; i < mPrevTiles.cnt; i++) {
      MapTile t = mPrevTiles.tiles[i];
      if (mTileSet.contains(t)) continue;

      Array<SharedModel> instances = mTileMap.get(t);
      if (instances == null) continue;

      changed = true;

      removed.addAll(instances);
      mTileMap.remove(t);
      log.debug("remove " + t);
    }

    mPrevTiles.releaseTiles();

    int zoom = mTileSet.tiles[0].zoomLevel;

    TileSet tmp = mPrevTiles;
    mPrevTiles = mTileSet;
    mTileSet = tmp;

    if (!changed) return;

    // scale aka tree height
    float scale = (float) (1f / (1 << (17 - zoom))) * 8;

    double tileX = (pos.x * (Tile.SIZE << zoom));
    double tileY = (pos.y * (Tile.SIZE << zoom));

    synchronized (g3d) {
      for (Entry<Tile, Array<SharedModel>> e : mTileMap.entrySet()) {
        Tile t = e.getKey();

        float dx = (float) (t.tileX * Tile.SIZE - tileX);
        float dy = (float) (t.tileY * Tile.SIZE - tileY);

        for (SharedModel inst : e.getValue()) {
          SymbolItem it = (SymbolItem) inst.userData;

          // variable height
          float s = scale + (it.x * it.y) % 3;
          float r = (it.x * it.y) % 360;

          inst.transform.idt();
          inst.transform.scale(s, s, s);
          inst.transform.translate((dx + it.x) / s, (dy + it.y) / s, 0);
          inst.transform.rotate(0, 0, 1, r);

          // inst.transform.setToTranslationAndScaling((dx +
          // it.x), (dy + it.y),
          // 0, s, s, s);

        }
      }

      g3d.instances.removeAll(removed, true);
      g3d.instances.addAll(added);
      g3d.cam.setMapPosition(pos.x, pos.y, 1 << zoom);
    }
  }