This method in the Baidu map demo bus Search a class of files;
The parameter is a polyline that is connected to all the callout points, which can change the extent of the map display, and show the optimal display scale (pro-test in your own project)
Set the map extent according to Polyline
func mapviewfitpolyline (polyline: bmkpolyline!) {
if polyline. Pointcount < 1 {
return
}
let pt = polyline. Points[0]
var ltX = pt.x
var rbX = pt.x
var lty = pt.y
var rby = pt.y
for i in 1.. <polyline. pointcount {
let pt = polyline. Points[Int(i)]
if pt.x < LtX {
LtX = pt.x
}
if pt.x > RbX {
RbX = pt.x
}
if pt.y > lty {
Lty = pt.y
}
if pt.y < Rby {
Rby = pt.y
}
}
let rect = bmkmaprectmake(LtX, Lty, Rbx-ltx, rby-lty)
Mapview!. visiblemaprect = rect
Mapview!. zoomlevel = mapview!. zoomlevel - 0.3
}
Let the map display the range (Swift) based on the callout point