Options
All
  • Public
  • Public/Protected
  • All
Menu

Package core

XYZ Maps JS: Core

XYZ Maps is an experimental and work in progress open-source map editor written in TypeScript/JavaScript. The core module of XYZ Maps provides the most basic functionality and is used by all other modules of xyz-maps. Main functionalities of the module are: DataProviders, TileLayers, Geometric Classes and Styling definitions.

Links

Installation

Install XYZ Map Core by using

# install using npm
npm install @here/xyz-maps-core

or

# install using yarn
yarn add @here/xyz-maps-core

Example Usage:

Create a MVTLayer

import {MVTLayer} from '@here/xyz-maps-core';

// create a MVT Layer
const myLayer = new MVTLayer({
    remote: {
        url: 'https://xyz.api.here.com/tiles/osmbase/512/all/{z}/{x}/{y}.mvt?access_token=' + YOUR_ACCESS_TOKEN
        tileSize : 512
    },
    min: 1,
    max: 20
})
// and add it to the map display
display.addLayer(myLayer);

Start developing

  1. Install node module dependencies

    yarn install
    

    In case yarn is not installed already: install yarn

  2. watch for source code changes and build dev version

    yarn run watch-dev
    

    Builds are located in located in ./dist/

Other

  • build dev version once yarn run build-dev (located in packages/*/dist/)

  • build release version only yarn run build-release (minified...)

License

Copyright (C) 2019-2022 HERE Europe B.V.

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details

Index

Type aliases

ClusterFeatureProperties

ClusterFeatureProperties: { clusterSize: number; isCluster: true; zoom: number }

Properties of a ClusterFeature.

The isCluster, clusterSize, and zoom properties are automatically populated for each cluster feature.

Custom properties aggregation for clusters can be achieved by defining custom property creation and aggregation functions using the createProperties and aggregateProperties options.

Type declaration

  • [name: string]: any

    Additional custom properties of the cluster feature.

  • Readonly clusterSize: number

    The size of the cluster, i.e., the number of features it contains.

  • Readonly isCluster: true

    Indicates if the feature is a cluster.

  • Readonly zoom: number

    The zoom level at which the cluster was formed.

Color

Color: string | number | [number, number, number, number]

The Color is an RGBA color value representing RED, GREEN, and BLUE light sources with an optional alpha channel. Colors can be specified in the following ways:

  • CSS color names: "red"
  • RGB colors: "rgb(255,0,0)"
  • RGBA colors: "rgba(255,0,0,1.0)"
  • Hexadecimal colors: "#ff0000" | "#f00"
  • Hexadecimal colors with transparency: "#ff0000ff"
  • hexadecimal numbers: 0xff0000
  • RGBA Color Array: [1.0, 0.0, 0.0, 1.0]

GeoJSONBBox

GeoJSONBBox: [number, number, number, number]

Defines a geographical rectangle. The values of a GeoJSONBBox array are "[west: number, south: number, east: number, north: number]"

GeoJSONCoordinate

GeoJSONCoordinate: number[]

A GeoJSON Geometry coordinate is a array of coordinates. The array must contain two or three elements [longitude, latitude, altitude?] / [x, y, z?].

StyleExpression

StyleExpression<ResultType>: [string, any]

A StyleExpression is a JSON array representing an expression that returns the desired value for a specific style property. It is particularly useful for data-driven styling in map or UI components.

The structure of a StyleExpression is as follows:

  • The first element (index 0) is a string that specifies the operator of the expression.
  • The subsequent elements are the operands required by the operator.

Type parameters

  • ResultType = any

    The type of the value that the expression returns.

    StyleExpression Operators

    A StyleExpression is a JSON array representing an expression that returns the desired value for a specific style property. Below are the possible operators and their descriptions, along with examples.

    Reference

    • ref: References another expression by name.
      • Example: ["ref", "otherExpression"]

    Data Retrieval

    • get: Retrieves a property from the input data. The third optional operand specifies the input data from which to retrieve the property. If not provided, it defaults to feature.properties.

      The property name can also be a global map context variable:

      • $zoom: The current zoom level.

      • $layer: The name of the datasource layer.

      • $geometryType: The type of the current feature geometry ("line", "point", "polygon").

      • $id: The ID of the current feature.

      • Example: ["get", "propertyName"] // Retrieves propertyName from feature.properties.

      • Example with input data: ["get", "propertyName", { custom: "data" }] // Retrieves propertyName from the specified input data.

      • Example with global map context variable: ["get", "$zoom"] // Retrieves the current zoom level.

    Arithmetic

    • +: Adds two numbers.
      • Example: ["+", 2, 3] // Outputs: 5
    • -: Subtracts the second number from the first.
      • Example: ["-", 5, 3] // Outputs: 2
    • *: Multiplies two numbers.
      • Example: ["*", 2, 3] // Outputs: 6
    • /: Divides the first number by the second.
      • Example: ["/", 6, 3] // Outputs: 2
    • %: Computes the remainder of dividing the first number by the second.
      • Example: ["%", 5, 2] // Outputs: 1
    • floor: Rounds down a number to the nearest integer.
      • Example: ["floor", 4.7] // Outputs: 4
    • min: Returns the smallest number.
      • Example: ["min", 1, 2, 3] // Outputs: 1
    • max: Returns the largest number.
      • Example: ["max", 1, 2, 3] // Outputs: 3

    Logical

    • all: Returns true if all conditions are true.
      • Example: ["all", true, true] // Outputs: true
    • any: Returns true if any condition is true.
      • Example: ["any", true, false] // Outputs: true
    • !: Negates a boolean value.
      • Example: ["!", true] // Outputs: false
    • !has: Checks if a property does not exist.
      • Example: ["!has", "propertyName"]
    • has: Checks if a property exists.
      • Example: ["has", "propertyName"]
    • none: Returns true if no conditions are true.
      • Example: ["none", false, false] // Outputs: true

    Comparison

    • ==: Checks if two values are equal.
      • Example: ["==", 2, 2] // Outputs: true
    • !=: Checks if two values are not equal.
      • Example: ["!=", 2, 3] // Outputs: true
    • >: Checks if the first value is greater than the second.
      • Example: [" >", 3, 2] // Outputs: true
    • >=: Checks if the first value is greater than or equal to the second.
      • Example: [" >=", 3, 3] // Outputs: true
    • <=: Checks if the first value is less than or equal to the second.
      • Example: ["<=", 2, 2] // Outputs: true
    • <: Checks if the first value is less than the second.
      • Example: ["<", 2, 3] // Outputs: true
    • ^=: Checks if a string starts with a given substring.
      • Example: ["^=", "hello", "he"] // Outputs: true
    • $=: Checks if a string ends with a given substring.
      • Example: ["$=", "hello", "lo"] // Outputs: true

    String Manipulation

    • split: Splits a string by a delimiter.
      • Example: ["split", "a,b,c", ","] // Outputs: ["a", "b", "c"]
    • to-string: Converts a value to a string.
      • Example: ["to-string", 123] // Outputs: "123"
    • concat: Concatenates multiple strings.
      • Example: ["concat", "hello", " ", "world"] // Outputs: "hello world"
    • regex-replace: Replaces parts of a string matching a regex.
      • Example: ["regex-replace", "hello world", "world", "there"] // Outputs: "hello there"
    • slice: Extracts a section of a string.
      • Example: ["slice", "hello", 0, 2] // Outputs: "he"
    • at: Gets the character at a specified index in a string.
      • Example: ["at", "hello", 1] // Outputs: "e"
    • length: Gets the length of a string.
      • Example: ["length", "hello"] // Outputs: 5

    Conditional

    • case: Evaluates conditions in order and returns the corresponding result for the first true condition.
      • Example: ["case", ["==", 1, 1], "one", ["==", 2, 2], "two", "default"] // Outputs: "one"
    • step: Returns a value from a step function based on input.
      • Example: ["step", 3, "small", 5, "medium", 10, "large"] // Outputs: "small"
    • match: Returns a value based on matching input values.
      • Example: ["match", "a", "a", 1, "b", 2, 0] // Outputs: 1

    Utility

    • literal: Returns a literal value.
      • Example: ["literal", [1, 2, 3]] // Outputs: [1, 2, 3]
    • lookup: Finds an entry in a table that matches the given key values. The entry with the most matching keys is returned. If multiple entries match equally, one of them is returned. If no match is found, the default entry (if any) is returned. If no default entry is defined, null is returned.
      • The lookupTable should be an array of objects, each with a keys member and an attributes member:
        • keys: An object containing key-value pairs used for matching.
        • attributes: An object containing the attributes to be returned when a match is found.
      • Example:
        {
        "definitions": {
          "lookupTable": [ "literal", [
            { "keys": { "country": "US" }, "attributes": { "population": 331000000 } },
            { "keys": { "country": "US", "state": "CA" }, "attributes": { "population": 39500000 } },
            { "keys": {}, "attributes": { "population": 7800000000 } } // Default entry
          ]]
        }
        }
        // This example looks up the population for the state of California in the United States from the `lookupTable`.
        ["lookup", { "country": "US", "state": "CA" }, ["ref", "lookupTable"]] // Outputts: `{ "population": 39500000 }`.
        

    Type Conversion

    • number: Converts a value to a number.
      • Example: ["number", "123"] // Outputs: 123
    • boolean: Converts a value to a boolean.
      • Example: ["boolean", "true"] // Outputs: true
    • to-number: Converts a value to a number.
      • Example: ["to-number", "123"] // Outputs: 123
    • to-boolean: Converts a value to a boolean.
      • Example: ["to-boolean", "true"] // Outputs: true

    Zoom and Interpolation

    • zoom: Returns the current zoom level.
      • Example: ["zoom"] // Outputs: current zoom level
    • interpolate: Interpolates between values based on zoom level.
      • Example: ["interpolate", ["linear"], ["zoom"], 10, 1, 15, 10]

    Example:

    const expression: StyleExpression = ["==", ["get", "property"], "value"];
    

    In this example, "==" is the operator, and ["get", "property"] and "value" are the operands.

    Operators can include logical, arithmetic, string manipulation, and other types of operations, which are evaluated to determine the final value of the style property.

StyleValueFunction

StyleValueFunction<Type>: (feature: Feature, zoom: number) => Type | undefined

A StyleValueFunction is a function that returns the desired value for the respective style property. It's especially useful for data driven styling.

param

the feature for which the style is to be obtained

param

the zoomlevel of the style

example
text: (feature, zoom) => feature.properties.name

Type parameters

  • Type

Type declaration

    • (feature: Feature, zoom: number): Type | undefined
    • Parameters

      Returns Type | undefined

StyleZoomRange

StyleZoomRange<Type>: {}

A StyleZoomRange is a Map<number,any> with zoomlevel as its keys and the value for the respective Style Property at the respective zoomlevel. Values for intermediate zoom levels are interpolated linearly.

example
strokeWidth: {
    // 2px for zoomlevel 1 to 12
    13: 2,  // 2px at zoomlevel 13
    // 10px for zoomlevel 14 (linear interpolation)
    15: 18, // 18px at zoomlevel 15
    // 27px for zoomlevel 16 (linear interpolation)
    17: 36  // 36px at zoomlevel 20
    // 36px for zoomlevels 18 to 20
}

Type parameters

  • Type

Type declaration

  • [zoom: number | string]: Type

Variables

Const webMercator

webMercator: { alt2z: alt2z; earthCircumference: earthCircumference; geoToPixel: geoToPixel; getGroundResolution: getGroundResolution; lat2y: lat2y; lon2x: lon2x; mapSizePixel: mapSizePixel; meterToPixel: meterToPixel; pixelToGeo: pixelToGeo; pixelToMeter: pixelToMeter; x2lon: x2lon; y2lat: y2lat } = webMercatorPrj

WebMercator projection utilities.

Type declaration

  • alt2z: alt2z
  • earthCircumference: earthCircumference
  • geoToPixel: geoToPixel
  • getGroundResolution: getGroundResolution
  • lat2y: lat2y
  • lon2x: lon2x
  • mapSizePixel: mapSizePixel
  • meterToPixel: meterToPixel
  • pixelToGeo: pixelToGeo
  • pixelToMeter: pixelToMeter
  • x2lon: x2lon
  • y2lat: y2lat

Object literals

Const build

build: object

Detailed Information about the build.

name

name: string = "xyz-maps"

Generated using TypeDoc