Skip to content

Commit

Permalink
Refactor closeness, no pointer events on marker
Browse files Browse the repository at this point in the history
  • Loading branch information
tgs committed Oct 13, 2016
1 parent e5ebab7 commit a498025
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
8 changes: 8 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
border-right: solid thin grey;
border-bottom: solid thin grey;
}
#image-info-text {
color: #fff;
}
html, body {
height: 100%;
margin: 0;
Expand Down Expand Up @@ -107,6 +110,9 @@
div#markerInfo {
display: none;
}
#marker {
pointer-events: none;
}
div.wymercontrol {
margin-top: 10px;
margin-left: 10px;
Expand Down Expand Up @@ -178,6 +184,8 @@
</div>
<div id="pano">
<div class="wymercontrol wymerpanocontrol" id="image-info">
<a href="#" target="_blank" id="image-info-text"
title="Open catalog entry in a new tab"></a>
</div>
<div class="wymercontrol" id="flip-button">
<span class="flip">Flip</span><br>
Expand Down
14 changes: 12 additions & 2 deletions app/js/closeness.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
var metersPerDegreeLng = 85394; // at 40 degrees north
var metersPerDegreeLat = 111035;
var epsilon = 0.1; // choose img this much farther away, if it's preferred

// For simplicity and speed, I'll see if a point is in a rectangle-ish thing
// rather than exactly within 10 meters.

function findClosePoint(queryPoint, points, metersRadius) {
function findClosePoint(queryPoint, points, metersRadius, preferID) {
// return the closest point, if any is within the radius.
var closePoints = findPointsWithin(queryPoint, points, metersRadius);
var closest = closePoints.reduce(function(best, pt) {
if (best === null || pt.dist < best.dist) {
if (best === null) {
return pt;
}
if (pt.dist <= (best.dist + epsilon)) {
// if both are very close, and we have a preferID, override and
// choose the preferred.
if (preferID && (Math.abs(pt.dist - best.dist) < epsilon) &&
(best.point.imageID === preferID)) {
return best;
}
return pt;
}
return best;
Expand Down
17 changes: 11 additions & 6 deletions app/js/fancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ function updateShareButtons() {
}


function updateImageInfo(info) {
$('#image-info').text(info);
function updateImageInfo(image) {
$('#image-info-text')
.text(image.TITLE)
.attr('href', image['CAT Record URL']);
}


Expand Down Expand Up @@ -102,7 +104,7 @@ function initialize(google) {
svo.m_toggleVisible(true);
updateFlipButton();
updateShareButtons();
updateImageInfo(image.TITLE);
updateImageInfo(image);
} else {
console.log("Failed a try to get pano data");
if (giveUpNextTime) {
Expand Down Expand Up @@ -142,14 +144,17 @@ function initialize(google) {
google.maps.event.addListener(svo.pan, 'position_changed', function ()
{
var newPos = svo.pan.getPosition(),
location = {lat: newPos.lat(), lng: newPos.lng()};
newLatLng = {lat: newPos.lat(), lng: newPos.lng()};
svo.map.setCenter(newPos);

// Add markers to the street view that are within a certain number of
// meters from here
updateImageSpots(
closeness.findPointsWithin(location, imageList, 100));
closeness.findPointsWithin(newLatLng, imageList, 100));

// TODO: reuse the list of close points we got earlier
var imageToShow = closeness.findClosePoint(location , imageList, 10);
var imageToShow = closeness.findClosePoint(newLatLng, imageList, 10,
location.hash.slice(1));
if (imageToShow === null) {
svo.m_setImage(null, null);
svo.m_toggleVisible(false);
Expand Down

0 comments on commit a498025

Please sign in to comment.