All skills
mapbox avatar

/mapbox-google-maps-migration

@65bab68 official
by mapboxmapbox/mapbox-agent-skills80 stars
17

Migration guide for developers moving from Google Maps Platform to Mapbox GL JS, covering API equivalents, pattern translations, and key differences

Use this Skill: https://skilld.dev/gh/mapbox/mapbox-agent-skills/mapbox-google-maps-migration

This session only. Nothing lands on disk.

referencesshapes-geocoding.md

≈991 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Shapes, Custom Icons, and Geocoding

Polygons and Shapes

Google Maps

const polygon = new google.maps.Polygon({
  paths: [
    { lat: 37.7749, lng: -122.4194 },
    { lat: 37.7849, lng: -122.4094 },
    { lat: 37.7649, lng: -122.4094 }
  ],
  strokeColor: '#FF0000',
  strokeOpacity: 0.8,
  strokeWeight: 2,
  fillColor: '#FF0000',
  fillOpacity: 0.35,
  map: map
});

Mapbox GL JS

map.addSource('polygon', {
  type: 'geojson',
  data: {
    type: 'Feature',
    geometry: {
      type: 'Polygon',
      coordinates: [
        [
          [-122.4194, 37.7749],
          [-122.4094, 37.7849],
          [-122.4094, 37.7649],
          [-122.4194, 37.7749] // Close the ring
        ]
      ]
    }
  }
});

map.addLayer({
  id: 'polygon-layer',
  type: 'fill',
  source: 'polygon',
  paint: {
    'fill-color': '#FF0000',
    'fill-opacity': 0.35
  }
});

// Add outline
map.addLayer({
  id: 'polygon-outline',
  type: 'line',
  source: 'polygon',
  paint: {
    'line-color': '#FF0000',
    'line-width': 2,
    'line-opacity': 0.8
  }
});

Polylines / Lines

Google Maps

const line = new google.maps.Polyline({
  path: [
    { lat: 37.7749, lng: -122.4194 },
    { lat: 37.7849, lng: -122.4094 }
  ],
  strokeColor: '#0000FF',
  strokeWeight: 3,
  map: map
});

Mapbox GL JS

map.addSource('route', {
  type: 'geojson',
  data: {
    type: 'Feature',
    geometry: {
      type: 'LineString',
      coordinates: [
        [-122.4194, 37.7749],
        [-122.4094, 37.7849]
      ]
    }
  }
});

map.addLayer({
  id: 'route-layer',
  type: 'line',
  source: 'route',
  paint: {
    'line-color': '#0000FF',
    'line-width': 3
  }
});

Custom Icons and Symbols

Google Maps

const marker = new google.maps.Marker({
  position: { lat: 37.7749, lng: -122.4194 },
  map: map,
  icon: {
    url: 'marker.png',
    scaledSize: new google.maps.Size(32, 32)
  }
});

Mapbox GL JS

Option 1: HTML Marker

const el = document.createElement('div');
el.className = 'marker';
el.style.backgroundImage = 'url(marker.png)';
el.style.width = '32px';
el.style.height = '32px';

new mapboxgl.Marker(el).setLngLat([-122.4194, 37.7749]).addTo(map);

Option 2: Symbol Layer (Better Performance)

// Load image
map.loadImage('marker.png', (error, image) => {
  if (error) throw error;
  map.addImage('custom-marker', image);

  map.addLayer({
    id: 'markers',
    type: 'symbol',
    source: 'points',
    layout: {
      'icon-image': 'custom-marker',
      'icon-size': 1
    }
  });
});

Geocoding

Google Maps

const geocoder = new google.maps.Geocoder();

geocoder.geocode({ address: '1600 Amphitheatre Parkway' }, (results, status) => {
  if (status === 'OK') {
    map.setCenter(results[0].geometry.location);
  }
});

Mapbox GL JS

// Use Mapbox Geocoding API v6
fetch(
  `https://api.mapbox.com/search/geocode/v6/forward?q=1600+Amphitheatre+Parkway&access_token=${mapboxgl.accessToken}`
)
  .then((response) => response.json())
  .then((data) => {
    const [lng, lat] = data.features[0].geometry.coordinates;
    map.setCenter([lng, lat]);
  });

// Or use mapbox-gl-geocoder plugin
const geocoder = new MapboxGeocoder({
  accessToken: mapboxgl.accessToken,
  mapboxgl: mapboxgl,
  countries: 'us', // ISO 3166-1 alpha-2 code(s), comma-separated; hard filter, not a soft bias
  language: 'en' // Also affects which result ranks first, not just the UI/response text
});

map.addControl(geocoder);

Note: countries and language change which results come back, not just how they're filtered or displayed. language affects result scoring (the same query can rank a different place first depending on language), and countries excludes everything outside the listed codes. Port these over from the original Google Maps region/locale config.

Source: SKILL.md on GitHub

1 warning15d5 checks · Risk SAFE
  • Gen Agent Trust Hub15d

    This skill is a safe and educational migration guide for developers moving from Google Maps to Mapbox GL JS. It provides technical comparisons, API equivalents, and best practices for performance optimization. All external references and code samples target official Mapbox services and reputable open-source libraries.

  • Socket15d

    No alerts

  • Snyk15d

    Risk: LOW · No issues

  • Runlayer7mo

    2/2 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 65bab68. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 hours ago.

Activeupdated 6 months ago
  • mapbox
  • google-maps
  • migration
  • mapping
  • javascript
  • geospatial
  • gl-js
  • web-mapping

README badge

README badge for mapbox/mapbox-agent-skills/mapbox-google-maps-migration

Guides developers migrating from Google Maps Platform to Mapbox GL JS, covering API method equivalents, coordinate order differences, and architectural patterns. Includes reference tables for map methods and events, marker strategies for different data volumes, and gotchas like timing issues and data updates that cause visual flashing.

Generated from the current SKILL.md.

Does Mapbox have a Street View equivalent?
No. Street View is not available in Mapbox GL JS, so if Street View is critical to your application, you should stay with Google Maps.
What's the coordinate order difference between Google Maps and Mapbox?
Google Maps uses {lat, lng} while Mapbox uses [lng, lat] (reversed). This applies to all methods: map.setCenter(), marker.setLngLat(), fitBounds(), etc.
How do I handle large numbers of markers in Mapbox?
For 100+ points, use data-driven layers (GeoJSON sources + circle/symbol layers) instead of individual marker objects. Mapbox renders these with WebGL, making them much faster than DOM-based markers for 1,000-10,000+ points.
How do I update marker data without causing a visual flash?
Call map.getSource('source-id').setData(newGeoJSON) to update data in place, or use map.setFilter() to filter existing data on the GPU. Never remove and re-add layers to update data, as this reinitializes WebGL resources and causes a visible flash.
What authentication method does Mapbox use?
Mapbox uses access tokens set in code (mapboxgl.accessToken = 'YOUR_TOKEN'), whereas Google Maps uses API keys in the script tag.

Generated from the current SKILL.md. These answers refresh after source changes.