Mapbox vector tiles improvements and example #57
This commit is contained in:
parent
05e9e0cdc8
commit
dece13ddc9
@ -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" />
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ public class Samples extends Activity {
|
||||
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));
|
||||
|
44
vtm-playground/src/org/oscim/test/MapboxTest.java
Normal file
44
vtm-playground/src/org/oscim/test/MapboxTest.java
Normal file
@ -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());
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -20,13 +21,37 @@ import org.oscim.tiling.ITileDataSource;
|
||||
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
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -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;
|
||||
@ -166,7 +167,8 @@ public class TileDecoder extends PbfDecoder {
|
||||
}
|
||||
|
||||
Tag layerTag = new Tag("layer", name);
|
||||
log.debug("add layer " + name);
|
||||
if (debug)
|
||||
log.debug("add layer " + name);
|
||||
|
||||
if (numFeatures == 0)
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user