To access the features, you will need to verify your identity using the client-side OAuth method outlined in this guide: https://developers.google.com/earth-engine/npm_install. After completing that step, you can utilize Google Maps and Earth Engine APIs as usual:
Here is an example of how to use HTML:
<div id="map" style="width: 600px; height: 400px"></div>
And here is a snippet of JavaScript code:
// Load client library.
const ee = window.ee = require('@google/earthengine');
const CLIENT_ID = 'YOUR_CLIENT_ID';
window.initMap = function () {
// Initialize client library.
const initialize = function () {
ee.initialize(null, null, () => {
createMap();
}, (e) => {
console.error('Initialization error: ' + e);
});
};
// Start authentication process with OAuth pop-up.
ee.data.authenticateViaOauth(CLIENT_ID, initialize, (e) => {
console.error('Authentication error: ' + e);
}, null, () => {
ee.data.authenticateViaPopup(initialize);
});
};
function createMap() {
// Set up map.
const mapEl = document.querySelector('#map');
const map = new google.maps.Map(mapEl, {
center: new google.maps.LatLng(39.8282, -98.5795),
zoom: 5
});
// Load image from EE.
const image = ee.Image('srtm90_v4');
image.getMap({ min: 0, max: 1000 }, ({ mapid, token }) => {
// Create Google Maps overlay.
const mapType = new google.maps.ImageMapType({
getTileUrl: ({ x, y }, z) =>
`https://earthengine.googleapis.com/map/${mapid}/${z}/${x}/${y}?token=${token}`,
tileSize: new google.maps.Size(256, 256)
});
// Add the EE layer to the map.
map.overlayMapTypes.push(mapType);
});
}
In a practical scenario, it's advisable to display a "Log in" button before opening the popup to avoid potential blocking by the browser's popup blocker.