Add Initial PMTiles support (#2882)
Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
@@ -91,9 +91,15 @@ void RegisterNativeHTTPRequest(jni::JNIEnv& env) {
|
||||
HTTPRequest::HTTPRequest(jni::JNIEnv& env, const Resource& resource_, FileSource::Callback callback_)
|
||||
: resource(resource_),
|
||||
callback(callback_) {
|
||||
std::string dataRangeStr;
|
||||
std::string etagStr;
|
||||
std::string modifiedStr;
|
||||
|
||||
if (resource.dataRange) {
|
||||
dataRangeStr = std::string("bytes=") + std::to_string(resource.dataRange->first) + std::string("-") +
|
||||
std::to_string(resource.dataRange->second);
|
||||
}
|
||||
|
||||
if (resource.priorEtag) {
|
||||
etagStr = *resource.priorEtag;
|
||||
} else if (resource.priorModified) {
|
||||
@@ -104,13 +110,14 @@ HTTPRequest::HTTPRequest(jni::JNIEnv& env, const Resource& resource_, FileSource
|
||||
|
||||
static auto& javaClass = jni::Class<HTTPRequest>::Singleton(env);
|
||||
static auto constructor =
|
||||
javaClass.GetConstructor<jni::jlong, jni::String, jni::String, jni::String, jni::jboolean>(env);
|
||||
javaClass.GetConstructor<jni::jlong, jni::String, jni::String, jni::String, jni::String, jni::jboolean>(env);
|
||||
|
||||
javaRequest = jni::NewGlobal(env,
|
||||
javaClass.New(env,
|
||||
constructor,
|
||||
reinterpret_cast<jlong>(this),
|
||||
jni::Make<jni::String>(env, resource.url),
|
||||
jni::Make<jni::String>(env, dataRangeStr),
|
||||
jni::Make<jni::String>(env, etagStr),
|
||||
jni::Make<jni::String>(env, modifiedStr),
|
||||
(jboolean)(resource_.usage == Resource::Usage::Offline)));
|
||||
|
||||
@@ -18,12 +18,13 @@ public interface HttpRequest {
|
||||
* @param httpRequest callback to be invoked when we receive a response
|
||||
* @param nativePtr the pointer associated to the request
|
||||
* @param resourceUrl the resource url to download
|
||||
* @param dataRange http header, used to indicate the part of a resource that the server should return
|
||||
* @param etag http header, identifier for a specific version of a resource
|
||||
* @param modified http header, used to determine if a resource hasn't been modified since
|
||||
* @param offlineUsage flag to indicate a resource will be used for offline, appends offline=true as a query parameter
|
||||
*/
|
||||
void executeRequest(HttpResponder httpRequest, long nativePtr, String resourceUrl,
|
||||
String etag, String modified, boolean offlineUsage);
|
||||
String dataRange, String etag, String modified, boolean offlineUsage);
|
||||
|
||||
/**
|
||||
* Cancels the request.
|
||||
|
||||
@@ -19,7 +19,8 @@ public class NativeHttpRequest implements HttpResponder {
|
||||
private long nativePtr;
|
||||
|
||||
@Keep
|
||||
private NativeHttpRequest(long nativePtr, String resourceUrl, String etag, String modified, boolean offlineUsage) {
|
||||
private NativeHttpRequest(long nativePtr, String resourceUrl, String dataRange, String etag, String modified,
|
||||
boolean offlineUsage) {
|
||||
this.nativePtr = nativePtr;
|
||||
|
||||
if (resourceUrl.startsWith("local://")) {
|
||||
@@ -27,7 +28,7 @@ public class NativeHttpRequest implements HttpResponder {
|
||||
executeLocalRequest(resourceUrl);
|
||||
return;
|
||||
}
|
||||
httpRequest.executeRequest(this, nativePtr, resourceUrl, etag, modified, offlineUsage);
|
||||
httpRequest.executeRequest(this, nativePtr, resourceUrl, dataRange, etag, modified, offlineUsage);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
|
||||
@@ -58,7 +58,8 @@ public class HttpRequestImpl implements HttpRequest {
|
||||
|
||||
@Override
|
||||
public void executeRequest(HttpResponder httpRequest, long nativePtr, @NonNull String resourceUrl,
|
||||
@NonNull String etag, @NonNull String modified, boolean offlineUsage) {
|
||||
@NonNull String dataRange, @NonNull String etag, @NonNull String modified,
|
||||
boolean offlineUsage) {
|
||||
OkHttpCallback callback = new OkHttpCallback(httpRequest);
|
||||
try {
|
||||
HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
|
||||
@@ -74,6 +75,11 @@ public class HttpRequestImpl implements HttpRequest {
|
||||
.url(resourceUrl)
|
||||
.tag(resourceUrl.toLowerCase(MapLibreConstants.MAPLIBRE_LOCALE))
|
||||
.addHeader("User-Agent", userAgentString);
|
||||
|
||||
if (dataRange.length() > 0) {
|
||||
builder.addHeader("Range", dataRange);
|
||||
}
|
||||
|
||||
if (etag.length() > 0) {
|
||||
builder.addHeader("If-None-Match", etag);
|
||||
} else if (modified.length() > 0) {
|
||||
|
||||
@@ -11,11 +11,11 @@ import org.maplibre.android.module.http.HttpRequestImpl
|
||||
*/
|
||||
class ExampleHttpRequestImpl : HttpRequest {
|
||||
override fun executeRequest(httpRequest: HttpResponder, nativePtr: Long, resourceUrl: String,
|
||||
etag: String, modified: String, offlineUsage: Boolean)
|
||||
dataRange: String, etag: String, modified: String, offlineUsage: Boolean)
|
||||
{
|
||||
// Load all json documents and any pbf ending with a 0.
|
||||
if (resourceUrl.endsWith(".json") || resourceUrl.endsWith("0.pbf")) {
|
||||
impl.executeRequest(httpRequest, nativePtr, resourceUrl, etag, modified, offlineUsage)
|
||||
impl.executeRequest(httpRequest, nativePtr, resourceUrl, dataRange, etag, modified, offlineUsage)
|
||||
} else {
|
||||
// All other requests get an instant 404!
|
||||
httpRequest.onResponse(
|
||||
|
||||
@@ -61,6 +61,7 @@ target_sources(
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_database.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_download.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/online_file_source.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/$<IF:$<BOOL:${MLN_WITH_PMTILES}>,pmtiles_file_source.cpp,pmtiles_file_source_stub.cpp>
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/sqlite3.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/text/bidi.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/compression.cpp
|
||||
|
||||
Reference in New Issue
Block a user