From ab86aabbf6292f758d92c191c6e1e2089dabdb0b Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 30 May 2019 13:38:35 +0800 Subject: [PATCH 1/4] Create style json plugin --- plugin-stylejson/.gitignore | 1 + plugin-stylejson/build.gradle | 34 +++++++++++++++++++ plugin-stylejson/gradle.properties | 5 +++ plugin-stylejson/proguard-rules.pro | 21 ++++++++++++ plugin-stylejson/src/main/AndroidManifest.xml | 2 ++ .../src/main/res/values/strings.xml | 3 ++ .../pluginstylejson/ExampleUnitTest.java | 17 ++++++++++ settings.gradle | 3 +- 8 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 plugin-stylejson/.gitignore create mode 100644 plugin-stylejson/build.gradle create mode 100644 plugin-stylejson/gradle.properties create mode 100644 plugin-stylejson/proguard-rules.pro create mode 100644 plugin-stylejson/src/main/AndroidManifest.xml create mode 100644 plugin-stylejson/src/main/res/values/strings.xml create mode 100644 plugin-stylejson/src/test/java/com/mapbox/pluginstylejson/ExampleUnitTest.java diff --git a/plugin-stylejson/.gitignore b/plugin-stylejson/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/plugin-stylejson/.gitignore @@ -0,0 +1 @@ +/build diff --git a/plugin-stylejson/build.gradle b/plugin-stylejson/build.gradle new file mode 100644 index 000000000..a28c8586e --- /dev/null +++ b/plugin-stylejson/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion androidVersions.compileSdkVersion + + defaultConfig { + minSdkVersion androidVersions.minSdkVersion + targetSdkVersion androidVersions.targetSdkVersion + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + configurations { + javadocDeps + } + + lintOptions { + abortOnError false + } + + testOptions { + unitTests.returnDefaultValues true + } +} + +dependencies { + implementation dependenciesList.mapboxMapSdk + javadocDeps dependenciesList.mapboxMapSdk + testImplementation dependenciesList.junit + testImplementation dependenciesList.mockito +} + +apply from: "${rootDir}/gradle/javadoc.gradle" +apply from: "${rootDir}/gradle/publish.gradle" +apply from: "${rootDir}/gradle/checkstyle.gradle" \ No newline at end of file diff --git a/plugin-stylejson/gradle.properties b/plugin-stylejson/gradle.properties new file mode 100644 index 000000000..e7623ba4d --- /dev/null +++ b/plugin-stylejson/gradle.properties @@ -0,0 +1,5 @@ +VERSION_NAME=0.1.0-SNAPSHOT +POM_ARTIFACT_ID=mapbox-android-plugin-stylejson +POM_NAME=Mapbox Android StyleJson Plugin +POM_DESCRIPTION=Mapbox Android StyleJson Plugin +POM_PACKAGING=aar \ No newline at end of file diff --git a/plugin-stylejson/proguard-rules.pro b/plugin-stylejson/proguard-rules.pro new file mode 100644 index 000000000..f1b424510 --- /dev/null +++ b/plugin-stylejson/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/plugin-stylejson/src/main/AndroidManifest.xml b/plugin-stylejson/src/main/AndroidManifest.xml new file mode 100644 index 000000000..aba05813e --- /dev/null +++ b/plugin-stylejson/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/plugin-stylejson/src/main/res/values/strings.xml b/plugin-stylejson/src/main/res/values/strings.xml new file mode 100644 index 000000000..9c3595fee --- /dev/null +++ b/plugin-stylejson/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + pluginstylejson + diff --git a/plugin-stylejson/src/test/java/com/mapbox/pluginstylejson/ExampleUnitTest.java b/plugin-stylejson/src/test/java/com/mapbox/pluginstylejson/ExampleUnitTest.java new file mode 100644 index 000000000..2ee114f4d --- /dev/null +++ b/plugin-stylejson/src/test/java/com/mapbox/pluginstylejson/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.mapbox.pluginstylejson; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 07e316702..873225790 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,4 +7,5 @@ include ':plugin-localization' include ':plugin-annotation' include ':plugin-markerview' include ':ktx-mapbox-maps' -include ':plugin-scalebar' \ No newline at end of file +include ':plugin-scalebar' +include ':plugin-stylejson' \ No newline at end of file From 56f7315b27aef3b63c83c3dd2e6e0b35f3089b4f Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 30 May 2019 15:40:20 +0800 Subject: [PATCH 2/4] Add parserGeoJsonSource. --- .../pluginstylejson/StyleJsonContants.java | 21 +++++++ .../pluginstylejson/StyleJsonParser.java | 55 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.java create mode 100644 plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.java diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.java b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.java new file mode 100644 index 000000000..4c208c1fb --- /dev/null +++ b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.java @@ -0,0 +1,21 @@ +package com.mapbox.pluginstylejson; + +public class StyleJsonContants { + public static final String LAYER_BACKGROUND = "background"; + public static final String LAYER_CYCLE = "cycle"; + public static final String LAYER_CUSTOM = "custom"; + public static final String LAYER_FILL_EXTRUSION = "fillextrusion"; + public static final String LAYER_FILL = "fill"; + public static final String LAYER_HEATMAP = "heatmap"; + public static final String LAYER_HILLSHADE = "hillshade"; + public static final String LAYER_LINE = "line"; + public static final String LAYER_RASTER = "raster"; + public static final String LAYER_SYMBOL = "symbol"; + public static final String SOURCE_CUSTOM_GEOMETRY = "custom geometry"; + public static final String SOURCE_GEO_JSON = "geojson"; + public static final String SOURCE_IMAGE = "image"; + public static final String SOURCE_RASTER_DEM = "rasterdem"; + public static final String SOURCE_RASTER = "raster"; + public static final String SOURCE_UNKNOW = "unknow"; + public static final String SOURCE_VECTOR = "vector"; +} diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.java b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.java new file mode 100644 index 000000000..30ba38ef2 --- /dev/null +++ b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.java @@ -0,0 +1,55 @@ +package com.mapbox.pluginstylejson; + +import android.support.annotation.NonNull; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.geojson.GeometryCollection; +import com.mapbox.geojson.LineString; +import com.mapbox.geojson.MultiLineString; +import com.mapbox.geojson.MultiPoint; +import com.mapbox.geojson.MultiPolygon; +import com.mapbox.geojson.Point; +import com.mapbox.geojson.Polygon; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; + +public class StyleJsonParser { + private Gson gson = new Gson(); + + GeoJsonSource parserGeoJsonSource(@NonNull String id, @NonNull String json) { + GeoJsonSource geoJsonSource = new GeoJsonSource(id); + JsonObject source = gson.fromJson(json, JsonObject.class); + if (source.has("data")) { + JsonObject data = source.getAsJsonObject("data"); + String dataString = data.getAsString(); + if (dataString.startsWith("http")) { + geoJsonSource.setUrl(dataString); + } else { + String type = data.get("type").getAsString(); + if ("Feature".equals(type)) { + geoJsonSource.setGeoJson(Feature.fromJson(dataString)); + } else if ("FeatureCollection".equals(type)) { + geoJsonSource.setGeoJson(FeatureCollection.fromJson(dataString)); + } else if ("GeometryCollection".equals(type)) { + geoJsonSource.setGeoJson(GeometryCollection.fromJson(dataString)); + } else if ("LineString".equals(type)) { + geoJsonSource.setGeoJson(LineString.fromJson(dataString)); + } else if ("MultiLineString".equals(type)) { + geoJsonSource.setGeoJson(MultiLineString.fromJson(dataString)); + } else if ("MultiPoint".equals(type)) { + geoJsonSource.setGeoJson(MultiPoint.fromJson(dataString)); + } else if ("MultiPolygon".equals(type)) { + geoJsonSource.setGeoJson(MultiPolygon.fromJson(dataString)); + } else if ("Point".equals(type)) { + geoJsonSource.setGeoJson(Point.fromJson(dataString)); + } else if ("Polygon".equals(type)) { + geoJsonSource.setGeoJson(Polygon.fromJson(dataString)); + } + } + } + + return geoJsonSource; + } +} From 68234f611981b0c5ab45f657c92f6809c3564d4d Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 3 Jun 2019 14:10:27 +0800 Subject: [PATCH 3/4] make lib to kotlin --- gradle/dependencies.gradle | 2 +- plugin-stylejson/build.gradle | 3 + .../pluginstylejson/StyleJsonContants.java | 21 ------- .../pluginstylejson/StyleJsonContants.kt | 31 +++++++++++ .../pluginstylejson/StyleJsonParser.java | 55 ------------------- .../mapbox/pluginstylejson/StyleJsonParser.kt | 51 +++++++++++++++++ 6 files changed, 86 insertions(+), 77 deletions(-) delete mode 100644 plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.java create mode 100644 plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.kt delete mode 100644 plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.java create mode 100644 plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.kt diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 3b2cd99ce..c72dc63fb 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -31,7 +31,7 @@ pluginVersion = [ checkstyle: '8.10.1', gradle : '3.4.0', - kotlin : '1.3.20', + kotlin : '1.3.31', dokka : '0.9.17' ] diff --git a/plugin-stylejson/build.gradle b/plugin-stylejson/build.gradle index a28c8586e..445ec091b 100644 --- a/plugin-stylejson/build.gradle +++ b/plugin-stylejson/build.gradle @@ -1,4 +1,6 @@ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-android' android { compileSdkVersion androidVersions.compileSdkVersion @@ -23,6 +25,7 @@ android { } dependencies { + implementation dependenciesList.kotlin implementation dependenciesList.mapboxMapSdk javadocDeps dependenciesList.mapboxMapSdk testImplementation dependenciesList.junit diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.java b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.java deleted file mode 100644 index 4c208c1fb..000000000 --- a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mapbox.pluginstylejson; - -public class StyleJsonContants { - public static final String LAYER_BACKGROUND = "background"; - public static final String LAYER_CYCLE = "cycle"; - public static final String LAYER_CUSTOM = "custom"; - public static final String LAYER_FILL_EXTRUSION = "fillextrusion"; - public static final String LAYER_FILL = "fill"; - public static final String LAYER_HEATMAP = "heatmap"; - public static final String LAYER_HILLSHADE = "hillshade"; - public static final String LAYER_LINE = "line"; - public static final String LAYER_RASTER = "raster"; - public static final String LAYER_SYMBOL = "symbol"; - public static final String SOURCE_CUSTOM_GEOMETRY = "custom geometry"; - public static final String SOURCE_GEO_JSON = "geojson"; - public static final String SOURCE_IMAGE = "image"; - public static final String SOURCE_RASTER_DEM = "rasterdem"; - public static final String SOURCE_RASTER = "raster"; - public static final String SOURCE_UNKNOW = "unknow"; - public static final String SOURCE_VECTOR = "vector"; -} diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.kt b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.kt new file mode 100644 index 000000000..551b89fd5 --- /dev/null +++ b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.kt @@ -0,0 +1,31 @@ +package com.mapbox.pluginstylejson + +object StyleJsonContants { + val LAYER_BACKGROUND = "background" + val LAYER_CYCLE = "cycle" + val LAYER_CUSTOM = "custom" + val LAYER_FILL_EXTRUSION = "fillextrusion" + val LAYER_FILL = "fill" + val LAYER_HEATMAP = "heatmap" + val LAYER_HILLSHADE = "hillshade" + val LAYER_LINE = "line" + val LAYER_RASTER = "raster" + val LAYER_SYMBOL = "symbol" + val SOURCE_CUSTOM_GEOMETRY = "custom geometry" + val SOURCE_GEO_JSON = "geojson" + val SOURCE_IMAGE = "image" + val SOURCE_RASTER_DEM = "rasterdem" + val SOURCE_RASTER = "raster" + val SOURCE_UNKNOW = "unknow" + val SOURCE_VECTOR = "vector" + + const val GEO_JSON_FEATURE = "Feature" + const val GEO_JSON_FEATURE_COLLECTION = "FeatureCollection" + const val GEO_JSON_GEOMETRY_COLLECTION = "GeometryCollection" + const val GEO_JSON_LINE_STRING = "LineString" + const val GEO_JSON_NULTI_LINE_STRING = "MultiLineString" + const val GEO_JSON_MULTI_POINT = "MultiPoint" + const val GEO_JSON_MULTI_POLYGON = "MultiPolygon" + const val GEO_JSON_POINT = "Point" + const val GEO_JSON_POLYGON = "Polygon" +} diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.java b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.java deleted file mode 100644 index 30ba38ef2..000000000 --- a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.mapbox.pluginstylejson; - -import android.support.annotation.NonNull; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.mapbox.geojson.Feature; -import com.mapbox.geojson.FeatureCollection; -import com.mapbox.geojson.GeometryCollection; -import com.mapbox.geojson.LineString; -import com.mapbox.geojson.MultiLineString; -import com.mapbox.geojson.MultiPoint; -import com.mapbox.geojson.MultiPolygon; -import com.mapbox.geojson.Point; -import com.mapbox.geojson.Polygon; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; - -public class StyleJsonParser { - private Gson gson = new Gson(); - - GeoJsonSource parserGeoJsonSource(@NonNull String id, @NonNull String json) { - GeoJsonSource geoJsonSource = new GeoJsonSource(id); - JsonObject source = gson.fromJson(json, JsonObject.class); - if (source.has("data")) { - JsonObject data = source.getAsJsonObject("data"); - String dataString = data.getAsString(); - if (dataString.startsWith("http")) { - geoJsonSource.setUrl(dataString); - } else { - String type = data.get("type").getAsString(); - if ("Feature".equals(type)) { - geoJsonSource.setGeoJson(Feature.fromJson(dataString)); - } else if ("FeatureCollection".equals(type)) { - geoJsonSource.setGeoJson(FeatureCollection.fromJson(dataString)); - } else if ("GeometryCollection".equals(type)) { - geoJsonSource.setGeoJson(GeometryCollection.fromJson(dataString)); - } else if ("LineString".equals(type)) { - geoJsonSource.setGeoJson(LineString.fromJson(dataString)); - } else if ("MultiLineString".equals(type)) { - geoJsonSource.setGeoJson(MultiLineString.fromJson(dataString)); - } else if ("MultiPoint".equals(type)) { - geoJsonSource.setGeoJson(MultiPoint.fromJson(dataString)); - } else if ("MultiPolygon".equals(type)) { - geoJsonSource.setGeoJson(MultiPolygon.fromJson(dataString)); - } else if ("Point".equals(type)) { - geoJsonSource.setGeoJson(Point.fromJson(dataString)); - } else if ("Polygon".equals(type)) { - geoJsonSource.setGeoJson(Polygon.fromJson(dataString)); - } - } - } - - return geoJsonSource; - } -} diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.kt b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.kt new file mode 100644 index 000000000..17abede38 --- /dev/null +++ b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.kt @@ -0,0 +1,51 @@ +package com.mapbox.pluginstylejson + +import com.google.gson.Gson +import com.google.gson.JsonObject +import com.mapbox.geojson.* +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource +import com.mapbox.mapboxsdk.style.sources.VectorSource +import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_FEATURE +import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_FEATURE_COLLECTION +import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_GEOMETRY_COLLECTION +import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_LINE_STRING +import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_MULTI_POINT +import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_MULTI_POLYGON +import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_NULTI_LINE_STRING +import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_POINT +import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_POLYGON + +class StyleJsonParser { + private val gson = Gson() + + internal fun parserGeoJsonSource(id: String, json: String): GeoJsonSource { + val geoJsonSource = GeoJsonSource(id) + val source = gson.fromJson(json, JsonObject::class.java) + if (source.has("data")) { + val data = source.getAsJsonObject("data") + val dataString = data.asString + if (dataString.startsWith("http")) { + geoJsonSource.url = dataString + } else { + val type = data.get("type").asString + when (type) { + GEO_JSON_FEATURE -> geoJsonSource.setGeoJson(Feature.fromJson(dataString)) + GEO_JSON_FEATURE_COLLECTION -> geoJsonSource.setGeoJson(FeatureCollection.fromJson(dataString)) + GEO_JSON_GEOMETRY_COLLECTION -> geoJsonSource.setGeoJson(GeometryCollection.fromJson(dataString)) + GEO_JSON_LINE_STRING -> geoJsonSource.setGeoJson(LineString.fromJson(dataString)) + GEO_JSON_NULTI_LINE_STRING -> geoJsonSource.setGeoJson(MultiLineString.fromJson(dataString)) + GEO_JSON_MULTI_POINT -> geoJsonSource.setGeoJson(MultiPoint.fromJson(dataString)) + GEO_JSON_MULTI_POLYGON -> geoJsonSource.setGeoJson(MultiPolygon.fromJson(dataString)) + GEO_JSON_POINT -> geoJsonSource.setGeoJson(Point.fromJson(dataString)) + GEO_JSON_POLYGON -> geoJsonSource.setGeoJson(Polygon.fromJson(dataString)) + } + } + } + + return geoJsonSource + } + + internal fun parserVectorSource(id: String, json: String): VectorSource { + + } +} From 2b46e23d952e063ddac6efaf60369c996bc7a720 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 3 Jun 2019 15:19:21 +0800 Subject: [PATCH 4/4] add StyleJsonPlugin.kt --- .../mapbox/pluginstylejson/LayerJsonParser.kt | 48 +++++++++++++ ...StyleJsonParser.kt => SourceJsonParser.kt} | 32 ++++++--- .../pluginstylejson/StyleJsonContants.kt | 1 - .../mapbox/pluginstylejson/StyleJsonPlugin.kt | 70 +++++++++++++++++++ 4 files changed, 140 insertions(+), 11 deletions(-) create mode 100644 plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/LayerJsonParser.kt rename plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/{StyleJsonParser.kt => SourceJsonParser.kt} (70%) create mode 100644 plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonPlugin.kt diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/LayerJsonParser.kt b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/LayerJsonParser.kt new file mode 100644 index 000000000..9be45a804 --- /dev/null +++ b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/LayerJsonParser.kt @@ -0,0 +1,48 @@ +package com.mapbox.pluginstylejson + +import com.google.gson.JsonObject +import com.mapbox.mapboxsdk.style.layers.* + +class LayerJsonParser { + + internal fun parserBackgroundLayer(id: String, json: JsonObject): BackgroundLayer { + return BackgroundLayer(id) + } + + internal fun parserCircleLayer(id: String, json: JsonObject): CircleLayer { + return CircleLayer(id, "") + } + + internal fun parserCustomLayer(id: String, json: JsonObject): CustomLayer { + return CustomLayer(id, 0) + } + + internal fun parserFillExtrusionLayer(id: String, json: JsonObject): FillExtrusionLayer { + return FillExtrusionLayer(id, "") + } + + internal fun parserFillLayer(id: String, json: JsonObject): FillLayer { + return FillLayer(id, "") + } + + internal fun parserHeatmapLayer(id: String, json: JsonObject): HeatmapLayer { + return HeatmapLayer(id, "") + } + + internal fun parserHillshadeLayer(id: String, json: JsonObject): HillshadeLayer { + return HillshadeLayer(id, "") + } + + internal fun parserLineLayer(id: String, json: JsonObject): LineLayer { + return LineLayer(id, "") + } + + internal fun parserRasterLayer(id: String, json: JsonObject): RasterLayer { + return RasterLayer(id, "") + } + + internal fun parserSymbolLayer(id: String, json: JsonObject): SymbolLayer { + return SymbolLayer(id, "") + } + +} \ No newline at end of file diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.kt b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/SourceJsonParser.kt similarity index 70% rename from plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.kt rename to plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/SourceJsonParser.kt index 17abede38..13ed83570 100644 --- a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonParser.kt +++ b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/SourceJsonParser.kt @@ -1,10 +1,8 @@ package com.mapbox.pluginstylejson -import com.google.gson.Gson import com.google.gson.JsonObject import com.mapbox.geojson.* -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource -import com.mapbox.mapboxsdk.style.sources.VectorSource +import com.mapbox.mapboxsdk.style.sources.* import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_FEATURE import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_FEATURE_COLLECTION import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_GEOMETRY_COLLECTION @@ -15,14 +13,12 @@ import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_NULTI_LINE_STRING import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_POINT import com.mapbox.pluginstylejson.StyleJsonContants.GEO_JSON_POLYGON -class StyleJsonParser { - private val gson = Gson() +class SourceJsonParser { - internal fun parserGeoJsonSource(id: String, json: String): GeoJsonSource { + internal fun parserGeoJsonSource(id: String, json: JsonObject): GeoJsonSource { val geoJsonSource = GeoJsonSource(id) - val source = gson.fromJson(json, JsonObject::class.java) - if (source.has("data")) { - val data = source.getAsJsonObject("data") + if (json.has("data")) { + val data = json.getAsJsonObject("data") val dataString = data.asString if (dataString.startsWith("http")) { geoJsonSource.url = dataString @@ -45,7 +41,23 @@ class StyleJsonParser { return geoJsonSource } - internal fun parserVectorSource(id: String, json: String): VectorSource { + internal fun parserVectorSource(id: String, json: JsonObject): VectorSource { + return VectorSource(id, "") + } + + internal fun parserCustomGeometrySource(id: String, json: JsonObject): CustomGeometrySource { + return CustomGeometrySource(id, null) + } + + internal fun parserImageSource(id: String, json: JsonObject): ImageSource { + return ImageSource(id, null, 0) + } + + internal fun parserRasterDemSource(id: String, json: JsonObject): RasterDemSource { + return RasterDemSource(id, "") + } + internal fun parserRasterSource(id: String, json: JsonObject): RasterSource { + return RasterSource(id, "") } } diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.kt b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.kt index 551b89fd5..bce3a1823 100644 --- a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.kt +++ b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonContants.kt @@ -16,7 +16,6 @@ object StyleJsonContants { val SOURCE_IMAGE = "image" val SOURCE_RASTER_DEM = "rasterdem" val SOURCE_RASTER = "raster" - val SOURCE_UNKNOW = "unknow" val SOURCE_VECTOR = "vector" const val GEO_JSON_FEATURE = "Feature" diff --git a/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonPlugin.kt b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonPlugin.kt new file mode 100644 index 000000000..cb7cec68a --- /dev/null +++ b/plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonPlugin.kt @@ -0,0 +1,70 @@ +package com.mapbox.pluginstylejson + +import com.google.gson.Gson +import com.google.gson.JsonObject +import com.mapbox.mapboxsdk.style.layers.Layer +import com.mapbox.mapboxsdk.style.sources.Source +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_BACKGROUND +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_CUSTOM +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_CYCLE +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_FILL +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_FILL_EXTRUSION +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_HEATMAP +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_HILLSHADE +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_LINE +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_RASTER +import com.mapbox.pluginstylejson.StyleJsonContants.LAYER_SYMBOL +import com.mapbox.pluginstylejson.StyleJsonContants.SOURCE_CUSTOM_GEOMETRY +import com.mapbox.pluginstylejson.StyleJsonContants.SOURCE_GEO_JSON +import com.mapbox.pluginstylejson.StyleJsonContants.SOURCE_IMAGE +import com.mapbox.pluginstylejson.StyleJsonContants.SOURCE_RASTER +import com.mapbox.pluginstylejson.StyleJsonContants.SOURCE_RASTER_DEM +import com.mapbox.pluginstylejson.StyleJsonContants.SOURCE_VECTOR + +class StyleJsonPlugin { + private val gson = Gson() + private val layerJsonParser = LayerJsonParser() + private val sourceJsonParser = SourceJsonParser() + + fun parserLayer(content: String): Layer? { + val source = gson.fromJson(content, JsonObject::class.java) + val id = source.get("id") + id?.let { + val type = source.get("type") + type?.let { + return when (type.asString) { + LAYER_BACKGROUND -> layerJsonParser.parserBackgroundLayer(id.asString, source) + LAYER_CYCLE -> layerJsonParser.parserCircleLayer(id.asString, source) + LAYER_CUSTOM -> layerJsonParser.parserCustomLayer(id.asString, source) + LAYER_FILL_EXTRUSION -> layerJsonParser.parserFillExtrusionLayer(id.asString, source) + LAYER_FILL -> layerJsonParser.parserFillLayer(id.asString, source) + LAYER_HEATMAP -> layerJsonParser.parserHeatmapLayer(id.asString, source) + LAYER_HILLSHADE -> layerJsonParser.parserHillshadeLayer(id.asString, source) + LAYER_LINE -> layerJsonParser.parserLineLayer(id.asString, source) + LAYER_RASTER -> layerJsonParser.parserRasterLayer(id.asString, source) + LAYER_SYMBOL -> layerJsonParser.parserSymbolLayer(id.asString, source) + else -> null + } + } + } + return null + } + + fun parserSource(id: String, content: String): Source? { + val source = gson.fromJson(content, JsonObject::class.java) + val type = source.get("type") + type?.let { + return when (type.asString) { + SOURCE_CUSTOM_GEOMETRY -> sourceJsonParser.parserCustomGeometrySource(id, source) + SOURCE_GEO_JSON -> sourceJsonParser.parserGeoJsonSource(id, source) + SOURCE_IMAGE -> sourceJsonParser.parserImageSource(id, source) + SOURCE_RASTER_DEM -> sourceJsonParser.parserRasterDemSource(id, source) + SOURCE_RASTER -> sourceJsonParser.parserRasterSource(id, source) + SOURCE_VECTOR -> sourceJsonParser.parserVectorSource(id, source) + else -> null + } + } + return null + } + +} \ No newline at end of file