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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              
<div id="map"></div>
<button id="bar" class="btn tarmac">Use the thumb controller to switch POIs ↔, zoom ↕ and navigate</button>

<div id="navigation-overlay" class="overlay" style="display: none">
  <h2 id="navigation-destination"></h2>
  <p>
    Curious how to start a navigation? Just use the function
    <a href="https://cobi-bike.github.io/COBI.js/#cobinavigationservicecontrolwrite" target="_blank">COBI.navigationService.control.write()</a> and run the demo in the COBI <b>App</b>.
  </p>
  <p>
    To learn more, please check out the documentation on <a href="https://github.com/cobi-bike/DevKit" target="_blank">GitHub</a>. 
    You can also just fork this pen and play around with it. 
  </p>

  <p>
    Press <b>⊙</b> again to close this dialog.
  </p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.cobi.bike/cobi.js/0.44.0/cobi.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBJmloGS_QRE3aetND1q2CRH6Q_lJiwTyA&libraries=places,geometry"></script>
<script src="https://cdn.cobi.bike/devkit/v1.0.0/js/cobi-style.min.js"></script>

            
          
!

CSS

            
              body,
html {
    height: 100%;
    width: 100%;
}

#map {
    height: 100%;
    width: 100%;
}

#bar {
    position: absolute;
    left: 2%;
    right: 2%;
    bottom: 2%;
    width: 96%;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #F7F7F7;
    padding: 15px 20px;
}

a {
    text-decoration: underline;
}

            
          
!

JS

            
              // ----------- State ------------

let poi = [] // Set of markers
let position = null
let nearbyPosition = null
let currentMarkerIndex = null

// ----------- Map Configuration ------------

const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 16,
    mapTypeId: google.maps.MapTypeId.TERRAIN,
    disableDefaultUI: true,
    styles: [
        { featureType: "poi", stylers: [{ visibility: "off" }] },
        { featureType: "transit", stylers: [{ visibility: "off" }] }
    ]
})

const bikeLayer = new google.maps.BicyclingLayer()
bikeLayer.setMap(map)

const positionMarker = new google.maps.Marker({ map: map })

// ----------- COBI.Bike DevKit Hooks ------------

COBI.init("token — can by anything right now")

COBI.mobile.location.subscribe(function(location) {
    $("#simulator-overlay").fadeOut(300)
    updatePosition(location)
    updateNearbyPlaces()
})

COBI.hub.externalInterfaceAction.subscribe(function(action) {
    switch (action) {
        case "RIGHT":
            return updateSelectedMarker(currentMarkerIndex === null ? 0 : currentMarkerIndex + 1)
        case "LEFT":
            return updateSelectedMarker(currentMarkerIndex === null ? poi.length - 1 : currentMarkerIndex - 1)
        case "UP":
            return map.setZoom(map.getZoom() + 1)
        case "DOWN":
            return map.setZoom(map.getZoom() - 1)
        case "SELECT":
            return toggleRouting()
    }
})

// ----------- Logic ------------

const updatePosition = function(location) {
    position = new google.maps.LatLng(location.coordinate.latitude, location.coordinate.longitude)
    positionMarker.setPosition(position)
    if (currentMarkerIndex === null) {
        map.panTo(position)
    }
}

const updateSelectedMarker = function(index) {
    // Reset icon of last selected marker
    if (currentMarkerIndex !== null) {
        poi[currentMarkerIndex].setIcon(markerIcon)
    }

    // Update index
    currentMarkerIndex = index
    if (currentMarkerIndex >= poi.length || currentMarkerIndex < 0) {
        resetSelectedMarker()
        return
    }

    // Set hilighted icon and scroll to marker
    poi[currentMarkerIndex].setIcon(selectdMarkerIcon)
    map.panTo(poi[currentMarkerIndex].getPosition())

    // Show POI name in info bar 
    $("#bar").fadeIn(300)
    $("#bar").html(poi[currentMarkerIndex].getTitle() + " (press ⊙ to navigate)")
}

const resetSelectedMarker = function() {
    if (currentMarkerIndex !== null) {
        currentMarkerIndex = null
        navigationMarkerIndex = null
        map.panTo(position)
        $("#bar").fadeOut(300)
    }
}

const toggleRouting = function() {
    if (currentMarkerIndex !== null) {
        $("#navigation-destination").html("📍 " + poi[currentMarkerIndex].getTitle())
    }
    $("#navigation-overlay").fadeToggle(300)
}

// ----------- Points of Interest ------------

const service = new google.maps.places.PlacesService(map)
const updateNearbyPlaces = function radar() {
    if (!position) {
        return
    }

    // Only update when position is not too close to the last nearby location
    if (nearbyPosition) {
        const distance = google.maps.geometry.spherical.computeDistanceBetween(position, nearbyPosition)
        if (distance < 50) {
            return
        }
    }

    console.log("🚲 Updating nearby points of interest")
    nearbyPosition = position

    resetSelectedMarker()
    poi.map(marker => marker.setMap(null)) // remove previous markers

    const callback = function(results, status) {
        if (status != google.maps.places.PlacesServiceStatus.OK) {
            console.log("⚠️ Received no results: " + status)
            return
        }

        console.log("🚲 Received " + results.length + " nearby results")

        poi = results.slice(0, 5).map(result => new google.maps.Marker({
            position: result.geometry.location,
            map: map,
            icon: markerIcon,
            title: result.name
        }))
    }

    service.nearbySearch({
        location: position,
        rankBy: google.maps.places.RankBy.DISTANCE,
        type: ["bar"],
        openNow: true
    }, callback)
}

// ----------- Assets ------------

const markerIcon = {
    url: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxzdmcgd2lkdGg9IjQ2cHgiIGhlaWdodD0iNjBweCIgdmlld0JveD0iMCAwIDQ2IDYwIiB2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