• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Add Custom Style Layers

This example shows how to add customize style layer.

  • Query features in Rect

  • Add a list of features layer into map style

  • Add Multi Shape Layers source

    • Circle style layer

    • Line style layer

    • Fill style layer

docs-image

For all code examples, refer to Maps Code Examples

AddMapStyleLayerViewController view source

1//
2// AddMapStyleLayerViewController.swift
3// maps-ios-demo
4//
5import Foundation
6import UIKit
7import Nbmap
8enum AddActionType{
9 case AddQueryFeaturesLayer
10 case AddMultiShapeLayers
11 case UpdateMultiShapeLayers
12}
13class AddMapStyleLayerViewController: UIViewController {
14
15 var nbMapView: NGLMapView! {
16 didSet {
17 oldValue?.removeFromSuperview()
18 if let mapView = nbMapView {

This code example defines a view controller (AddMapStyleLayerViewController) that manages a map view (NGLMapView) and provides functionality to add different types of map style layers. It includes methods for adding query features layers and multi-shape layers to the map view. The code uses various classes and protocols from the Nbmap framework to handle map-related operations and display map features.

  • Initializing the mapView:

    • The nbMapView property is declared as an NGLMapView.

    • In the viewDidLoad() method, the nbMapView is initialized with a frame equal to the bounds of the view.

    • The mapView is added as a subview to the view.

  • Adding Query Features Layer:

    • A query rectangle is defined based on the bounds of the nbMapView.

    • Visible features within the query rectangle are retrieved using the visibleFeatures(in:) method. The existing query source and layer are removed from the nbMapView style, if they exist.

    • A new NGLShapeSource is created with the visible features and added to the style. And a NGLFillStyleLayer is created with the NGLShapeSource and customized properties such as fill color and opacity.

    • The fill layer is added to the style.

  • Adding NGLPolygonFeature Layer:

    • An array of CLLocationCoordinate2D is created to define the leaf coordinates for a polygon feature.

    • A NGLPolygonFeature is created with the leaf coordinates and additional attributes.

    • A NGLShapeSource is created with the polygon feature and added to the style if it doesn't already exist. A NGLFillStyleLayer is created with the shape source, and properties such as fill color and predicate.

    • The fill layer is added to the style.

  • Adding GeoJson Source Layer

    • A GeoJSON string is defined to create a point feature, and a NGLShape is created from the GeoJSON data.

    • A NGLShapeSource is created with the shape and added to the style if it doesn't already exist.

    • A NGLCircleStyleLayer is created with the point source, and properties such as circle color and predicate.

    • The circle layer is added to the style.

  • Adding NGLPolyline feature layer

    • An array of CLLocationCoordinate2D is created to define the square coordinates for a polyline.

    • A NGLPolyline is created with the square coordinates.

    • A NGLShapeSource is created with the polyline and added to the style if it doesn't already exist.

    • A NGLLineStyleLayer is created with the plain shape source, and properties such as line color and width.

    • The line layer is added to the style.

Have Questions ?