Skip to content

Instantly share code, notes, and snippets.

@swingley
Created February 27, 2013 19:06
Show Gist options
  • Save swingley/5050654 to your computer and use it in GitHub Desktop.
Save swingley/5050654 to your computer and use it in GitHub Desktop.
Nice Nice JPG! in an esri JS API map popup.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Nice Nice Popup</title>
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">
<style>
html, body, #map {
height: 100%; width: 100%; margin: 0; padding: 0;
}
.esriPopup .title a {
color: #fff;
}
</style>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>
<script>
var map, popup;
require(["dojo/dom-construct", "dojo/string", "esri/map", "esri/dijit/Popup"],
function(domConstruct, string) {
popup = new esri.dijit.Popup(null, domConstruct.create("div"));
map = new esri.Map("map", {
basemap: "streets",
center: [ 19.291, 48.343 ],
zoom: 4,
infoWindow: popup
});
map.infoWindow.setTitle("<a href=\"http://nicenicejpg.com/\">NiceNiceJpg, Baby</a>");
map.on("click", function(evt) {
var imgStr = "<img src=\"http://nicenicejpg.com/${0}/${1}\">";
// use 5.0 in the URL to get 90s mustang pics instead...
// var imgStr = "<img src=\"http://nicenicejpg.com/5.0/${0}/${1}\">";
var height = parseInt((Math.random() + 1) * 2) * 100;
var width = parseInt((Math.random() + 1) * 5) * 100;
map.infoWindow.resize(width + 25, height + 25);
map.infoWindow.setContent(string.substitute(imgStr, [width, height]));
map.infoWindow.show(evt.mapPoint);
});
}
);
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment