forked from opensciencemap/vtm
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
691 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
rootProject.name = 'vtm-parent' | ||
include ':vtm' | ||
include ':vtm-android' | ||
include ':vtm-android-example' | ||
include ':vtm-android-gdx' | ||
include ':vtm-app' | ||
include ':vtm-desktop' | ||
include ':vtm-extras' | ||
include ':vtm-gdx' | ||
include ':vtm-http' | ||
include ':vtm-ios' | ||
include ':vtm-ios-example' | ||
include ':vtm-jeo' | ||
include ':vtm-json' | ||
include ':vtm-jts' | ||
include ':vtm-playground' | ||
include ':vtm-tests' | ||
include ':vtm-extras' | ||
include ':vtm-android' | ||
include ':vtm-android-example' | ||
include ':vtm-themes' | ||
include ':vtm-gdx' | ||
include ':vtm-desktop' | ||
include ':vtm-android-gdx' | ||
include ':vtm-web' | ||
include ':vtm-web-app' | ||
//include ':vtm-web-js' | ||
include ':vtm-jeo' | ||
include ':vtm-playground' | ||
include ':vtm-ios' | ||
include ':vtm-ios-example' | ||
include ':vtm-app' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
vtm-android-example/src/org/oscim/android/test/MapzenGeojsonMapActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2017 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.android.cache.TileCache; | ||
import org.oscim.layers.TileGridLayer; | ||
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.OkHttpEngine; | ||
import org.oscim.tiling.source.UrlTileSource; | ||
import org.oscim.tiling.source.geojson.MapzenGeojsonTileSource; | ||
|
||
public class MapzenGeojsonMapActivity extends MapActivity { | ||
|
||
private static final boolean USE_CACHE = false; | ||
|
||
private TileCache mCache; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
UrlTileSource tileSource = MapzenGeojsonTileSource.builder() | ||
.apiKey("mapzen-xxxxxxx") // Put a proper API key | ||
.httpFactory(new OkHttpEngine.OkHttpFactory()) | ||
//.locale("en") | ||
.build(); | ||
|
||
if (USE_CACHE) { | ||
// Cache the tiles into a local SQLite database | ||
mCache = new TileCache(this, null, "tile.db"); | ||
mCache.setCacheSize(512 * (1 << 10)); | ||
tileSource.setCache(mCache); | ||
} | ||
|
||
VectorTileLayer l = mMap.setBaseMap(tileSource); | ||
mMap.setTheme(VtmThemes.MAPZEN); | ||
|
||
mMap.layers().add(new BuildingLayer(mMap, l)); | ||
mMap.layers().add(new LabelLayer(mMap, l)); | ||
|
||
mMap.layers().add(new TileGridLayer(mMap, getResources().getDisplayMetrics().density)); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
|
||
if (mCache != null) | ||
mCache.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apply plugin: 'java' | ||
apply plugin: 'maven' | ||
|
||
dependencies { | ||
compile project(':vtm') | ||
compile 'com.fasterxml.jackson.core:jackson-core:2.8.4' | ||
} | ||
|
||
sourceSets { | ||
main.java.srcDirs = ['src'] | ||
} | ||
|
||
if (project.hasProperty("SONATYPE_USERNAME")) { | ||
afterEvaluate { | ||
project.apply from: "${rootProject.projectDir}/deploy.gradle" | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
vtm-json/src/org/oscim/tiling/source/geojson/GeojsonTileSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2014 Hannes Janetzek | ||
* Copyright 2017 devemux86 | ||
* | ||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org). | ||
* | ||
* 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.tiling.source.geojson; | ||
|
||
import org.oscim.core.MapElement; | ||
import org.oscim.core.Tag; | ||
import org.oscim.tiling.ITileDataSource; | ||
import org.oscim.tiling.source.UrlTileDataSource; | ||
import org.oscim.tiling.source.UrlTileSource; | ||
|
||
import java.util.Map; | ||
|
||
public abstract class GeojsonTileSource extends UrlTileSource { | ||
|
||
protected GeojsonTileSource(Builder<?> builder) { | ||
super(builder); | ||
} | ||
|
||
protected GeojsonTileSource(String urlString, String tilePath) { | ||
super(urlString, tilePath); | ||
} | ||
|
||
protected GeojsonTileSource(String urlString, String tilePath, int zoomMin, int zoomMax) { | ||
super(urlString, tilePath, zoomMin, zoomMax); | ||
} | ||
|
||
@Override | ||
public ITileDataSource getDataSource() { | ||
return new UrlTileDataSource(this, new TileDecoder(this), getHttpEngine()); | ||
} | ||
|
||
public Tag getFeatureTag() { | ||
return null; | ||
} | ||
|
||
/** | ||
* allow overriding tag handling | ||
*/ | ||
public abstract void decodeTags(MapElement mapElement, Map<String, Object> properties); | ||
|
||
public Tag rewriteTag(String key, Object value) { | ||
if (value == null) | ||
return null; | ||
|
||
String val = (value instanceof String) ? (String) value : String.valueOf(value); | ||
|
||
return new Tag(key, val); | ||
} | ||
|
||
/** | ||
* modify mapElement before process() | ||
*/ | ||
public void postGeomHook(MapElement mapElement) { | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
vtm-json/src/org/oscim/tiling/source/geojson/MapzenGeojsonTileSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright 2017 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.tiling.source.geojson; | ||
|
||
import org.oscim.core.MapElement; | ||
import org.oscim.core.Tag; | ||
import org.oscim.tiling.source.UrlTileSource; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class MapzenGeojsonTileSource extends GeojsonTileSource { | ||
|
||
private final static String DEFAULT_URL = "https://tile.mapzen.com/mapzen/vector/v1/all"; | ||
private final static String DEFAULT_PATH = "/{Z}/{X}/{Y}.json"; | ||
|
||
public static class Builder<T extends Builder<T>> extends UrlTileSource.Builder<T> { | ||
private String locale = ""; | ||
|
||
public Builder() { | ||
super(DEFAULT_URL, DEFAULT_PATH, 1, 17); | ||
} | ||
|
||
public T locale(String locale) { | ||
this.locale = locale; | ||
return self(); | ||
} | ||
|
||
public MapzenGeojsonTileSource build() { | ||
return new MapzenGeojsonTileSource(this); | ||
} | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
public static Builder<?> builder() { | ||
return new Builder(); | ||
} | ||
|
||
private static Map<String, Tag> mappings = new LinkedHashMap<>(); | ||
|
||
private static Tag addMapping(String key, String val) { | ||
Tag tag = new Tag(key, val); | ||
mappings.put(key + "=" + val, tag); | ||
return tag; | ||
} | ||
|
||
private final String locale; | ||
|
||
public MapzenGeojsonTileSource(Builder<?> builder) { | ||
super(builder); | ||
this.locale = builder.locale; | ||
} | ||
|
||
public MapzenGeojsonTileSource() { | ||
this(builder()); | ||
} | ||
|
||
public MapzenGeojsonTileSource(String urlString) { | ||
this(builder().url(urlString)); | ||
} | ||
|
||
@Override | ||
public void decodeTags(MapElement mapElement, Map<String, Object> properties) { | ||
boolean hasName = false; | ||
String fallbackName = null; | ||
|
||
for (Map.Entry<String, Object> entry : properties.entrySet()) { | ||
String key = entry.getKey(); | ||
Object value = entry.getValue(); | ||
String val = (value instanceof String) ? (String) value : String.valueOf(value); | ||
|
||
if (key.startsWith(Tag.KEY_NAME)) { | ||
int len = key.length(); | ||
if (len == 4) { | ||
fallbackName = val; | ||
continue; | ||
} | ||
if (len < 7) | ||
continue; | ||
if (locale.equals(key.substring(5))) { | ||
hasName = true; | ||
mapElement.tags.add(new Tag(Tag.KEY_NAME, val, false)); | ||
} | ||
continue; | ||
} | ||
|
||
Tag tag = mappings.get(key + "=" + val); | ||
if (tag == null) | ||
tag = addMapping(key, val); | ||
mapElement.tags.add(tag); | ||
} | ||
|
||
if (!hasName && fallbackName != null) | ||
mapElement.tags.add(new Tag(Tag.KEY_NAME, fallbackName, false)); | ||
} | ||
} |
Oops, something went wrong.