@vietmap/vietmap-gl-js
v6.0.1
Published
Vietmap GL JS is a JavaScript library that render interactive maps
Readme
Vietmap WebGL
Import Vietmap WebGL API to your project.
v6.0.0 Update
From version 6.0.0, Vietmap WebGL API has been updated to use the below style URL:
For more information about tilemap, please checkout our official documentation page: https://maps.vietmap.vn/docs/map-api/tilemap/
VietMap Tile map:
https://maps.vietmap.vn/maps/styles/tm/style.json?apikey=YOUR_API_KEY_HEREVietMap Dark map:
https://maps.vietmap.vn/maps/styles/dm/style.json?apikey=YOUR_API_KEY_HEREVietMap Light map:
https://maps.vietmap.vn/maps/styles/lm/style.json?apikey=YOUR_API_KEY_HEREFrom version 5.x.x and below, the style URL is:
VietMap Tile map:
https://maps.vietmap.vn/mt/tm/style.json?apikey=YOUR_API_KEY_HEREVietMap Dark map:
https://maps.vietmap.vn/mt/dm/style.json?apikey=YOUR_API_KEY_HEREVietMap Light map:
https://maps.vietmap.vn/mt/lm/style.json?apikey=YOUR_API_KEY_HEREInstallation
React
Import the library in your React project.
npm install @vietmap/vietmap-gl-jsImport the library in your React component.
import vietmapgl from "@vietmap/vietmap-gl-js/dist/vietmap-gl";
import '@vietmap/vietmap-gl-js/dist/vietmap-gl.css';
Init the map in your component.
const [map, setMap] = useState<vietmapgl.Map | null>(null);
useEffect(() => {
if (!mapContainerRef.current) return;
// Get API key from environment variables
const apiKey = import.meta.env.VITE_VIETMAP_API_KEY || '';
const mapInstance = new vietmapgl.Map({
container: mapContainerRef.current,
style: `https://maps.vietmap.vn/maps/styles/tm/style.json?apikey=${apiKey}`,
center: [106.6755666, 10.7588867], // Vietnam centered
zoom: 12,
});
mapInstance.addControl(new vietmapgl.NavigationControl(), 'top-right');
// Wait for map to load
mapInstance.on('load', () => {
setMap(mapInstance);
});
// Clean up on unmount
return () => {
mapInstance.remove();
};
}, []);Add Marker
const marker = new vietmapgl.Marker()
.setLngLat([106.6755666, 10.7588867])
.addTo(map);Add Popup
const popup = new vietmapgl.Popup()
.setLngLat([106.6755666, 10.7588867])
.setHTML('<h1>Hello Vietmap</h1>')
.addTo(map);Move the map
map.flyTo({
center: [106.6755666, 10.7588867],
zoom: 12,
duration: 1000,
});HTML
Add the following code to your HTML file.
<script src="https://unpkg.com/@vietmap/[email protected]/dist/vietmap-gl.js"></script>
<link href="https://unpkg.com/@vietmap/[email protected]/dist/vietmap-gl.css" rel="stylesheet" />Documentation
Follow the documentation here to get started. Contact vietmap.vn to register a valid key.
