One marker
The smallest map there is: one location, drawn as one marker.
Map and code
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
These maps come from Google Maps and OpenFreeMap, which see your IP address. They stay off until you say so, once for the whole site. What loading the maps sends
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<maplace-map>
<maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London"></maplace-location>
</maplace-map><!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<maplace-map api-key="YOUR_KEY">
<maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London"></maplace-location>
</maplace-map><!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet, what the map mounts on, and the map made with Maplace. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
#simple-maplibre-script-map { height: 24rem; }
</style>
<div id="simple-maplibre-script-map"></div>
<script type="module">
Maplace.createMapLibreMap("#simple-maplibre-script-map", {
locations: [{ id: "london", lat: 51.5074, lng: -0.1278, title: "London" }],
});
</script><!doctype html>
<!-- A page of your own script: the CDN script, what the map mounts on, and the map made with Maplace, which adds Maps JS with your key. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
#simple-script-map { height: 24rem; }
</style>
<div id="simple-script-map"></div>
<script type="module">
Maplace.createGoogleMap("#simple-script-map", {
apiKey: "YOUR_KEY",
locations: [{ id: "london", lat: 51.5074, lng: -0.1278, title: "London" }],
});
</script><!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
#simple-maplibre-vanilla-map { height: 24rem; }
</style>
<div id="simple-maplibre-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>import "maplibre-gl/dist/maplibre-gl.css";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";
createMapLibreMap("#simple-maplibre-vanilla-map", {
locations: [{ id: "london", lat: 51.5074, lng: -0.1278, title: "London" }],
});<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<script>
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
key: "YOUR_KEY",
v: "weekly",
});
</script><style>
#simple-vanilla-map { height: 24rem; }
</style>
<div id="simple-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>import { createGoogleMap } from "@maplacejs/maplace/google";
createGoogleMap("#simple-vanilla-map", {
locations: [{ id: "london", lat: 51.5074, lng: -0.1278, title: "London" }],
});<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
#simple-maplibre-react-root .map { height: 24rem; }
</style>
<div id="simple-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
const london: Location[] = [{ id: "london", lat: 51.5074, lng: -0.1278, title: "London" }];
function Simple() {
return (
<MaplaceProvider locations={london}>
<MaplaceMap createAdapter={createMapLibreAdapter} className="map" />
</MaplaceProvider>
);
}
createRoot(document.getElementById("simple-maplibre-react-root") as HTMLElement).render(
<StrictMode>
<Simple />
</StrictMode>,
);<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<script>
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
key: "YOUR_KEY",
v: "weekly",
});
</script><style>
#simple-react-root .map { height: 24rem; }
</style>
<div id="simple-react-root"></div>
<script type="module" src="./react.tsx"></script>import type { Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
const london: Location[] = [{ id: "london", lat: 51.5074, lng: -0.1278, title: "London" }];
function Simple() {
return (
<MaplaceProvider locations={london}>
<MaplaceMap createAdapter={createGoogleAdapter} className="map" />
</MaplaceProvider>
);
}
createRoot(document.getElementById("simple-react-root") as HTMLElement).render(
<StrictMode>
<Simple />
</StrictMode>,
);How it works
The shortest map: one place, its pin on the map, and the map centred on it.
- HTML: a
<maplace-location>withlocation-id,lat,lngandtitleinside a<maplace-map>, which draws at a default height (Location attributes). - Script and Bundler:
createGoogleMap(container, { locations }), orcreateMapLibreMapon MapLibre; each location needs anidand its position (Every location). - React: a
<MaplaceMap>inside a<MaplaceProvider locations={…}>(<MaplaceProvider>).