aboutsummaryrefslogtreecommitdiff
path: root/iosApp/iosApp/Map/MapViewController.swift
diff options
context:
space:
mode:
Diffstat (limited to 'iosApp/iosApp/Map/MapViewController.swift')
-rw-r--r--iosApp/iosApp/Map/MapViewController.swift103
1 files changed, 101 insertions, 2 deletions
diff --git a/iosApp/iosApp/Map/MapViewController.swift b/iosApp/iosApp/Map/MapViewController.swift
index f068bf4..3c38b89 100644
--- a/iosApp/iosApp/Map/MapViewController.swift
+++ b/iosApp/iosApp/Map/MapViewController.swift
@@ -18,9 +18,23 @@
import UIKit
import WhirlyGlobe
import shared
+import GEOSwift
typealias MarkerCallback = (Int32?) -> ()
+extension Geometry {
+ func getCoordinates() -> [Point] {
+ switch self {
+ case let .polygon(polygon):
+ return polygon.exterior.points
+ case let .lineString(lineString):
+ return lineString.points
+ default:
+ return []
+ }
+ }
+}
+
class MapViewController: UIViewController {
var markerCallback: MarkerCallback? = nil
var mapLayer: MapLayer = MapLayer.companion.defaultLayer
@@ -84,6 +98,12 @@ class MapViewController: UIViewController {
}
}
+ func display(geofences: [Geofence]) {
+ mapView.runOnInit {
+ self.mapView.display(geofences: geofences)
+ }
+ }
+
func focusOn(marker: Marker) {
mapView.runOnInit {
self.mapView.focusOn(marker: marker)
@@ -206,8 +226,8 @@ class OurMaplyViewController: MaplyViewController {
let fontSize = 11.0
let colorReport = UIColor(red: 0.0, green: 0.5, blue: 0.0, alpha: 1.0)
- let colorLabel = UIColor.secondaryLabel
- let colorLabelOutline = UIColor.systemBackground
+ let colorLabel = UIColor.darkGray
+ let colorLabelOutline = UIColor.white
let vectorDesc: [AnyHashable : Any] = [
kMaplyColor: colorReport,
@@ -319,6 +339,85 @@ class OurMaplyViewController: MaplyViewController {
}
}
+ func display(geofences: [Geofence]) {
+ clear(geofences: true)
+
+ let fontSize = 11.0
+ let colorFill = UIColor(red: 0.10, green: 0.46, blue: 0.82, alpha: 1.00)
+ let colorLabel = UIColor(red: 0.10, green: 0.46, blue: 0.82, alpha: 1.00)
+ let colorLabelOutline = UIColor.white
+
+ let vectorDesc: [AnyHashable : Any] = [
+ kMaplyColor: colorFill,
+ kMaplyVecWidth: 12.0,
+ kMaplyWideVecImpl: kMaplyWideVecImplPerf
+ ]
+
+ let labelDesc: [AnyHashable : Any] = [
+ kMaplyFont: UIFont.boldSystemFont(ofSize: fontSize),
+ kMaplyTextColor: colorLabel,
+ kMaplyTextOutlineColor: colorLabelOutline,
+ kMaplyTextOutlineSize: 3.0
+ ]
+
+ let shapes = [MaplyShape]()
+ var vectors = [MaplyVectorObject]()
+ var labels = [MaplyScreenLabel]()
+
+ geofences.forEach { geofence in
+ if let area = geofence.area {
+ print ("Draw geofence with area = \(area)")
+ if let geometry = try? Geometry(wkt: area) {
+ switch geometry {
+ case .polygon(_):
+ let geoJSON: [AnyHashable : Any] = [
+ "type": "FeatureCollection",
+ "features": [
+ [
+ "type": "Feature",
+ "properties": [],
+ "geometry": [
+ "type": "Polygon",
+ "coordinates": [
+ geometry.getCoordinates().map { coordinate in
+ [coordinate.y, coordinate.x]
+ }
+ ]
+ ]
+ ]
+ ]
+ ]
+ if let vector = MaplyVectorObject(fromGeoJSONDictionary: geoJSON) {
+ vectors.append(vector)
+ }
+ default:
+ break
+ }
+
+ if let centroid = try? geometry.centroid() {
+ let label = MaplyScreenLabel()
+ label.text = geofence.name
+ label.loc = MaplyCoordinateMakeWithDegrees(Float(centroid.y),
+ Float(centroid.x))
+ label.layoutImportance = .infinity
+
+ labels.append(label)
+ }
+ }
+ }
+ }
+
+ if let objs = addShapes(shapes, desc: nil, mode: .any) {
+ geofenceObjects.append(objs)
+ }
+ if let objs = addWideVectors(vectors, desc: vectorDesc, mode: .any) {
+ geofenceObjects.append(objs)
+ }
+ if let objs = addScreenLabels(labels, desc: labelDesc, mode: .any) {
+ geofenceObjects.append(objs)
+ }
+ }
+
func setZoomLimits(minZoom: Int32, maxZoom: Int32) {
setZoomLimitsMin(
height(forMapScale: Float(truncating: