Vehicle Restrictions
Vehicle restrictions are the rules about which vehicles can use which roads. They have often been used to limit where vehicles such as trucks, delivery vans, and scooters can go. Climate and pollution regulations have added more rules, regarding, for example, electric vehicles (EVs) and high-emission vehicles. The Map Display SDK supports applying those restrictions to a specific vehicle as defined by the user.
The Vehicle restrictions API is available under the TomTomMap
object. To enable vehicle restrictions in your app, load the pre-defined StyleContainer.restrictionsStyle
.
map.styleContainer = .restrictionsStyle
Next, define the vehicle by importing:
import TomTomSDKCommon
This provides access to the Vehicle
protocol:
1let dimensions = try? VehicleDimensions(2 weight: Measurement.tt.kilograms(8000),3 axleWeight: Measurement.tt.kilograms(4000),4 length: Measurement.tt.millimeters(8340),5 width: Measurement.tt.millimeters(4650),6 height: Measurement.tt.millimeters(3445),7 numberOfAxles: 38)9let vehicle = Truck(10 maxSpeed: Measurement.tt.kilometersPerHour(120),11 isCommercial: false,12 combustionEngine: nil,13 electricEngine: nil,14 dimensions: dimensions,15 hazmatClasses: [.intlExplosive, .intlGeneral, .unClass2Gas, .unClass1Explosive, .unClass6Toxic],16 adrTunnelRestrictionCode: .b,17 modelID: VehicleModelID("Fancy Truck")18)
To show vehicle restrictions, it is crucial to to have the restrictions style fully applied to the map. Setting the style container is an asynchronous operation, therefore, it is imperative to asynchronously retrieve the prepared map before attempting to showcase vehicle restrictions on it:
1mapView.getMapAsync { map in2 do {3 try map.showVehicleRestrictions(vehicle: vehicle)4 } catch {5 print("Failed to show vehicle restrictions: \(error)")6 }7}
To hide restrictions:
try? map.hideVehicleRestrictions()
To apply changes after updating vehicle restriction parameters:
try? map.updateVehicle(vehicle)
Low-emission zone
A low-emission zone is enabled by default using the pre-defined StyleContainer.restrictionsStyle
.
Supported vehicle restriction types
Europe, Canada | Norway, Iceland, Sweden | US | |
No access | |||
Height limit | |||
Width limit | |||
Length limit | |||
Weight limit | |||
Axle weight limit | |||
Hazardous Materials | |||
Goods Harmful To Water | does not occur | ||
Explosive Materials | does not occur | ||
ADR (B, C, D, E) | does not occur |
UN Dangerous Goods Class
Explosives, Gases, Flammable Liquids, Flammable Solids, Oxidizing And Organix Substance, Toxic And Infectious Substance, Radioactive Material, Corrosives, Miscellaneous Dangerous Goods |
Next steps
Since you have learned how to work with vehicle restrictions, here are recommendations for next steps: