Get started with maptalks CDN

BSD-3-Clause licensed

Maptalks is an open-source library for creating interactive maps and location-based applications.

Tags:
  • javascript
  • gis
  • map
  • 2d-maps
  • 3d-maps
  • geospatial
  • maps
  • maptalks

Stable version

Copied!

How to start using maptalks CDN


// Include MapTalks library
const script = document.createElement('script');
script.src = 'https://cdn.cdnhub.io/maptalks/0.49.5/maptalks.min.js';
document.head.appendChild(script);

// Wait for MapTalks to load
window.onMapTalksReady = () => {
  // Create a Map object
  const map = new maptalks.Map('map', {
    center: [0, 0], // Set initial center coordinates
    zoom: 2 // Set initial zoom level
  });

  // Add a base layer (OpenStreetMap)
  map.addBaseLayer(new maptalks.OpenStreetMapLayer());

  // Create a marker at a specific location
  const marker = new maptalks.Marker(map.getCenter(), {
    draggable: true,
    icon: new maptalks.Icon('marker.png', new maptalks.Size(32, 32))
  });

  // Add the marker to the map
  map.addMapObject(marker);
};
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions