Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Customize Map Navigation Animation</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.31/esri/css/esri.css">
    <style>
      html, body, #map {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
      body {
        background-color: #FFF;
        overflow: hidden;
        font-family: "Trebuchet MS";
      }
      
      #sideDiv {
        position: absolute;
        left: 20px;
        top: 20px;
        width: 200px;
        height: 30%;
        margin: 100px 0 0 0;
        background-color:white;
        z-index: 2000;
        vertical-align: middle;
        text-align: center;
      }
      
      #bottomDiv {
        position: fixed;
        left: 40%;
        bottom: 20px;
        width: 20%;
        height: 50px;
        margin: 0 ;
        background-color:white;
        z-index: 2000;
      } 
      #LocateButton {
        position: absolute;
        top: 95px;
        left: 20px;
        z-index: 2500;
      }
    </style>     
    <script src="https://js.arcgis.com/3.31/"></script>
    <script>
      var map;

      require(["esri/map", "esri/dijit/LocateButton","esri/geometry/ScreenPoint","esri/geometry/screenUtils",
               "esri/geometry/Point","esri/geometry/Extent",  "esri/config", "dojo/domReady!"], function(Map,LocateButton,ScreenPoint ,screenUtils, Point, Extent, esriConfig) {
        //configure map animation to be faster
        esriConfig.defaults.map.panDuration = 1; // time in milliseconds, default panDuration: 350
        esriConfig.defaults.map.panRate = 1; // default panRate: 25
        esriConfig.defaults.map.zoomDuration = 100; // default zoomDuration: 500
        esriConfig.defaults.map.zoomRate = 1; // default zoomRate: 25

        map = new Map("map", {
          basemap: "satellite",
          center: [-93.5, 36.972],
          zoom: 5
        }); 
        // 48.8584 2.2945  48.80 48.90 2.2 2.4
        // 48.858222 2.294500 
        var extent = new esri.geometry.Extent({
          "ymin":48.858,"xmin":2.29,"ymax":48.859,"xmax":2.3,
          "spatialReference":{"wkid":4326} 
        });
        map.setExtent(extent);
        console.log(extent.getCenter())
        document.getElementById('sideDiv').innerHTML = "Center: " +extent.getCenter().x + "<br>" +  extent.getCenter().y;
        centerMap();
        
        geoLocate = new LocateButton({
          map: map,           
        }, "LocateButton");       
        geoLocate.startup();                
        // Add on locate functionality
        geoLocate.on("locate", function(e) {          
          var loc = e.position;          
          // Create map point from locate result
          var point = new Point(loc.coords.longitude, loc.coords.latitude);
          console.log(point)
          //var mapP = map.toScreen(point);         
          centerMap()  
          //map.setZoom(18) 
          // map.centerAt(centeredMapPoint) 
           
        });      
        function centerMap(zoom = null) {
          var currExtent = map.extent;
          console.log(currExtent.getCenter())
          // Get dimensions of side div
          var sideDiv = document.getElementById('sideDiv');      
          var centerdMapWidth = map.width - sideDiv.getBoundingClientRect().right;
          // Create centered screen X
          var centeredMapX = centerdMapWidth/2;
          
          // Get dimensions of bottom div
          var bottomDiv = document.getElementById('bottomDiv');         
          var centerdMapHeight = bottomDiv.getBoundingClientRect().top;
          // Create centered screen Y
          var centeredMapY = map.height - centerdMapHeight/2;
          
          // Create new center point
          var scrPoint = new ScreenPoint(centeredMapX, centeredMapY);         
          // Create the center point in map units
          var centeredMapPoint = screenUtils.toMapPoint(map.extent, map.width, map.height, scrPoint);
   
   
          // Move to the new center
          // Added a timeout to see the difference between the points
          setTimeout(function () {
            map.centerAt(centeredMapPoint);
            document.getElementById('sideDiv').innerHTML += "<br>New center: " + centeredMapPoint.x + "<br>" +  centeredMapPoint.y;
            //Zoom out (for polygons...)
            //map.setZoom(map.getZoom() - 1) 
            
          }, 2000);      
        }
      });
      
      
    </script>
  </head>
  <body>
    <div id='sideDiv'></div>
    <div id='bottomDiv'></div>
    <div id="map">
       <div id="LocateButton"></div>
    </div>
  </body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console