Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!--

To run this demo, you need to replace 'YOUR_API_KEY' with an API key from the ArcGIS Developers dashboard.

Sign up for a free account and get an API key.

https://developers.arcgis.com/documentation/mapping-apis-and-services/get-started/

-->

<html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
  <title></title>
  <style>
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
    
    #box {
  height:200px;
  width:300px; 

 
  position:absolute;
  border:2px solid red;
  background-color:transparent;
 /* left:-121.755px;
  top:38.359px */

  padding: 10px;
  cursor: move;
  z-index: 10;
  overflow: auto;
 
}
  </style>
  <link rel="stylesheet" href="https://js.arcgis.com/4.27/esri/themes/light/main.css">
  <script src="https://js.arcgis.com/4.27/"></script>
  <script>

  require([
    "esri/config",
    "esri/Map",
    "esri/views/MapView",
    "esri/geometry/Point",
    "esri/geometry/support/webMercatorUtils",
    "esri/Graphic",
    "esri/layers/GraphicsLayer"

    ], function(esriConfig,Map, MapView, Point, webMercatorUtils, Graphic, GraphicsLayer) {

  esriConfig.apiKey = "YOUR_API_KEY";

  const map = new Map({
    basemap: "streets"
  });

  const view = new MapView({
    map: map,
    center: [-119.475, 37.737], 
    zoom: 6,
    container: "viewDiv"
 });
    
    view.on("click", function(event) {
 // you must overwrite default click-for-popup
 // behavior to display your own popup
 view.popupEnabled = false;

 // Get the coordinates of the click on the view
 let lat = Math.round(event.mapPoint.latitude * 1000) / 1000;
 let lon = Math.round(event.mapPoint.longitude * 1000) / 1000;
     console.log(lat + "  " + lon) 
      
    })
    
    view.when(function() {
	var point = new Point({x:-121.755, y:38.359});
   console.log("topleft: " + point.x + "  " + point.y)
	var screenPoint = view.toScreen(point);

	var rect = view.container.getBoundingClientRect();
	var left = screenPoint.x + rect.left + window.scrollX;
	var top = screenPoint.y + rect.top + window.scrollY;
      


	var box = document.getElementById("box");
	box.style.left = left.toString() + "px";
	box.style.top = top.toString() + "px";
      
 var bottomrightX= left + 200  //200 is the width of the box pre css
  var bottomrightY= top + 300 //300 is the height of the box per css
  
   var sPoint = {
   x: bottomrightX,
   y: bottomrightY
}
   let ptUpdate=view.toMap(sPoint);
  // console.log("POINT = " + ptUpdate.x + "," + ptUpdate.y);
  var value = webMercatorUtils.xyToLngLat(
          ptUpdate.x,
          ptUpdate.y
        );
  console.log("bottomright: " + value)
  
});
    
    
    
    //Coords widget
    var coordsWidget = document.createElement("div");
coordsWidget.id = "coordsWidget";
coordsWidget.className = "esri-widget esri-component";
coordsWidget.style.padding = "7px 15px 5px";
view.ui.add(coordsWidget, "bottom-right");

//*** Update lat, lon, zoom and scale ***//
function showCoordinates(pt) {
  var coords = "Lat/Lon " + pt.latitude.toFixed(3) + " " + pt.longitude.toFixed(3) + 
      " | Scale 1:" + Math.round(view.scale * 1) / 1 +
      " | Zoom " + view.zoom;
  coordsWidget.innerHTML = coords;
}

//*** Add event and show center coordinates after the view is finished moving e.g. zoom, pan ***//
view.watch(["stationary"], function() {
  showCoordinates(view.center);
});

//*** Add event to show mouse coordinates on click and move ***//
view.on(["pointer-down","pointer-move"], function(evt) {
  showCoordinates(view.toMap({ x: evt.x, y: evt.y }));
});


 });
</script>
</head>
<body>
     <div id="box"></div>
  <div id="viewDiv"></div>
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console