Communitygithub.com

YepAPI/skills

Mapbox/Leaflet統合、ジオコーディング、ストアロケーター、マーククラスター、ルート表示。

skills とは?

このスキルは、React アプリケーションに地図と位置情報機能を統合するための包括的なガイドです。Mapbox GL JS(`react-map-gl` ラッパー)と Leaflet(`react-leaflet` ラッパー)の2つの主要な地図ライブラリをサポートし、用途に応じて選択できます。住所から座標への変換(ジオコーディング)には Mapbox Geocoding API または無料の OpenStreetMap Nominatim を利用し、100件以上のマーカーを扱う際は `supercluster` や Mapbox 組み込みクラスタリングでパフォーマンスを最適化します。ストアロケーターの実装パターン、Haversine 公式による近傍検索、Mapbox Directions API を使ったルート表示、ブラウザの位置情報取得とその権限拒否への対応など、実践的なコード例とルールが含まれています。また、地図コンポーネントは必ず動的インポートで SSR を無効にするなど、Next.js 環境でのベストプラクティスも網羅しています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/maps-geolocation

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

地図と位置情報

ルール

  • Mapbox GL JS でリッチなインタラクティブマップ — React ラッパーは react-map-gl
  • 無料の代替として Leaflet — React では react-leaflet、基本タイルに API キー不要
  • API キー管理: クライアント側 Mapbox 用に NEXT_PUBLIC_MAPBOX_TOKEN、サーバー側の秘密鍵は絶対に公開しない
  • ジオコーディング: 住所を座標に変換 — Mapbox Geocoding API または OpenStreetMap Nominatim(無料)
  • マーククラスター: 大量のマーカーデータセット(100件以上)には supercluster または Mapbox 組み込みクラスタリングを使用
  • ストアロケーターパターン: ユーザーの位置をジオコーディング → Haversine/PostGIS で近隣店舗を検索 → 地図に表示
  • ルート表示: Mapbox Directions API で運転/徒歩ルートを取得し、GeoJSON LineString レイヤーとして描画
  • ブラウザの位置情報: navigator.geolocation.getCurrentPosition() — 権限拒否は常に適切に処理
  • 地図コンポーネントは遅延ロード — 地図は重いので dynamic(() => import("./Map"), { ssr: false }) を使用

パターン

// react-map-gl と Mapbox
import Map, { Marker, NavigationControl } from "react-map-gl";
import "mapbox-gl/dist/mapbox-gl.css";

function StoreMap({ stores }: { stores: Store[] }) {
  return (
    <Map
      initialViewState={{ longitude: -122.4, latitude: 37.8, zoom: 11 }}
      mapboxAccessToken={process.env.NEXT_PUBLIC_MAPBOX_TOKEN}
      mapStyle="mapbox://styles/mapbox/streets-v12"
      style={{ width: "100%", height: 400 }}
    >
      <NavigationControl position="top-right" />
      {stores.map((store) => (
        <Marker key={store.id} longitude={store.lng} latitude={store.lat}>
          <Pin />
        </Marker>
      ))}
    </Map>
  );
}
// 近傍検索のための Haversine 距離
function haversineDistance(lat1: number, lon1: number, lat2: number, lon2: number): number {
  const R = 6371; // km
  const dLat = ((lat2 - lat1) * Math.PI) / 180;
  const dLon = ((lon2 - lon1) * Math.PI) / 180;
  const a = Math.sin(dLat / 2) ** 2 + Math.cos((lat1 * Math.PI) / 180) * Math.cos((lat2 * Math.PI) / 180) * Math.sin(dLon / 2) ** 2;
  return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}

避けるべきこと

  • 地図コンポーネントをサーバーサイドレンダリング — 常に ssr: false または "use client" で読み込むこと
  • クラスタリングなしで1000個以上のマーカーを表示 — パフォーマンスを著しく低下させるため、supercluster を使用
  • 座標をハードコード — 住所はビルド時またはオンデマンドでジオコーディングすること
  • 位置情報の権限拒否を無視 — 常にフォールバック(手動住所入力)を用意すること

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

関連スキル