Skip to content

Commit 92ac87f

Browse files
RD-1384: Add raster demo (#96)
1 parent 1a4c205 commit 92ac87f

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

.github/workflows/autopr.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,35 @@ jobs:
8787
prompt: |
8888
Implement ticket ${{ env.ISSUE_KEY }}: ${{ env.TITLE }}. ${{ env.DESC }}
8989
90+
# Run unit tests and capture output; don't fail the job yet
91+
- name: Run unit tests
92+
id: unit_tests
93+
continue-on-error: true
94+
run: |
95+
set -o pipefail
96+
status=0
97+
./gradlew -Dorg.gradle.daemon=false :MapTilerSDK:test 2>&1 | tee test.log || status=$?
98+
echo "exit_code=$status" >> $GITHUB_OUTPUT
99+
100+
# If tests failed, run Codex again with the test log to apply fixes
101+
- name: Run Codex Action (Fix tests)
102+
if: ${{ steps.unit_tests.outputs.exit_code != '0' }}
103+
uses: openai/codex-action@v1
104+
env:
105+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
106+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
with:
109+
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
110+
prompt: |
111+
Unit tests failed (exit=${{ steps.unit_tests.outputs.exit_code }}).
112+
Read ./test.log from the workspace and fix the failures with minimal, focused changes.
113+
Follow AGENTS.md rules strictly.
114+
115+
# Auto-format Kotlin code to satisfy ktlint after possible fixes
116+
- name: Gradle ktlintFormat
117+
run: ./gradlew -Dorg.gradle.daemon=false ktlintFormat
118+
90119
# Commit any changes produced by Codex
91120

92121
- name: Commit changes

Examples/MapTilerMobileDemo/app/src/main/java/com/maptilerdemo/maptilermobiledemo/HomeScreen.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ import com.maptiler.maptilersdk.map.style.MTStyleError
5151
import com.maptiler.maptilersdk.map.style.layer.MTLayerType
5252
import com.maptiler.maptilersdk.map.style.layer.fill.MTFillLayer
5353
import com.maptiler.maptilersdk.map.style.layer.line.MTLineLayer
54+
import com.maptiler.maptilersdk.map.style.layer.raster.MTRasterLayer
5455
import com.maptiler.maptilersdk.map.style.layer.symbol.MTSymbolLayer
56+
import com.maptiler.maptilersdk.map.style.source.MTRasterTileSource
5557
import com.maptiler.maptilersdk.map.style.source.MTVectorTileSource
5658
import com.maptiler.maptilersdk.map.types.MTData
5759
import java.net.URL
@@ -182,6 +184,27 @@ fun HomeScreen(
182184
} catch (error: MTStyleError) {
183185
Log.e("MTStyleError", "Line Layer already exists.")
184186
}
187+
} else if (type == MTLayerType.RASTER) {
188+
val mapTilerAPIKey = MTConfig.apiKey
189+
val rasterUrl = URL("https://api.maptiler.com/tiles/satellite/tiles.json?key=$mapTilerAPIKey")
190+
val rasterSourceId = "satellitesource"
191+
192+
// Add or reuse the raster source
193+
try {
194+
val rasterSource = MTRasterTileSource(rasterSourceId, rasterUrl)
195+
mapController.controller.style?.addSource(rasterSource)
196+
} catch (error: MTStyleError) {
197+
Log.e("MTStyleError", "Raster Source already exists.")
198+
}
199+
200+
// Add the raster layer (set opacity 0.7)
201+
try {
202+
val rasterLayer = MTRasterLayer("rasterLayer", rasterSourceId)
203+
rasterLayer.opacity = 0.7
204+
mapController.controller.style?.addLayer(rasterLayer)
205+
} catch (error: MTStyleError) {
206+
Log.e("MTStyleError", "Raster Layer already exists.")
207+
}
185208
}
186209
},
187210
modifier =

Examples/MapTilerMobileDemo/app/src/main/java/com/maptilerdemo/maptilermobiledemo/LayerControl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ fun LayerControl(
7575
text = { Text("Line", color = Color.Black) },
7676
onClick = { onSelect(MTLayerType.LINE) },
7777
)
78+
79+
DropdownMenuItem(
80+
text = { Text("Raster", color = Color.Black) },
81+
onClick = { onSelect(MTLayerType.RASTER) },
82+
)
7883
}
7984
}
8085
}

MapTilerSDK/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ plugins {
1616
signing
1717
}
1818

19-
tasks.named("ktlintFormat") {
20-
enabled = false
21-
}
19+
// Keep ktlintFormat enabled so it can be invoked explicitly by CI or developers.
2220

2321
tasks.register<Copy>("copyPreCommitHook") {
2422
description = "Copy pre-commit git hook from the scripts to the .git/hooks folder."

MapTilerSDK/src/main/java/com/maptiler/maptilersdk/commands/style/AddLayer.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.maptiler.maptilersdk.helpers.JsonConfig
1414
import com.maptiler.maptilersdk.map.style.layer.MTLayer
1515
import com.maptiler.maptilersdk.map.style.layer.fill.MTFillLayer
1616
import com.maptiler.maptilersdk.map.style.layer.line.MTLineLayer
17+
import com.maptiler.maptilersdk.map.style.layer.raster.MTRasterLayer
1718
import com.maptiler.maptilersdk.map.style.layer.symbol.MTSymbolLayer
1819

1920
internal data class AddLayer(
@@ -28,6 +29,8 @@ internal data class AddLayer(
2829
handleFillLayer(layer)
2930
} else if (layer is MTLineLayer) {
3031
handleLineLayer(layer)
32+
} else if (layer is MTRasterLayer) {
33+
handleRasterLayer(layer)
3134
} else {
3235
// Fallback to a generic addLayer for any future-supported layer types
3336
val layerString: JSString = JsonConfig.json.encodeToString(layer)
@@ -70,4 +73,10 @@ internal data class AddLayer(
7073

7174
return "${MTBridge.MAP_OBJECT}.addLayer($layerString);"
7275
}
76+
77+
private fun handleRasterLayer(layer: MTRasterLayer): JSString {
78+
val layerString: JSString = JsonConfig.json.encodeToString(layer)
79+
80+
return "${MTBridge.MAP_OBJECT}.addLayer($layerString);"
81+
}
7382
}

0 commit comments

Comments
 (0)