9
case StyleBuildingExtrusions
10
case StyleWaterWithFunction
11
case StyleRoadsWithFunction
12
case AddBuildingExtrusions
14
class StyleMapLayerViewController: UIViewController {
16
var nbMapView: NGLMapView! {
18
oldValue?.removeFromSuperview()
19
if let mapView = nbMapView {
20
view.insertSubview(mapView, at: 0)
21
mapView.delegate = self
28
ActionType.StyleBuildingExtrusions,
29
ActionType.AddBuildingExtrusions,
30
ActionType.StyleWaterWithFunction,
31
ActionType.StyleRoadsWithFunction,
35
var points : Array = [CLLocationCoordinate2D]()
37
override func viewDidLoad() {
39
nbMapView = NGLMapView(frame:self.view.bounds)
40
button = UIButton(type: .system)
41
button.setTitle("Settings", for: .normal)
42
button.addTarget(self, action: #selector(showSetings), for: .touchUpInside)
43
button.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
44
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: button)
47
@objc func showSetings() {
48
let tableViewController = UITableViewController(style: .plain)
49
tableViewController.tableView.delegate = self
50
tableViewController.tableView.dataSource = self
51
tableViewController.title = "Camera Settings"
52
self.present(tableViewController, animated: true)
55
func performeSettings(type: ActionType) {
57
case ActionType.StyleBuildingExtrusions :
58
styleBuildingExtrusions()
60
case ActionType.StyleWaterWithFunction :
61
styleWaterWithFunction()
63
case .StyleRoadsWithFunction:
64
styleRoadsWithFunction()
66
case .AddBuildingExtrusions:
67
addBuildingExtrusions()
73
func styleBuildingExtrusions() {
74
let layer = self.nbMapView.style?.layer(withIdentifier: "building-3d") as? NGLFillExtrusionStyleLayer
76
layer?.fillExtrusionColor = NSExpression(forConstantValue: UIColor.purple)
77
layer?.fillExtrusionOpacity = NSExpression(forConstantValue: 0.55)
80
nbMapView.setCenter(CLLocationCoordinate2DMake(12.98780156, 77.59956748), zoomLevel: 18, animated: true)
83
func addBuildingExtrusions() {
84
let source = self.nbMapView.style?.source(withIdentifier: "openmaptiles")
85
if let source = source, self.nbMapView.style?.layer(withIdentifier: "extrudedBuildings") == nil {
86
let layer = NGLFillExtrusionStyleLayer(identifier: "extrudedBuildings", source: source)
87
layer.sourceLayerIdentifier = "building"
88
layer.fillExtrusionBase = NSExpression(forConstantValue: 20)
89
layer.fillExtrusionHeight = NSExpression(forConstantValue: 50)
91
layer.fillExtrusionColor = NSExpression(forConstantValue: UIColor.red)
92
layer.fillExtrusionOpacity = NSExpression(forConstantValue: 0.75)
93
self.nbMapView.style?.addLayer(layer)
97
let camera = NGLMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(12.98780156, 77.59956748),
101
nbMapView.fly(to: camera, withDuration: 2)
105
func styleWaterWithFunction() {
107
let waterLayer = self.nbMapView.style?.layer(withIdentifier: "water") as? NGLFillStyleLayer
108
let waterColorStops: [NSNumber: UIColor] = [
115
let fillColorExpression = NSExpression(format: "ngl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", waterColorStops)
117
waterLayer?.fillColor = fillColorExpression
119
let fillAntialiasedStops: [NSNumber: Any] = [
126
waterLayer?.fillAntialiased = NSExpression(forNGLStepping: .zoomLevelVariable, from: NSExpression(forConstantValue: false), stops: NSExpression(forConstantValue: fillAntialiasedStops))
130
func styleRoadsWithFunction() {
132
let roadLayer = self.nbMapView.style?.layer(withIdentifier: "road_primary") as? NGLLineStyleLayer
133
roadLayer?.lineColor = NSExpression(forConstantValue: UIColor.black)
135
let lineWidthStops: [NSNumber: NSNumber] = [
140
let lineWidthExpression = NSExpression(format: "ngl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", lineWidthStops)
141
roadLayer?.lineWidth = lineWidthExpression
142
roadLayer?.lineGapWidth = lineWidthExpression
144
let roadLineColorStops: [NSNumber: UIColor] = [
150
roadLayer?.lineColor = NSExpression(format: "ngl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", roadLineColorStops)
152
roadLayer?.isVisible = true
156
extension StyleMapLayerViewController: NGLMapViewDelegate {
157
func mapView(_ mapView: NGLMapView, didFinishLoading style: NGLStyle){
159
nbMapView.setCenter(CLLocationCoordinate2DMake(12.97780156, 77.59656748), zoomLevel: 10, animated: true)
163
extension StyleMapLayerViewController: UITableViewDelegate, UITableViewDataSource {
165
func settingsTitlesForRaw(index: Int) -> String {
166
let type = typeList[index]
168
case ActionType.StyleBuildingExtrusions :
169
return "Style Building Extrusions"
170
case ActionType.StyleWaterWithFunction :
171
return "Style Water with function"
172
case ActionType.StyleRoadsWithFunction :
173
return "Style Roads with function"
174
case ActionType.AddBuildingExtrusions :
175
return "Add Building Extrusions"
178
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
179
return typeList.count
182
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
183
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
184
cell.textLabel?.text = settingsTitlesForRaw(index: indexPath.row)
188
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
189
tableView.isHidden = true
190
let type = typeList[indexPath.row]
191
dismissSettings(type: type)
194
func dismissSettings(type: ActionType) {
195
dismiss(animated: true)
196
performeSettings(type: type)