Oracle APEX Map and Faceted Search

I know that filtering data is a popular topic, and there are many articles on how to filter data in reports using the Faceted Search component. But did you know that you can just as easily filter data on a map? After all, what is a map if not a report that presents spatial data? Today, I will introduce two components: Map and Faceted Search. Let's get started! :)

Load Data

I'll start with the data. I found an example dataset to use in this article here. The CSV file contains information about cities around the world and their populations. Let's quickly load the data into a new table step by step.

Go to SQL Workshop → Utilities → Data Workshop, and choose the Load Data option.

Select the CSV file with the data, and you'll see the following screen:

I want to load my data into a new table, so I select the following options:

  • Load To: New Table

  • Table Owner: here I have to enter the database schema

  • Table Name: CITIES (My fancy table name)

APEX allows us to choose which columns to load. I decide to load all the columns.

  • Primary Keys: Identity Column

Next, I select the appropriate settings such as Column Headers, Column Delimiter, Enclosed By, and File Encoding. Fortunately, the default settings perfectly match the format of my input data file. All I need to do is click the Load Data button. APEX will create a new CITIES table and load all 140,632 rows from the CSV file into it. Low-code magic!

💡
In the CITIES table, I store spatial data using two VARCHAR columns: Latitude and Longitude.

Map and New Layer

Now that we have a table, we can display our data on the map. Let's create a new Map region with the following parameters:

Source

  • Location: Local Database

  • Type: SQL Query

      select
          ASCII_NAME,
          COUNTRY_CODE,
          COUNTRY_NAME_EN,
          POPULATION,
          LONGITUDE,
          LATITUDE
      from CITIES
      where POPULATION > 250000
    

Next, create a new layer with these parameters:

Identification

  • Name: Cities

  • Layer Type: Points

Label

  • Label: Cities

Source

  • Location: Region Source (using the query above)

Column Mapping

  • Geometry Column Data Type: Longitude/Latitude

  • Longitude Column: LONGITUDE

  • Latitude Column: LATITUDE

Leave the rest of the fields at their default values. Save and Run Page. Our map now looks like this:

Faceted Search is one of my favorite Oracle APEX components because it allows us to implement low-code data filtering! It was introduced in Oracle APEX 19.2, so we’ve been using it for some time now. Thanks to this, users can set filters using facets that display possible values along with the number of occurrences in the result set. When a user changes a facet, the results, dependent facets, and the number of occurrences refresh immediately. Now that we’ve had a small introduction, let's add Faceted Search to our page and filter the data on the map!

  1. In the page settings in the Appearance section set Page Template: Left Side Column

  2. From the list of available regions, choose Search and set following parameters:

Identification

  • Name: Filters

  • Type: Faceted Search

Source

  • FIltered Region: Map (my Map region)

Layout

  • Slot: Left Column (Facet Search will appear on the left side as per the Left Side Column Template)

Oracle APEX automatically creates the first facet of type Search, which allows users to search the columns defined in the Source section under the Database Column(s) field.

💡
A Faceted Search region supports one Search facet, which will always be at the top of the list of facets, regardless of its sequence.

Input Field Type

I would like to add a new facet that allows me to display only the cities from the country I specify. Ideally, this would be a text field. Additionally, I’d like to define the comparison operator myself, allowing the choice between whether the country name equals the entered value or whether the entered value is contained within the country name.

Here’s how to do it. Let’s add a new facet with the following parameters:

Identification

  • Type: Input Field

Label

  • Label: Country Name

Settings

  • User can Choose Operator: True

Source

  • Database Column: COUNTRY_NAME_EN

  • Data Type: VARCHAR2

Now my Faceted Search component looks like this:

Checkbox Group Type

Now that I can display cities within a given country, I’d like the option to select specific cities using checkboxes. Let's add another facet with the following parameters:

Identification

  • Type: Checkbox Group

Label

  • Label: City

List of Values

  • Type: Distinct Values

  • Sort Direction: Ascending

Source

  • Database Column: ASCII_NAME

  • Data Type: VARCHAR2

Depending On

  • Facet: P13_COUNTRY_NAME (the facet I previously created to filter by country name)

  • Type: is not null

Range Type

I can already search my data by country and city name. Now, I’d like to filter cities by their population. Can we do something about this? Absolutely! Let's add one more facet with the following parameters:

Identification

  • Type: Range

Label

  • Label: Population

List of Values

  • Type: Static Values

  • Static Values:

Source

  • Database Column: POPULATION

  • Data Type: Number

Conclusions

Faceted Search enables advanced data filtering on maps with a low-code approach. This article demonstrates how Faceted Search simplifies the creation of sophisticated filters with minimal coding effort. The examples shown are just a small sample of what this component can do. To explore further and discover additional features, visit the following links:

  1. APEX 19.2 - Faceted Search by Carsten Czarski

  2. apex.oracle.com