Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BaseMap

The BaseMap provides a minimal setup that allows to work with Deck.gl and Google Maps. It supports:

  • Basic Google Maps Markers
  • Deck.gl optimized Markers
  • Basic Google Maps Polylines
  • Deck.gl optimized Polylines
  • SideCard with information
  • Navbar with information

Basic implementation

It is important to note that the BaseMap.initialize method should be called first thing after creting the instance.

import { BaseMap } from '@resser/mapster';

(async () => {
  const mapContainer = document.createElement('div');
  mapContainer.style.width = '100vw';
  mapContainer.style.height = '100vh';
  const body = document.querySelector('body');
  if (body) body.appendChild(mapContainer);

  const map = new BaseMap(mapContainer, {
    mapId: '306a568df144c1e3',
    zoom: 8,
    center: { lat: 20.643086060047693, lng: -103.42928984418265 },
  });

  // IMPORTANT!!!!
  await map.initialize();
})();

Adding Basic Google Maps Markers (Legacy)

BaseMap support Google Maps classic markers. Their are not recommended because of performance issues. Consider using {@link Marker}. You can learn more about them here.

const marker = new google.maps.Marker({
  position: { lat: 20.643086060047693, lng: -103.42928984418265 },
});

marker.setMap(map.googleMap);

Adding Basic Google Maps Polygons (Legacy)

BaseMap support Google Maps classic polygons. Their are not recommended because of performance issues. Consider using {@link GeoJsonFeature}. You can learn more about them here.

const polygonCoordinates = [
  { lat: 20.728398126197423, lng: -104.07016426168617 },
  { lat: 19.618571974014426, lng: -104.01137167407285 },
  { lat: 19.803064360014687, lng: -102.80938988286705 },
  { lat: 21.112814452401953, lng: -102.84205243154112 },
];

const polygon = new google.maps.Polyline({
  path: polygonCoordinates,
  geodesic: true,
  strokeColor: '#FF0000',
  strokeOpacity: 1.0,
  strokeWeight: 2,
});

polygon.setMap(map.googleMap);

Adding Mapster Markers (Recommended)

import { Icon } from '@resser/mapster';

const mapsterMarker = {
  id: '87998',
  icon: Icon.DEFAULT_RED,
  lat: 20.7492650861,
  lng: -103.23710715239,
};

// Add marker.
map.addMarker(mapsterMarker);

// Wait 5 seconds and update marker.
await new Promise((resolve) => setTimeout(resolve, 5000));
map.updateMarker('87998', {
  lng: mapsterMarker.lng + 0.1,
  lat: mapsterMarker.lat + 0.1,
  icon: Icon.DEFAULT_BLACK,
});

// Wait 5 seconds and remove marker.
await new Promise((resolve) => setTimeout(resolve, 5000));
map.removeMarker('87998');

// Remove all map markers.
// map.removeAllMarkers()

Adding Mapster GeoJsons

const geoJson = {
    id: 1,
    feature: {
        type: 'Feature',
        properties: {
            stroke: [85, 55, 55],
            'stroke-width': 2,
        },
        geometry: {
            type: 'LineString',
            coordinates: [
                [
                    -103.09432983398436,
                    20.873568860790446,
                ],
                [
                    -103.4857177734375,
                    20.548580033472923,
                ],
            ],
        },
    },
}

// Add geoJson to collection.
baseMap.addGeoJson(geoJson);

// You will usually add the GeoJson to a map:
// map.removeGeoJson(geoJson)

Setting up a SideCard

Learn more about SideCard.

const mapsterSideCard = new Mapster.SideCard({
    subtitle: 'hace 5 min.',
    values: [
        {
            label: 'ID',
            value: '959483',
        },
        {
            label: 'BaterĂ­a',
            value: '12.5 V',
        },
    ],
})

// Add SideCard to map
baseMap.setSideCard(mapsterSideCard);

// Show
baseMap.showSideCard()

// Hide
// baseMap.hideSideCard()

Setting up a Nabvar

Learn more about Navbar.

const mapsterNavbar = new Mapster.Navbar({
    avatar: 'https://cdn.iconscout.com/icon/free/png-64/suzuki-3441642-2874411.png',
    title: 'ABC-APV00021688',
    subtitle: '#50949',
})

// Add Navbar to map
baseMap.setNavbar(mapsterNavbar)

Adding WMTS Layers

// WMTS layer to be used for testing
const wmtsLayer: IWmtsLayer = {
     id: '102',
     url: 'https://lbsva.telcel.com/tiles/gwc/service/wmts?layer=telcel:cincog_no_garantizada&style=&tilematrixset=EPSG:900913&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image/png&TileMatrix=EPSG:900913:{z}&TileCol={x}&TileRow={y}'
};

// Creates a WMTS layer collection
const wmtsLayerCollection: WmtsLayerCollection = new WmtsLayerCollection();

// Adds a WMTS Layer to the collection.
wmtsLayerCollection.addWmtsLayer(wmtsLayer);

// Removes a WMTS layer from the collection
wmtsLayerCollection.removeById('102');

Using Google Maps Infowindows

You can use regular Google Maps Infowindows. Learn more here. You can have custom Infowindows by using overlays like here

const contentString = '<div id="content">'
    + '<h4 id="firstHeading" class="firstHeading">Hello World!</h1>'
    + '</div>'

const infowindow = new google.maps.InfoWindow({
    content: contentString,
    position: new google.maps.LatLng(20.652738741003635, -103.43845898568829),
})

infowindow.open({
    map: baseMap.map,
})

Hierarchy

  • BaseMap

Index

Constructors

