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 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

              
                <div id="map" class="map"></div>
<div id="mly" class="map"></div>
              
            
!

CSS

              
                body { margin:0; padding:0; height: 100%; }

#mly { position: absolute; height: 100%; width: 50%; }
#map { position: absolute; width: 50%; top: 0; right: 0; bottom: 0; }

              
            
!

JS

              
                const centerCoord = ol.proj.fromLonLat([14.26317443160897, 46.614749220149136]);

const faCircleLineMarkerStyle = new ol.style.Style({
  text: new ol.style.Text({
    text: "\uf111", // fas circle
    scale: 0.7,
    font: "normal 18px FontAwesome",
    fill: new ol.style.Fill({ color: "rgb(255, 0, 0, 0.5)" }),
    stroke: new ol.style.Stroke({ color: "white", width: 4 })
  })
});

const faCircleSolidStyle = new ol.style.Style({
  text: new ol.style.Text({
    text: "\uf111", // fas circle
    scale: 1,
    font: "normal 18px FontAwesome",
    fill: new ol.style.Fill({ color: "red" }),
    stroke: new ol.style.Stroke({ color: "white", width: 4 })
  })
});

let faWifiStyle = new ol.style.Style({
  text: new ol.style.Text({
    text: "\uf1eb", // fas circle
    scale: 1.2,
    font: "normal 18px FontAwesome",
    offsetY: -10,
    rotation: 0,
    fill: new ol.style.Fill({ color: "red" }),
    stroke: new ol.style.Stroke({ color: "red", width: 3 })
  })
});

let updateBearingStyle = function(bearing) {
  liveBearing = new ol.style.Style({
    text: new ol.style.Text({
      text: "\uf1eb", // fas circle
      scale: 1.2,
      font: "normal 18px FontAwesome",
      offsetY: -10,
      rotation: bearing * Math.PI / 180, // value must be radians, bearing is degrees
      fill: new ol.style.Fill({ color: "red" }),
      stroke: new ol.style.Stroke({ color: "red", width: 3 })
    })
  });

  return [liveBearing, faCircleSolidStyle];
};

const mapillaryId = "QjI1NnU0aG5FZFZISE56U3R5aWN4ZzplNDVjNDc0YmYwYjJmYjQ0";
const startImageId = "w3p5M6s6J3HoX1ZREqXZIw";

const urlStartImage =  "https://a.mapillary.com/v3/images/" +  startImageId +  "?client_id=" +  mapillaryId;
const urlSequence =  "https://a.mapillary.com/v3/sequences/JMOBN38RSF2h6dpuuiBz6w?client_id=" +  mapillaryId;

const urlImages =  "https://a.mapillary.com/v3/images?client_id=" +  mapillaryId +  "&sequence_keys=JMOBN38RSF2h6dpuuiBz6w";

let imageListSource = new ol.source.Vector({
  projection: "EPSG:3857",
  url: urlImages,
  format: new ol.format.GeoJSON()
});

let imageListLayer = new ol.layer.Vector({
  source: imageListSource,
  style: faCircleLineMarkerStyle
});

var seqSource = new ol.source.Vector({
  projection: "EPSG:3857",
  url: urlSequence,
  format: new ol.format.GeoJSON()
});

const seqLayer = new ol.layer.Vector({
  source: seqSource,
  style: new ol.style.Style({
    stroke: new ol.style.Stroke({ color: "white", width: 4 })
  })
});

const pointFeature = new ol.Feature({
  geometry: new ol.geom.Point(centerCoord)
});

pointFeature.setStyle([faWifiStyle, faCircleSolidStyle]);

let movingPointLayer = new ol.layer.Vector({
  source: new ol.source.Vector({ features: [pointFeature] })
});

const osmLayer = new ol.layer.Tile({
  source: new ol.source.OSM()
});

const map = new ol.Map({
  target: "map",
  layers: [osmLayer, seqLayer, imageListLayer, movingPointLayer],
  view: new ol.View({
    center: centerCoord,
    zoom: 20
  })
});

let featureOverlay = new ol.layer.Vector({
  source: new ol.source.Vector(),
  map: map,
  style: [faWifiStyle, faCircleSolidStyle]
});

let mly = new Mapillary.Viewer("mly", mapillaryId, startImageId, {
  component: {
    cover: false
  }
});

let highlight;
let displayFeatureInfo = function(pixel, isClick) {
  let feature = map.forEachFeatureAtPixel(
    pixel,
    function(feature, layer) {
      return feature;
    },
    { // this is optional
      // it only allows the user to click the circles along the line and not the line itself
      layerFilter: function(layer) {
        return layer === imageListLayer;
      },
      hitTolerance: 5 // defines how close a user must have the mouse to a circle
    }
  );

  if (feature) {

    if (isClick) {
      let bearing = feature.get('ca');
      mly.moveToKey(feature.get("key"));
      featureOverlay.setStyle(updateBearingStyle(bearing));
    }
  } else {
    return;
  }

  if (feature !== highlight) {
    if (highlight) {
      featureOverlay.getSource().removeFeature(highlight);
    }
    if (feature) {
      featureOverlay.getSource().addFeature(feature);
    }
    highlight = feature;
  }
};


mly.on(Mapillary.Viewer.nodechanged, function(node) {
  if (featureOverlay.getVisible()) {
    featureOverlay.setVisible(false);
  }
  // use the coordinate of the circle on the line, not the interpreted coordinate
  let lonLat = ol.proj.fromLonLat([
    node.originalLatLon.lon,
    node.originalLatLon.lat
  ]);
  map.getView().setCenter(lonLat);
  pointFeature.getGeometry().setCoordinates(lonLat);
  pointFeature.setStyle(updateBearingStyle(node.ca));
  
});

map.on("click", function(evt) {
  displayFeatureInfo(evt.pixel, true);
});

window.addEventListener("resize", function() {
  mly.resize();
});

              
            
!
999px

Console