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

              
                <!-- 5 meters per pixel (median) -->
<!-- 1 meters per pixel zoomed in -->
<!-- 10 meters per pixel zoomed out -->

<div class="flex-layout-vertical">

<div class="top">
  <input type="range" id="zoom" min="0" max="1" value="0.5" step="0.00001">
  <p>use the arrow keys to fake movement</p>
</div>

<svg viewbox="0 0 320 320">
  
  <g class="map" transform="translate(160,300)">
    <rect width="80" height="80" fill="yellow" stroke="red"/>
  </g>
  
  <g class="guides" transform=" translate(160,300) rotate(0)">
    <polygon class="you" points="0,-8, 7,4.5, -7,4.5"/>
    <g class="pointer">
      <polygon class="arrow" id="angleBro" points="0,-48, 4,-24.5,  0, -26, -4,-24.5" transform="rotate(90)"/>
    </g>
    <g class="proximity">
      <g data-range="1600">
        <circle r="320"/>
        <text y="-320" dy="-6">1600m</text>
      </g>
      <g data-range="800">
        <circle r="160"/>
        <text y="-160" dy="-5">800m</text>
      </g>
      <g data-range="400">
        <circle r="80"/>
        <text y="-80" dy="-4">400m</text>
      </g>
      <g data-range="200">
        <circle r="40"/>
        <text y="-40" dy="-3">200m</text>
      </g>
      <g data-range="100">
        <circle r="20"/>
        <text y="-20" dy="-2">100m</text>
      </g>
      <g data-range="50">
        <circle r="10"/>
      </g>
<!--       <circle r="2.5"/> -->
    </g>
  </g>
</svg>

</div>
              
            
!

CSS

              
                html,
body{
  width:100%;
  height:100%;
  margin:0;
  border:0;
}

.top{
  background-color:tan;
}

input[type="range"]{
  width:50%;
}

.guides circle,
.guides .you{
  stroke-width:1px;
  stroke:#000;
  fill:none;
}

.guides .arrow{
  fill:red;
  stroke:none;
}

.guides circle{
  stroke-dash-array: 1 1;
}

.guides text{
  text-anchor:middle;
  font-family:Helvetica;
  font-size:8px;
}

.map circle{
  fill:red;
}

.flex-layout-vertical{
  height:100%;
  display:flex;
  flex-direction:column;
  align-items:stretch;
/*   justify-content:space-around;
 */
}

.flex-layout-vertical > *{
  flex-grow:1;
}

svg{
  width:100%;
  height:100%;
}

              
            
!

JS

              
                /**
5 meters per pixel median
(1m/px zoomed in)
(10m/px zoomed out)

* Viewbox
Width = 320px = 1600m

* Center Points
center = 160px = 800m

* Center of Rings
x = 160px = 800m
y = 300px = 1500m


* Coordinates
lat N, long E format
Latitude is N<-->S
Longitude is E<-->W
*/

var metersPerLatitude = 110950; // meters (N<->S)
var metersPerLongitude = 91288; // meters (E<->W)
var metersPerPixel = 5;
// var metersPerPixel = 1;
var walkingSpeed = 1.1; //meters per second
// var walkingSpeed = 1; //meters per second

var uiOffsetX = 160;
var uiOffsetY = 300;

currentPosition = {
  latitude: 34.009742226228035,
  longitude: -81.0104458417316
};

targetPosition = {
  latitude:34.01,
  longitude:-81.01
}

mapOffset = {
  latitude:34,
  longitude:-81
}

///// place dots on the map
var XMLNS = 'http://www.w3.org/2000/svg';
var dot = document.createElementNS(XMLNS,'circle');
document.querySelector('.map').appendChild(dot);
function placeDot(){
  dot.setAttributeNS(null, 'r', 5);
  dot.setAttributeNS(null, 'cy', -(targetPosition.latitude - mapOffset.latitude) * metersPerLatitude / metersPerPixel );
  dot.setAttributeNS(null, 'cx', (targetPosition.longitude - mapOffset.longitude) * metersPerLongitude / metersPerPixel );
}
placeDot();

var zoom = 1;
var metersPerPixel = 5;

function repaint(){
  console.clear();
  console.log(currentPosition);
  
  var map = document.querySelector('.map');
  var y = (currentPosition.latitude - mapOffset.latitude) * metersPerLatitude / metersPerPixel + uiOffsetY;
  var x = -(currentPosition.longitude - mapOffset.longitude) * metersPerLongitude / metersPerPixel + uiOffsetX;
  
  map.setAttributeNS(null,'transform','translate('+x+','+y+')');
  
//   var prox = document.querySelectorAll('.proximity > g');
//   for(var i=0; i<prox.length; i++){
//     var toX = i * 100000 * (targetPosition.longitude - currentPosition.longitude);
//     var toY = i * 100000 * -(targetPosition.latitude - currentPosition.latitude);
//     prox[i].setAttributeNS(null,'transform','translate('+toX+','+toY+')');
//   }
  
  var angle = 360 - Math.atan2(
    (targetPosition.latitude-currentPosition.latitude)*metersPerLatitude,
    (targetPosition.longitude-currentPosition.longitude)*metersPerLongitude
  ) / ( Math.PI * 2) * 360 + 90;
  console.log(angle,'degrees to the target');
  document.getElementById('angleBro').setAttributeNS(null,'transform','rotate('+angle+')');
  
  placeDot();
}
repaint();

// catch keyboard
window.addEventListener('keydown',function(event){
  switch(event.keyCode){
    case 38: // up
      currentPosition.latitude += walkingSpeed / metersPerLatitude;
      break;
    case 40: // down
      currentPosition.latitude -= walkingSpeed / metersPerLatitude;
      break;
    case 39: // right
      currentPosition.longitude += walkingSpeed / metersPerLongitude;
      break;
    case 37: // left
      currentPosition.longitude -= walkingSpeed / metersPerLongitude;
      break;
  }
  repaint();
});

//catch zooming
var zoomEl = document.getElementById('zoom');
var proxGuides = document.querySelectorAll('.proximity > *');
zoomEl.addEventListener('input',function(event){
  metersPerPixel = 10 - 9.9 * Math.pow(event.target.value,0.1) + 0.1;
  repaint();
  console.log(metersPerPixel,'meters per pixel');
});

//// GPS

var GPS = {
  coords:{
    latitude:34.000,
    longitude:-81.000000
  }
};

GPS.activated = false;

GPS.updatePosition = function(position){
	GPS.position = position;
//	console.log('GPS position',position);
};

GPS.handleError = function(error) {
	console.error("GPS error",error);
};

GPS.init = function(){
	if(navigator.geolocation !== undefined) {
		console.log('%cDevice Geolocation works','color:green');
		navigator.geolocation.getCurrentPosition(this.updatePosition, this.handleError, { enableHighAccuracy:true });
		navigator.geolocation.watchPosition(this.updatePosition, this.handleError, { enableHighAccuracy:true });
	} else {
		console.error('Device Geolocation unsupported');
	}
};

              
            
!
999px

Console