Skip to content

ym.modules.provider.Map

The central class of the API - it is used to create and manipulate a map on a page.

Initialization (Map)

To initialize a map, you typically create an instance of the ym.modules.provider.Map class and specify the container element for the map, along with any desired options.

var map = ym.map('mapContainer', {
    center: [50.5, 30.5],
    zoom: 13
});

Features (Map)

The ym.modules.provider.Map class provides a variety of features, including:

  • Panning and Zooming: Easily pan and zoom the map to focus on different areas.
  • Layer Management: Add and remove layers to display different types of data.
  • Markers and Overlays: Add markers, popups, and other overlays to highlight points of interest.
  • Event Handling: Respond to user interactions such as clicks and drags.

Events (Map)

The map object can emit a variety of events that you can listen to and handle. Some common events include:

  • click: Triggered when the map is clicked.
  • dblclick: Triggered when the map is double-clicked.
  • mousemove: Triggered when the mouse moves over the map.
  • zoomend: Triggered when the zoom level changes.
  • moveend: Triggered when the map stops moving.

Example of adding an event listener:

map.on('click', function(e) {
    console.log("Map clicked at " + e.latlng);
});

Methods (Map)

The ym.modules.provider.Map class provides various methods to interact with and manipulate the map:

  • setView(center, zoom): Sets the view of the map (center and zoom level).
  • panTo(latlng): Pans the map to the given geographical center.
  • fitBounds(bounds): Adjusts the map view to fit the given geographical bounds.
  • addLayer(layer): Adds a layer to the map.
  • removeLayer(layer): Removes a layer from the map.
  • addControl(control): Adds a control (e.g., zoom control) to the map.
  • removeControl(control): Removes a control from the map.

Example of using a method to set the view:

map.setView([51.505, -0.09], 13);

These features, events, and methods provide a robust framework for creating interactive maps with the ym.modules.provider.Map class.