constructor

  • Creates a new instance of BaseMap

    Parameters

    • parentContainer: HTMLElement

      The HTMLElement where the map will be added to.

    • Optional config: IBaseMapConfig

      See IBaseMapConfig for more information about configuration.

    Returns BaseMap

Properties

Protected _config

Optional wmtsLayer

wmtsLayer: string

Accessors

config

geoJsons

googleMap

  • get googleMap(): Map
  • Returns Map

markers

trafficLayer

  • get trafficLayer(): TrafficLayer
  • Returns TrafficLayer

Methods

addGeoJson

  • Adds a GeoJson feature to the Map

    Parameters

    Returns void

addGeoJsons

  • Adds multiple GeoJsons at a time. Please Consider using this method for better performance

    Parameters

    Returns void

addMarker

  • Adds a marker to the map. Make sure it has a unique ID.

    Parameters

    • marker: IMarker

      Instance of Marker to be added to the Map.

    Returns void

addMarkers

  • addMarkers(markers: IMarker[]): void
  • Adds multiple Markers at a time. Please consider using this method for better performance.

    Parameters

    • markers: IMarker[]

      List of Markers to be added at once.

    Returns void

addPrettyRoute

  • Adds a GeoJson feature to the Map

    Parameters

    Returns void

addPrettyRoutes

  • Adds multiple GeoJsons at a time. Please Consider using this method for better performance

    Parameters

    • prettyRoutes: IPrettyRoute[]

      List of GeoJsons to be added at once.

    Returns void

addWmtsLayer

  • Adds a wmts layer.

    Parameters

    Returns void

addWmtsLayers

  • Adds multiple wmts layers to the collection.

    Parameters

    • wmtsLayers: IWmtsLayer[]

      Wmts layers array to be added.

    Returns void

Protected getLayers

  • getLayers(timeStamp: any): any[]
  • Class to be implemented with extra layers.

    Parameters

    • timeStamp: any

      a timestamp is passed in case the layers depend on that information.

    Returns any[]

Protected getOffsetX

  • getOffsetX(): number
  • Returns the offset in pixels when we have the camera fixed.

    Returns number

Protected getPointTrack

  • getPointTrack(timeStamp: any): any
  • Returns the position to fix camera to. Return null if we don't want to track anything.

    Parameters

    • timeStamp: any

      current timestamp.

    Returns any

hideSideCard

  • hideSideCard(): void
  • Hides the SideCard if it exists.

    Returns void

initialize

  • initialize(): Promise<unknown>
  • Initializes map in an asynchronous way. It is mandatory to call this method as soon as possible. Most of the other features of the map depend on the execution and finalization of this method.

    Returns Promise<unknown>

removeAllGeoJsons

  • removeAllGeoJsons(): void
  • Removes all geoJsons at once.

    Returns void

removeAllMarkers

  • removeAllMarkers(): void
  • Removes all markers at once.

    Returns void

removeAllPrettyRoutes

  • removeAllPrettyRoutes(): void
  • Removes all geoJsons at once.

    Returns void

removeAllWmtsLayers

  • removeAllWmtsLayers(): void
  • Removes all WMTS layers at once.

    Returns void

removeGeoJson

  • removeGeoJson(id: string): void
  • Remove GeoJson by id. That's why having unique ID's for GeoJsons is so important.

    Parameters

    • id: string

      ID of GeoJson to delete.

    Returns void

removeMarker

  • removeMarker(id: string): void
  • Remove Marker by id. That's why having unique ID's for Markers is so important.

    Parameters

    • id: string

      ID of Marker to delete.

    Returns void

removePrettyRoute

  • removePrettyRoute(id: string): void
  • Remove GeoJson by id. That's why having unique ID's for GeoJsons is so important.

    Parameters

    • id: string

      ID of GeoJson to delete.

    Returns void

removeWmtsLayer

  • removeWmtsLayer(wmtsLayerId: string): boolean
  • Removes a Wmts layer.

    Parameters

    • wmtsLayerId: string

      Layer id from the layer that will be removed

    Returns boolean

setLayers

  • setLayers(layers: any[]): void
  • Parameters

    • layers: any[]

    Returns void

setNavbar

  • setNavbar(navbar?: Navbar | null): void
  • Sets a Navbar to the map.

    Parameters

    • Optional navbar: Navbar | null

      Pass null if you want to remove the current Navbar.

    Returns void

setPrettyRoutes

  • Adds multiple GeoJsons at a time. Please Consider using this method for better performance

    Parameters

    • prettyRoutes: IPrettyRoute[]

      List of GeoJsons to be added at once.

    Returns void

setSideCard

  • setSideCard(sideCard?: SideCard | null): void
  • Sets a SideCard to the map.

    Parameters

    • Optional sideCard: SideCard | null

      Pass null if you want to remove the current SideCard.

    Returns void

setWmtsLayerVisibility

  • setWmtsLayerVisibility(wmtsLayerId: string, visible?: boolean): void
  • Sets the visibility of a WMTS layer.

    Parameters

    • wmtsLayerId: string

      The id of the WMTS layer for which the visibility will be set.

    • Default value visible: boolean = true

      Indicates if the WMTS layer will be visible or not.

    Returns void

showSideCard

  • showSideCard(): void
  • Shows the SideCard if it exists.

    Returns void

stopAnimation

  • stopAnimation(): Promise<void>
  • Clears resources and stops animation

    Returns Promise<void>

updateMarker

  • updateMarker(id: string, options: object): void
  • Updates marker from collection by Id.

    Parameters

    • id: string

      Markers's id to be updated.

    • options: object

      Marker properties to be updates.

      • Optional icon?: Icon
      • Optional lat?: number
      • Optional lng?: number

    Returns void

Generated using TypeDoc