Skip to content

Commit

Permalink
Mapbox vector tiles improvements and example #57
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 committed Oct 29, 2016
1 parent 05e9e0c commit dece13d
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 9 deletions.
3 changes: 3 additions & 0 deletions vtm-android-example/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<activity
android:name=".LocationActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MapboxMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MapsforgeMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2016 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.android.test;

import android.os.Bundle;

import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.UrlTileSource;
import org.oscim.tiling.source.mvt.MapboxTileSource;

public class MapboxMapActivity extends MapActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

UrlTileSource tileSource = MapboxTileSource.builder()
.apiKey("vector-tiles-xxxxxxx") // Put a proper API key
.build();

VectorTileLayer l = mMap.setBaseMap(tileSource);
mMap.setTheme(VtmThemes.MAPZEN);

mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_samples);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples);
linearLayout.addView(createButton(SimpleMapActivity.class));
linearLayout.addView(createButton(MapboxMapActivity.class));
linearLayout.addView(createButton(BitmapTileMapActivity.class));
linearLayout.addView(createButton(MapsforgeMapActivity.class));
linearLayout.addView(createButton(MarkerOverlayActivity.class));
Expand Down
44 changes: 44 additions & 0 deletions vtm-playground/src/org/oscim/test/MapboxTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2016 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.test;

import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.UrlTileSource;
import org.oscim.tiling.source.mvt.MapboxTileSource;

public class MapboxTest extends GdxMapApp {

@Override
public void createLayers() {
UrlTileSource tileSource = MapboxTileSource.builder()
.apiKey("vector-tiles-xxxxxxx") // Put a proper API key
.build();

VectorTileLayer l = mMap.setBaseMap(tileSource);
mMap.setTheme(VtmThemes.MAPZEN);

mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
}

public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapboxTest());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand All @@ -20,13 +21,37 @@
import org.oscim.tiling.source.UrlTileDataSource;
import org.oscim.tiling.source.UrlTileSource;

public class MapboxVectorTileSource extends UrlTileSource {
public MapboxVectorTileSource(String url, String tilePath) {
super(url, tilePath);
//Map<String, String> opt = new HashMap<String, String>();
//opt.put("Accept-Encoding", "gzip");
//opt.put("User-Agent", "curl/7.47.1");
//setHttpRequestHeaders(opt);
public class MapboxTileSource extends UrlTileSource {

private final static String DEFAULT_URL = "https://vector.mapzen.com/osm/all";
private final static String DEFAULT_PATH = "/{Z}/{X}/{Y}.mvt";

public static class Builder<T extends Builder<T>> extends UrlTileSource.Builder<T> {

public Builder() {
super(DEFAULT_URL, DEFAULT_PATH, 1, 17);
}

public MapboxTileSource build() {
return new MapboxTileSource(this);
}
}

@SuppressWarnings("rawtypes")
public static Builder<?> builder() {
return new Builder();
}

protected MapboxTileSource(Builder<?> builder) {
super(builder);
}

public MapboxTileSource() {
this(builder());
}

public MapboxTileSource(String urlString) {
this(builder().url(urlString));
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions vtm/src/org/oscim/tiling/source/mvt/TileDecoder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand Down Expand Up @@ -64,7 +65,7 @@ public class TileDecoder extends PbfDecoder {
private short[] mTmpTags = new short[1024];

private Tile mTile;
private final String mLocale = "de";
private final String mLocale = "en";
private ITileDataSink mMapDataCallback;

private final static float REF_TILE_SIZE = 4096.0f;
Expand Down Expand Up @@ -166,7 +167,8 @@ private boolean decodeLayer() throws IOException {
}

Tag layerTag = new Tag("layer", name);
log.debug("add layer " + name);
if (debug)
log.debug("add layer " + name);

if (numFeatures == 0)
return true;
Expand Down

0 comments on commit dece13d

Please sign in to comment.