Tutorial: Points of interest and labels

In this tutorial, you learn how to add points of interest (POIs) and street labels to a map.

This image shows the result of the tutorial.

../../_images/adding-pois-completed.png

Assets for the tutorial

The starting point of this tutorial is the <KanziWorkspace>/Engine/plugins/maps/tutorials/AddingPOIsAndLabels/Start/Tool_project/AddingPOIsAndLabels.kzproj Kanzi Studio project.

The project contains textures that show Maki icons of different points of interest.

../../_images/poi-textures.png ../../_images/aerialway-15-properties.png

You can find the completed tutorial in the <KanziWorkspace>/Engine/plugins/maps/tutorials/AddingPOIsAndLabels/Completed directory.

In Kanzi Studio, to see the tutorial project in the Preview, in the main menu select Kanzi Maps > Set Up Kanzi Maps. This way, you copy the Kanzi Maps library files to the Application/bin directory of the tutorial project.

Create a renderer for the points of interest

In this section, you create a Prefab Feature Renderer node that you use to render the points of interest.

To create a renderer for the points of interest:

  1. In Kanzi Studio, open the <KanziWorkspace>/Engine/plugins/maps/tutorials/AddingPOIsAndLabels/Start/Tool_project/AddingPOIsAndLabels.kzproj project.

    The project contains a 3D map.

    ../../_images/start2.png
  2. In the Kanzi Studio main menu, select Kanzi Maps > Set Up Kanzi Maps.

    This way, you copy the Kanzi Maps library files to the Application/bin directory of the tutorial project.

    ../../_images/set-up-kanzi-maps.png
  3. If Kanzi Studio asks whether you want to set the map plugin credentials, click Yes and set up your Mapbox credentials. See Setting up your Mapbox credentials.

  4. In the Data Sources window, click Create Data Source and set:

    • Name to POIs

    • Data Source Type to Kanzi.Maps.TileDataSource

      Tile Data Source exposes all map features in the currently visible map area as a flat list.

    ../../_images/create-data-source.png ../../_images/pois-data-source1.png

    Tip

    To view the Data Sources window, in the Kanzi Studio main menu, select Window > Data Sources.

    ../../_images/window-data-sources-menu.png
  5. In the Data Sources window, click reload-data-source next to the POIs data source to create data objects from that data source.

    ../../_images/load-pois-data-source.png ../../_images/pois-data-source-loaded.png
  6. In the Node Tree in the Map View node, create a Prefab Feature Renderer node and name it Points of Interest.

    Use the Prefab Feature Renderer node to instantiate a prefab in place of all instances of a specific map feature, such as place of interest or street label.

    ../../_images/points-of-interest-in-node-tree.png
  7. In the Properties, add and set:

    • Data Context > Data Context to POIs

      This way, you enable the Points of Interest Prefab Feature Renderer to access the map features from the POIs data source.

      Tip

      To set the Data Context property, you can drag a data source from the Data Sources window to the Effective Data Context property in the Properties.

    • Scaling to Object scale

      This way, you keep the size of the POI items the same when the zoom level of the map changes.

    ../../_images/points-of-interest-properties1.png
  8. Select Kanzi Maps > Renderer Editor.

    Use the Renderer Editor to set layer and metadata filters that define the map features that a Renderer node renders.

    ../../_images/kanzi-maps-renderer-editor-menu.png
  9. In the Renderer Editor, set Layer to poi_label.

    Make sure that the Points of Interest node is selected in the Node Tree.

    Use the poi_label layer to place icons and labels for points of interest.

    ../../_images/renderer-editor-poi-labels.png
  10. In the Data Sources window, click reload-data-source next to the POIs data source to create data objects from that data source.

    ../../_images/reload-pois-data-source.png ../../_images/pois-items.png

    Tip

    To view the configuration of a Tile Data Source, in the Data Sources next to that data source click configure-data-source.

    ../../_images/pois-configure-data-source.png ../../_images/pois-data-source-properties.png

Create the point of interest prefab

In this section, you create the prefab that the Prefab Feature Renderer node instantiates in place of each place of interest.

