Skip to content

Commit

Permalink
add_local_asset_for_picture_marker_symbol (#58)
Browse files Browse the repository at this point in the history
* catch exceptions while parsing and fix poliline on mobile

* add missing return

* implement feature

* implement feature

* add example on button click

* add support for local asset android

* add support for local asset android

* fix logic

* implement iOS

* reformat

* review

* update README.md and add button for example only on mobile

* fix ios build

* resolve conflicts

* reformat code

---------

Co-authored-by: Julian Bissekkou <[email protected]>
  • Loading branch information
sbergmair and JulianBissekkou authored Feb 26, 2024
1 parent 6dca8cd commit 9e32426
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ArcgisMapPlugin : FlutterPlugin {
.platformViewRegistry
.registerViewFactory(
"<native_map_view>",
ArcgisMapViewFactory(flutterPluginBinding.binaryMessenger)
ArcgisMapViewFactory(flutterPluginBinding)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment
import com.esri.arcgisruntime.geometry.Geometry
import com.esri.arcgisruntime.geometry.GeometryEngine
import com.esri.arcgisruntime.geometry.Multipoint
import com.esri.arcgisruntime.geometry.Point
import com.esri.arcgisruntime.geometry.PointCollection
import com.esri.arcgisruntime.geometry.Polyline
Expand Down Expand Up @@ -35,7 +33,7 @@ import dev.fluttercommunity.arcgis_map_sdk_android.model.LatLng
import dev.fluttercommunity.arcgis_map_sdk_android.model.UserPosition
import dev.fluttercommunity.arcgis_map_sdk_android.model.ViewPadding
import dev.fluttercommunity.arcgis_map_sdk_android.util.GraphicsParser
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
Expand All @@ -52,20 +50,21 @@ import kotlin.math.roundToInt
internal class ArcgisMapView(
private val context: Context,
private val viewId: Int,
private val binaryMessenger: BinaryMessenger,
private val mapOptions: ArcgisMapOptions,
private val binding: FlutterPluginBinding,
) : PlatformView {

private val view: View = LayoutInflater.from(context).inflate(R.layout.vector_map_view, null)
private var mapView: MapView
private val map = ArcGISMap()
private val defaultGraphicsOverlay = GraphicsOverlay()
private val graphicsParser = GraphicsParser(binding)

private lateinit var zoomStreamHandler: ZoomStreamHandler
private lateinit var centerPositionStreamHandler: CenterPositionStreamHandler

private val methodChannel =
MethodChannel(binaryMessenger, "dev.fluttercommunity.arcgis_map_sdk/$viewId")
MethodChannel(binding.binaryMessenger, "dev.fluttercommunity.arcgis_map_sdk/$viewId")

override fun getView(): View = view

Expand Down Expand Up @@ -302,7 +301,7 @@ internal class ArcgisMapView(
) {
try {
val map = call.arguments as Map<String, Any>
val symbol = GraphicsParser.parseSymbol(map)
val symbol = graphicsParser.parseSymbol(map)
function(symbol)
result.success(true)
} catch (e: Throwable) {
Expand All @@ -315,16 +314,23 @@ internal class ArcgisMapView(
zoomStreamHandler = ZoomStreamHandler()
centerPositionStreamHandler = CenterPositionStreamHandler()

EventChannel(binaryMessenger, "dev.fluttercommunity.arcgis_map_sdk/$viewId/zoom")
EventChannel(binding.binaryMessenger, "dev.fluttercommunity.arcgis_map_sdk/$viewId/zoom")
.setStreamHandler(zoomStreamHandler)

EventChannel(binaryMessenger, "dev.fluttercommunity.arcgis_map_sdk/$viewId/centerPosition")
EventChannel(
binding.binaryMessenger,
"dev.fluttercommunity.arcgis_map_sdk/$viewId/centerPosition"
)
.setStreamHandler(centerPositionStreamHandler)
}

private fun onZoomIn(call: MethodCall, result: MethodChannel.Result) {
if (mapView.mapScale.isNaN()) {
result.error("Error", "MapView.mapScale is NaN. Maybe the map is not completely loaded.", null)
result.error(
"Error",
"MapView.mapScale is NaN. Maybe the map is not completely loaded.",
null
)
return
}

Expand All @@ -348,7 +354,11 @@ internal class ArcgisMapView(

private fun onZoomOut(call: MethodCall, result: MethodChannel.Result) {
if (mapView.mapScale.isNaN()) {
result.error("Error", "MapView.mapScale is NaN. Maybe the map is not completely loaded.", null)
result.error(
"Error",
"MapView.mapScale is NaN. Maybe the map is not completely loaded.",
null
)
return
}

Expand Down Expand Up @@ -396,7 +406,7 @@ internal class ArcgisMapView(
val graphicArguments = call.arguments as Map<String, Any>
lateinit var newGraphic: List<Graphic>
try {
newGraphic = GraphicsParser.parse(graphicArguments)
newGraphic = graphicsParser.parse(graphicArguments)
} catch (e: Throwable) {
result.error("unknown_error", "Error while adding graphic. $e)", null)
return
Expand Down Expand Up @@ -480,8 +490,9 @@ internal class ArcgisMapView(
SpatialReferences.getWgs84()
)

val future = if (padding != null) mapView.setViewpointGeometryAsync(polyline.extent, padding)
else mapView.setViewpointGeometryAsync(polyline.extent)
val future =
if (padding != null) mapView.setViewpointGeometryAsync(polyline.extent, padding)
else mapView.setViewpointGeometryAsync(polyline.extent)

future.addDoneListener {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package dev.fluttercommunity.arcgis_map_sdk_android

import android.content.Context
import dev.fluttercommunity.arcgis_map_sdk_android.model.ArcgisMapOptions
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory

class ArcgisMapViewFactory(private val binaryMessenger: BinaryMessenger) :
class ArcgisMapViewFactory(private val flutterPluginBinding: FlutterPluginBinding) :
PlatformViewFactory(StandardMessageCodec.INSTANCE) {
override fun create(context: Context?, viewId: Int, args: Any?): PlatformView {
val optionParams = args as Map<String, Any>
val params = optionParams.parseToClass<ArcgisMapOptions>()

return ArcgisMapView(context!!, viewId, binaryMessenger, params)
return ArcgisMapView(context!!, viewId, params, flutterPluginBinding)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.fluttercommunity.arcgis_map_sdk_android.model.symbol

data class PictureMarkerSymbolPayload(
val url: String,
val assetUri: String,
val width: Double,
val height: Double,
val xOffset: Int,
Expand Down
Loading

0 comments on commit 9e32426

Please sign in to comment.