Organic Maps

repository·master·Indexed 12 days ago

https://github.com/organicmaps/organicmaps

A privacy-first, open-source offline maps and GPS application powered by OpenStreetMap data. Designed for travelers, hikers, and cyclists, it provides offline navigation, contour lines, and track import/export without ads or tracking. The project includes developer documentation for building from source, configuring ICU, and using third-party libraries like Libtess2, Open Location Code, and succinct.

Tokens
29.4K
Snippets
79
Records
149
Agent score
92%

What's inside Organic Maps

  1. Overview of Libtess2

    master

    Libtess2 is a refactored version of the original GLU libtess polygon tesselator and triangulator. It is designed to provide high-quality polygon processing with a significantly improved interface and memory allocation scheme compared to the original GLU implementation.

    Key improvements include:

    • Performance: Uses a bucketed memory allocator that can improve speed by 15x to 50x depending on the data.
    • Memory Management: The API allows users to provide their own allocator or configure the library to run on a predefined chunk of memory to avoid frequent small allocations.
    • API Design: The interface is designed to loosely resemble the OpenGL vertex array API, using getter functions to access processed data.
    • Output Versatility: The library can output contours, polygons, and connected polygons. The output can also be fed back into the library as input for subsequent runs (e.g., calculating a union of contours before triangulation).
  2. Overview of the webcolors library

    master

    The webcolors library provides tools for working with color names and color codes defined by HTML and CSS specifications. It supports conversions between six-digit hexadecimal, three-digit hexadecimal, integer rgb() triplets, and percentage rgb() triplets.

    Supported Formats:

    • Six-digit hexadecimal (e.g., #0099cc)
    • Three-digit hexadecimal (e.g., #09c)
    • Integer rgb() triplets (e.g., (0, 153, 204))
    • Percentage rgb() triplets (e.g., (0%, 60%, 80%))
    • Predefined color names (e.g., white, AliceBlue)

    Limitations:

    • Does not support hsl() triplets.
    • Does not support opacity/alpha-channel information (rgba() or hsla()).
    • For HSL conversions, use the Python standard library's colorsys module.
  3. Understand the Organic Maps directory structure

    master
    The Organic Maps repository is organized into several key functional areas: platform-specific UI code, application data, map feature classification, styling assets, translation strings, build tools, and the C++ core engine. Use this overview to locate specific logic or assets for development or customization.
  4. Manage application data and map assets

    master

    The data/ directory contains the essential files required for the application to function, including map files, styles, and metadata. Key files include:

    • borders/: Polygons describing country borders.
    • countries.json: Map files hierarchy and checksums.
    • countries_meta.txt: Country/region languages and driving sides.
    • hierarchy.txt: Countries/map regions hierarchy, languages, and Wikidata IDs.
    • faq.html: FAQ text for the Help screen.
    • copyright.html: Attributions for 3rd-party libraries, data, icons, and fonts.
  5. Understand the Binary Format and Memory Layout

    master

    The JSON is converted into a compact binary format during maps generation. This format is optimized for minimal memory usage and fast UTC $\leftrightarrow$ local conversions.

    Logical Binary Structure:

    Timezone Header (28 bits $\rightarrow$ 4 bytes):

    • format_version: 3 bits
    • generation_year_offset: 6 bits
    • base_offset: 7 bits
    • dst_delta: 8 bits
    • transition_count: 4 bits

    Transition Entry (20 bits $\rightarrow$ 3 bytes):

    • day_delta: 9 bits (days since previous transition)
    • minute_of_day: 11 bits (0–1439)

    Comparison: While a full zoneinfo database can be 20–50 KB per timezone, this binary format typically uses only 3–25 bytes per timezone.

  6. Kotlin coding standards and detekt rules

    master

    When writing Kotlin, follow these specific rules enforced by the project:

    • Naming Conventions: Hungarian notation (using an m prefix) is forbidden for private properties.
      • Use _camelCase for backing fields.
      • Use camelCase for regular properties.
    • Formatting: Formatting is handled by ktlint, not detekt. There is no overlap between the two tools.
  7. Configure map features and classification

    master

    Map feature logic and OSM (OpenStreetMap) mapping are handled via several files:

    • mapcss-mapping.csv: Maps OSM tags to Organic Maps (OM) types.
    • replaced_tags.txt: Defines how similar OSM tags are merged.
    • mixed_tags.txt: Identifies high-popularity pedestrian streets.
    • editor.config: Configuration for the built-in OSM data editor (defines editable POIs and attributes).
    • config.xsd: XML schema for editor.config.

    Note: classificator.txt and types.txt are automatically generated files representing the hierarchical list of OM types.

  8. Understand the C++ Core architecture

    master

    The core engine is written in C++ and is organized into several functional modules:

    • ge0/: The external API of the application.
    • map/: Application business logic and scene management.
    • routing/: In-app routing engine.
    • search/: Ranking and searching classes.
    • indexer/: Processor for map files, classificator, and styles.
    • drape/: The core graphics library.
    • platform/: Platform abstraction (file paths, HTTP, location services).
    • storage/: Map reading functions.
    • geometry/: Geometry primitives.
    • shaders/: Rendering shaders.
    • routing_common/: Shared routing logic.
    • transit/: Experimental GTFS-based public transport support.
  9. Manage strings and translations

    master

    Localization is handled through various string files and generated JSON files:

    • strings/: Primary translation files.
    • categories.txt, categories_cuisines.txt, categories_brands.txt, countries_names.txt: Categorized strings.
    • countries_synonyms.csv: Alternative country names.
    • synonyms.txt: Country/region abbreviations and short names.
    • languages.txt: Native language names.

    Automatically generated localization files:

    • countries-strings/: JSON files for country and map region names.
    • sound-strings/: JSON files for Text-To-Speech.
  10. Understand the libtess2 tesselation algorithm phases

    master

    The libtess2 algorithm is a 2D tesselation process that operates on projected 3D data. It follows these five distinct phases:

    1. Find the polygon normal $N$: Computes a normal vector for the input polygon.
    2. Project vertices: Projects the 3D vertex data onto a 2D plane. To maintain numerical accuracy, the algorithm projects onto a plane perpendicular to the coordinate axis whose dot product with $N$ is largest.
    3. Line Sweep: Uses a line-sweep algorithm to partition the plane into $x$-monotone regions. An $x$-monotone region is one where any vertical line intersects it in at most one interval.
    4. Triangulate: Triangulates the resulting $x$-monotone regions.
    5. Group: Groups the triangles into strips and fans using a greedy approach.

    Note that triangulation is only performed after the line sweep is complete to ensure that vertex merging (caused by numerical errors or degeneracies) is fully accounted for.