To create the point of interest prefab:

  1. In the Prefabs, create an Empty Node 3D node named POI. In the POI prefab, create a Text Block 3D node named Name.

    ../../_images/poi-in-prefabs.png
  2. In the Node Tree, select the Points of Interest node. In the Properties, set the Prefab property to POI.

    In the Preview, you can see an instance of the POI prefab at every point of interest on the map.

    ../../_images/points-of-interest-in-node-tree.png ../../_images/prefab-poi.png ../../_images/pois-initial-preview.png
  3. In the Properties, set the Tags property to KanziMaps_Overlay, Transparent.

    With the KanziMaps_Overlay tag you make sure that buildings or other obstacles do not obscure the POIs. With the Transparent tag you let the render pass know that the content contains transparency.

    ../../_images/tags-menu.png ../../_images/poi-tags.png ../../_images/pois-overlay-transparency-preview.png
  4. In the Prefabs, select Name node. From the Data Sources, drag the POIs > features > Item > name_en data object to the Properties and drop it on the Text property.

    You set the Name node to show the English name of a point of interest that is set in the name_en data object. When you drop a data object on a property, Kanzi Studio binds the value of that property type to the value of the data object.

    ../../_images/drag-name-data-object.gif ../../_images/name-text-binding.png
  5. In the Properties, add the 2D to 3D Projection Scale property, and set it to 0.01.

    With this property, you set the factor that Kanzi uses to scale the text from pixels to 3D units.

    ../../_images/name-projection-scale.png
  6. In the Prefabs, select the POI prefab. In the Properties, add the Constraints > Face to Camera Mode property and set it to Billboarding.

    The Billboarding mode sets nodes to rotate with the rotation of the target camera, keeping the nodes rotated perpendicular to the field of view of the camera.

    ../../_images/poi-in-prefabs.png ../../_images/poi-face-to-camera.png ../../_images/all-pois-facing-camera.png
  7. In the Node Tree, select the Points of Interest node. In the Renderer Editor in the Metadata Filter:

    1. Next to all match, click renderer-add-filter and select the is less or equal to rule.

      ../../_images/metadata-less-or-equal-to.png
    2. Click category_en and set the key to filterrank.

      You use the filterrank field to control the density of points of interest that you show on the map.

      ../../_images/select-filterrank.png

      Tip

      In the metadata filter editor, hover over an item in the field menu to see its description generated from the Mapbox documentation.

      ../../_images/layer-field-documentation-tooltip.png
    3. Set the value to 2.

      ../../_images/filterrank-filter.png
  8. In the Renderer Editor in the Metadata Filter, add another filter for sizerank is less or equal to 14.

    ../../_images/poi-metadata-filter.png

    Kanzi Studio sets in the POIs data source the Metadata Filter property to the expression that matches the filter that you created in the Renderer Editor:

    filterrank <= 2 && sizerank <= 14
    

    In the Preview, you can see the points of interest that match the metadata filter.

    ../../_images/pois-metadata-filter.png ../../_images/pois-filtered.png

Add icons for the points of interest

To add icons for the points of interest:

  1. In the Prefabs > POI prefab, create a Plane node named Icon. In the Properties, set the Mesh Material property to KanziMaps/TextureHardDropShadow.

    ../../_images/icon-in-prefabs.png ../../_images/icon-mesh-material.png
  2. In the Library > Materials and Textures > Textures > KanziMaps > POIs, right-click the aerialway-15 texture and select Copy .kzb URL.

    ../../_images/copy-aerialway-kzb-url.png
  3. In the Prefabs, select the Icon node. In the Properties, click + Add Binding and in the Binding Editor set:

    • Property to Material > Texture

    • Expression to the kzb URL that you copied, enclosed in double quotes:

      "kzb://addingpoisandstreetlabels/Textures/KanziMaps/POIs/aerialway-15"
      
    ../../_images/icon-in-prefabs.png ../../_images/icon-texture-binding.png
  4. In the Properties, add and set:

    • Width and Height to 1

    • Layout Transformation Translation Y to 0.75

      You position the point of interest icon above the label.

    ../../_images/icon-properties.png
  5. In the Properties, click the binding to edit it, and in the Binding Editor, set Expression to

    "kzb://addingpoisandstreetlabels/Textures/KanziMaps/POIs/" + {DataContext.maki} + "-15"
    

    This way, you set the correct icon for each point of interest.

    ../../_images/icon-texture-binding-final.png

Show street labels

To show street labels:

  1. In the Data Sources, create a tile data source named Major roads and click reload-data-source to create data objects from the data source.

    ../../_images/major-roads-data-source.png
  2. In the Node Tree in the Map View node, create a Prefab Feature Renderer node named Major road labels. In the Properties, set the Data Context to Major roads.

    Leave the Scaling property set to Map scale. This way, you let the size of the road labels scale with the road.

    ../../_images/major-road-labels.png ../../_images/major-road-labels-data-context.png
  3. In the Renderer Editor, for the Major road labels renderer, set:

    • Layer to road

    • Metadata Filter to:

      all match
        class is one of
          motorway
          primary
          secondary
          tertiary
          trunk
        structure is not tunnel
      
    ../../_images/major-road-labels-filter.png
  4. In the Prefabs, create a Text Block 3D prefab named Road Label.

    ../../_images/road-label-in-prefabs.png
  5. In the Node Tree, select the Major road labels node. In the Properties, set the Prefab property to the Road Label prefab.

    ../../_images/major-road-labels-prefab.png
  6. In the Prefabs, select the Road Label prefab. In the Properties:

    • Set Tags to KanziMaps_2D.

      This way you let the render pass know that the road labels are 2D-like content.

    • Set 2D to 3D Projection Scale to 0.4.

    • Add the Layout Transformation property and set the Rotation X property field to -90.

    • Bind the Text property to the Major roads > features > Item > name_en data object.

    ../../_images/road-label-in-prefabs.png ../../_images/road-label-properties.png
  7. In the Node Tree, select the Map View node. In the Properties, set the Zoom Level property to 17.

    ../../_images/map-view-zoom-level1.png ../../_images/adding-pois-completed.png

See also

To learn more about the Tile Data Source, see Using the Tile Data Source.

To learn more about using the Prefab Feature Renderer node, see Using the Prefab Feature Renderer node.

To learn more about using the Renderer Editor, see Using the Renderer Editor.