Skip to content

Commit

Permalink
feat: add zoomInto for drawManually in iOS side
Browse files Browse the repository at this point in the history
  • Loading branch information
liodali committed Feb 19, 2022
1 parent 0dcd701 commit a6edbcf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
35 changes: 23 additions & 12 deletions ios/Classes/MyMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,12 @@ public class MyMapView: NSObject, FlutterPlatformView, CLLocationManagerDelegate

}
roadManager.drawMultiRoadsOnMap(on: roads, for: mapView)
let infos = roadInfos.filter { info in info != nil }.map {info -> [String:Any] in
let infos = roadInfos.filter { info in
info != nil
}
.map { info -> [String: Any] in
info!.toMap()
}
}
result(infos)
}

Expand Down Expand Up @@ -551,7 +554,7 @@ public class MyMapView: NSObject, FlutterPlatformView, CLLocationManagerDelegate
if (homeMarker != nil) {
homeMarker?.visible = false
let isExist = mapView.markers.contains(homeMarker!)
if (isExist ) {
if (isExist) {
mapView.markerRemove(homeMarker!)
}
homeMarker = nil
Expand Down Expand Up @@ -625,20 +628,20 @@ public class MyMapView: NSObject, FlutterPlatformView, CLLocationManagerDelegate
group.leave()
}
}
group.notify(queue: .main ) {
group.notify(queue: .main) {
var informations = [RoadInformation?]()
var roads = [(Road,RoadData)?]()
for (index , res) in results.enumerated() {
var roadInfo:RoadInformation? = nil
var routeToDraw:(Road,RoadData)? = nil
var roads = [(Road, RoadData)?]()
for (index, res) in results.enumerated() {
var roadInfo: RoadInformation? = nil
var routeToDraw: (Road, RoadData)? = nil
if let road = res {
routeToDraw = (road,roadConfigs[index].roadData)
roadInfo = RoadInformation(distance: road.distance, seconds: road.duration, encodedRoute: road.mRouteHigh)
routeToDraw = (road, roadConfigs[index].roadData)
roadInfo = RoadInformation(distance: road.distance, seconds: road.duration, encodedRoute: road.mRouteHigh)
}
informations.append(roadInfo)
roads.append(routeToDraw)
}
completion(informations,roads,nil)
completion(informations, roads, nil)
}

}
Expand Down Expand Up @@ -747,16 +750,24 @@ public class MyMapView: NSObject, FlutterPlatformView, CLLocationManagerDelegate
if (args.keys.contains("roadWidth")) {
roadWidth = "\(args["roadWidth"] as! Double)px"
}
let zoomInto = args["zoomInto"] as! Bool
if (roadMarkerPolyline != nil) {
mapView.markerRemove(roadMarkerPolyline!)
roadMarkerPolyline = nil
}
var road = Road()
road.mRouteHigh = roadEncoded
road.roadData = RoadData(roadColor: roadColor, roadWidth: roadWidth)
let route = Polyline(encodedPolyline: road.mRouteHigh, precision: 1e5)

let markerRoad = roadManager.drawRoadOnMap(on: road, for: mapView)
let markerRoad = roadManager.drawRoadOnMap(on: road, for: mapView,polyLine: route)
roadMarkerPolyline = markerRoad
if (zoomInto) {
let box = route.coordinates!.toBounds()
mapView.cameraPosition = mapView.cameraThatFitsBounds(box, withPadding: UIEdgeInsets.init(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0))
}


result(nil)
}

Expand Down
11 changes: 7 additions & 4 deletions ios/Classes/RoadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protocol PRoadManager {

func getRoad(wayPoints: [String], typeRoad: RoadType, handler: @escaping RoadHandler)

func drawRoadOnMap (on road:Road,for map:TGMapView) -> TGMarker
func drawRoadOnMap (on road:Road,for map:TGMapView,polyLine:Polyline? ) -> TGMarker

}

Expand Down Expand Up @@ -85,15 +85,18 @@ class RoadManager: PRoadManager {
}
}

public func drawRoadOnMap(on road: Road, for map: TGMapView) -> TGMarker {
public func drawRoadOnMap(on road: Road, for map: TGMapView,polyLine:Polyline? = nil) -> TGMarker {
if(lastMarkerRoad != nil){
map.markerRemove(lastMarkerRoad!)
}
let marker = map.markerAdd()
marker.stylingString = "{ style: 'lines',interactive: false, color: '\(road.roadData.roadColor)', width: \(road.roadData.roadWidth), order: 1500 }"

let route = Polyline(encodedPolyline: road.mRouteHigh, precision: 1e5)
let tgPolyline = TGGeoPolyline(coordinates: route.coordinates!,count: UInt(route.coordinates!.count))
var route = polyLine
if(route == nil){
route = Polyline(encodedPolyline: road.mRouteHigh, precision: 1e5)
}
let tgPolyline = TGGeoPolyline(coordinates: route!.coordinates!,count: UInt(route!.coordinates!.count))
marker.polyline = tgPolyline
lastMarkerRoad = marker
return marker
Expand Down

0 comments on commit a6edbcf

Please sign in to comment.