Skip to content

Generate embed MapVina map

Generate iframe MapVina map that can embedded on the website.

<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="utf-8" />
        <title>Generate embed MapVina map</title>
        <meta property="og:description" content="Generate iframe MapVina map that can embedded on the website." />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://unpkg.com/[email protected]/dist/mapvina-gl.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/mapvina-gl.css" />
    <style>
        body { margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
        html, body, #map { height: 100%; }

        /* Modern Glassmorphism Panel */
        #control-panel {
            position: absolute;
            top: 20px;
            left: 20px;
            background: rgba(255, 255, 255, 0.85);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border: 1px solid rgba(255, 255, 255, 0.5);
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            width: 320px;
            z-index: 10;
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        #control-panel h2 {
            margin: 0 0 5px 0;
            font-size: 18px;
            color: #0a2e5c;
            font-weight: 600;
        }

        #control-panel p {
            margin: 0;
            font-size: 13px;
            color: #555;
            line-height: 1.4;
        }

        textarea {
            width: 100%;
            height: 90px;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.9);
            font-family: monospace;
            font-size: 11px;
            color: #333;
            resize: none;
            box-sizing: border-box;
            outline: none;
            transition: border-color 0.3s;
        }

        textarea:focus {
            border-color: #4caf50;
        }

        .btn-group {
            display: flex;
            gap: 10px;
        }

        button {
            flex: 1;
            padding: 10px 15px;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .btn-primary {
            background-color: #4caf50;
            color: white;
            box-shadow: 0 4px 10px rgba(76, 175, 80, 0.3);
        }

        .btn-primary:hover {
            background-color: #43a047;
            transform: translateY(-1px);
        }

        /* Toast notification */
        #toast {
            visibility: hidden;
            min-width: 200px;
            background-color: #333;
            color: #fff;
            text-align: center;
            border-radius: 8px;
            padding: 12px;
            position: fixed;
            z-index: 100;
            left: 50%;
            bottom: 30px;
            transform: translateX(-50%);
            font-size: 14px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            opacity: 0;
            transition: opacity 0.3s, bottom 0.3s;
        }

        #toast.show {
            visibility: visible;
            opacity: 1;
            bottom: 40px;
        }
    </style>
</head>
<body>

<div id="map"></div>
<div id="control-panel">
    <h2>Nhúng Bản Đồ</h2>
    <p>Di chuyển marker hoặc zoom bản đồ. Mã iframe sẽ tự động cập nhật.</p>
    <textarea id="iframeTextarea" readonly></textarea>
    <div class="btn-group">
        <button class="btn-primary" onclick="copyIframeCode()">Sao chép</button>
    </div>
</div>
<div id="toast">Đã sao chép thành công!</div>

<script>
    var map = new mapvinagl.Map({
        container: 'map',
        style: 'https://maps.mapvina.com/styles/v2/streets.json?key=public_key',
        center: {"lat":10.762622,"lng":106.660172},
        zoom: 6
    });

    var marker = new mapvinagl.Marker({ draggable: true, color: '#EA4335' })
        .setLngLat({"lat":10.762622,"lng":106.660172})
        .addTo(map);

    function updateIframeCode() {
        const zoom = map.getZoom().toFixed(2);
        const lat = marker.getLngLat().lat.toFixed(5);
        const lng = marker.getLngLat().lng.toFixed(5);

        const iframeCode = `<iframe width="100%" height="500px" style="border:none; border-radius:8px; box-shadow:0 4px 12px rgba(0,0,0,0.1);" src="https://maps.mapvina.com/embed/?lat=${lat}&lng=${lng}&zoom=${zoom}"></iframe>`;
        document.getElementById('iframeTextarea').value = iframeCode;
    }

    // Auto-update on interaction
    map.on('moveend', updateIframeCode);
    map.on('zoomend', updateIframeCode);
    marker.on('dragend', updateIframeCode);

    map.on('click', function (e) {
        marker.setLngLat(e.lngLat);
        updateIframeCode();
    });

    // Initialize with default values
    map.on('load', updateIframeCode);

    function copyIframeCode() {
        const iframeTextarea = document.getElementById('iframeTextarea');
        iframeTextarea.select();
        document.execCommand('copy');
        navigator.clipboard.writeText(iframeTextarea.value);

        // Show toast
        const toast = document.getElementById('toast');
        toast.className = 'show';
        setTimeout(function(){ toast.className = toast.className.replace('show', ''); }, 3000);
    }
</script>

</body>
</html>