-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kevin
committed
Jun 3, 2019
1 parent
68234f6
commit 8483e57
Showing
4 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/LayerJsonParser.kt
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,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, "") | ||
} | ||
|
||
} |
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
70 changes: 70 additions & 0 deletions
70
plugin-stylejson/src/main/java/com/mapbox/pluginstylejson/StyleJsonPlugin.kt
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 @@ | ||
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<JsonObject>(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<JsonObject>(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 | ||
} | ||
|
||
} |