Skip to content

Instantly share code, notes, and snippets.

@oscarlorentzon
Last active January 20, 2021 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarlorentzon/9e31ccdcf39b4b5fe1b739871c4d7b86 to your computer and use it in GitHub Desktop.
Save oscarlorentzon/9e31ccdcf39b4b5fe1b739871c4d7b86 to your computer and use it in GitHub Desktop.
Display a configured clean popup
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://unpkg.com/mapillary-js@3.1.0/dist/mapillary.min.js'></script>
<link href='https://unpkg.com/mapillary-js@3.1.0/dist/mapillary.min.css' rel='stylesheet' />
<style>
html, body { margin: 0; padding: 0; height: 100%; }
#mly { height: 100%; }
</style>
</head>
<body>
<div id='mly'></div>
<script>
var popupKey = 'FnqSkFAZXjv4Uqmqd4X_NA';
var mly = new Mapillary.Viewer({
// Replace this with your own client ID from mapillary.com
apiClient: 'QjI1NnU0aG5FZFZISE56U3R5aWN4Zzo3NTM1MjI5MmRjODZlMzc0',
component: {
cover: false,
popup: true,
},
container: 'mly',
imageKey: popupKey,
});
// Get popup component
var popupComponent = mly.getComponent('popup');
// Create popup content
var div = document.createElement('div');
div.style.backgroundColor = "#fff";
div.style.border = "2px solid red";
div.style.color = "#f00";
div.style.padding = "5px 10px";
div.innerHTML = 'parking meter';
// Create popup and set content as well as point
var popup = new Mapillary.PopupComponent.Popup({
clean: true,
float: Mapillary.Alignment.Left,
offset: 10,
opacity: 0.7,
});
popup.setDOMContent(div);
popup.setBasicPoint([0.546, 0.523]);
// Show popup for the corresponding node
var onNodeChanged = function(node) {
if (node.key === popupKey) {
popupComponent.add([popup]);
} else {
popupComponent.removeAll();
}
}
mly.on(Mapillary.Viewer.nodechanged, onNodeChanged);
// Viewer size is dynamic so resize should be called every time the window size changes
window.addEventListener("resize", function() { mly.resize(); });
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment