Skip to content

Commit

Permalink
Support places search in viewfinder view
Browse files Browse the repository at this point in the history
Replace lat,long-only search with search for reqular query strings.

fixes #2280
fixes #2270
fixes #1796
  • Loading branch information
ianguerin committed Mar 6, 2024
1 parent bdd4e21 commit 81e357c
Show file tree
Hide file tree
Showing 12 changed files with 843 additions and 405 deletions.
Binary file modified docs/screenshots/views/maps/viewfinder/ViewfinderView.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 51 additions & 3 deletions src/css/map-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
}

/* hide the credits until we can find a better placement for them */
.cesium-widget-credits, .cesium-credit-lightbox-overlay {
.cesium-widget-credits,
.cesium-credit-lightbox-overlay {
display: none !important;
}

Expand Down Expand Up @@ -991,7 +992,7 @@ other class: .ui-slider-range */
*
*/

.map-help-panel{
.map-help-panel {
width: 100%;
}

Expand Down Expand Up @@ -1060,7 +1061,7 @@ other class: .ui-slider-range */
align-items: center;
}

.map-help-panel__title{
.map-help-panel__title {
text-transform: uppercase;
font-size: 0.95rem;
font-weight: 600;
Expand All @@ -1073,6 +1074,10 @@ other class: .ui-slider-range */
margin-top: 2.5rem;
}

.viewfinder {
width: 100%;
}

.viewfinder__field {
border-radius: 4px;
border: 1px solid var(--portal-col-bkg-active);
Expand All @@ -1091,6 +1096,7 @@ other class: .ui-slider-range */
flex: 1;
height: 100%;
margin: 0;
height: 48px;

&:focus {
border: none;
Expand All @@ -1114,4 +1120,46 @@ other class: .ui-slider-range */
color: var(--map-col-text);
font-size: .8rem;
padding: 4px 12px;
}

.viewfinder-predictions {
list-style: none;
margin: 0;

.viewfinder-prediction__content {
align-items: center;
background: var(--map-col-bkg);
border: 1px solid var(--portal-col-bkg-active);
border-radius: 4px;
box-sizing: border-box;
color: var(--map-col-text);
cursor: pointer;
display: flex;
height: 48px;
justify-content: flex-start;
margin: 4px 0;
padding: 12px 8px;

>* {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

i {
flex-grow: 0;
min-width: 24px;
max-width: 24px;
text-align: center;
}

&:hover {
background-color: var(--map-col-bkg-lightest);
}

&.viewfinder-prediction__focused {
background-color: var(--map-col-bkg-lighter);
}
}
}
69 changes: 35 additions & 34 deletions src/js/models/maps/viewfinder/ViewfinderModel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

define(
[
'underscore',
Expand Down Expand Up @@ -104,39 +105,6 @@ define(
this.set('focusIndex', -1);
},

/**
* Event handler for Backbone.View configuration that is called whenever
* the user clicks the search button or hits the Enter key.
* @param {string} value is the query string.
*/
async search(value) {
// This is not a lat,long value, so geocode the prediction instead.
if (!GeoPoint.couldBeLatLong(value)) {
const focusedIndex = Math.max(0, this.get("focusIndex"));
this.selectPrediction(this.get('predictions')[focusedIndex]);
return;
}

try {
const geoPoint = GeoPoint.fromString(value);
geoPoint.set("height", 10000 /* meters */);
if (geoPoint.isValid()) {
this.set('error', '');
this.mapModel.zoomTo(geoPoint);
return;
}

const errors = geoPoint.validationError;
if (errors.latitude) {
this.set('error', errors.latitude);
} else if (errors.longitude) {
this.set('error', errors.longitude);
}
} catch (e) {
this.set('error', e.message);
}
},

/**
* Navigate to the GeocodedLocation.
* @param {GeocodedLocation} geocoding is the location that corresponds
Expand Down Expand Up @@ -164,7 +132,7 @@ define(
async selectPrediction(prediction) {
if (!prediction) return;

const geocodings = await this.geocoderSearch.searchByPlaceId(
const geocodings = await this.geocoderSearch.geocode(
prediction.get('googleMapsPlaceId')
);

Expand All @@ -176,6 +144,39 @@ define(
this.trigger('selection-made', prediction.get('description'));
this.goToLocation(geocodings[0]);
},

/**
* Event handler for Backbone.View configuration that is called whenever
* the user clicks the search button or hits the Enter key.
* @param {string} value is the query string.
*/
async search(value) {
// This is not a lat,long value, so geocode the prediction instead.
if (!GeoPoint.couldBeLatLong(value)) {
const focusedIndex = Math.max(0, this.get("focusIndex"));
this.selectPrediction(this.get('predictions')[focusedIndex]);
return;
}

try {
const geoPoint = GeoPoint.fromString(value);
geoPoint.set("height", 10000 /* meters */);
if (geoPoint.isValid()) {
this.set('error', '');
this.mapModel.zoomTo(geoPoint);
return;
}

const errors = geoPoint.validationError;
if (errors.latitude) {
this.set('error', errors.latitude);
} else if (errors.longitude) {
this.set('error', errors.longitude);
}
} catch (e) {
this.set('error', e.message);
}
},
});

return ViewfinderModel;
Expand Down
30 changes: 13 additions & 17 deletions src/js/templates/maps/viewfinder/viewfinder.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
<div class="<%= classNames.baseClass %>">
<h2>Viewfinder</h2>
<span>Enter a latitude and longitude pair and click search to show that point on the map.</span>
<br /><br />
<div class="viewfinder__form-field">
<div class="viewfinder__field">
<input class="<%= classNames.input %>" type="text" placeholder="<%= placeholder %>" value="<%= inputValue %>" />
<button class="<%= classNames.button %>">
<i class="icon icon-search"></i>
</button>
</div>
<h2>Viewfinder</h2>
<div class="viewfinder__form-field">
<div class="viewfinder__field">
<input class="<%= classNames.input %>" type="text" placeholder="<%= placeholder %>" value="<%= inputValue %>" />
<button class="<%= classNames.button %>">
<i class="icon icon-search"></i>
</button>
</div>

<% if(errorMessage) { %>
<div class="viewfinder__error">
<%= errorMessage %>
</div>
<% } %>
<div class="<%= classNames.error %>">
<%= errorMessage %>
</div>
</div>
</div>

<div class="<%= classNames.predictions %>" tabindex="0"></div>
2 changes: 1 addition & 1 deletion src/js/views/maps/ToolbarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define(
'views/maps/LayerListView',
'views/maps/DrawToolView',
'views/maps/HelpPanelView',
'views/maps/ViewfinderView',
'views/maps/viewfinder/ViewfinderView',
],
function (
$,
Expand Down
Loading

0 comments on commit 81e357c

Please sign in to comment.