This commit is contained in:
Jon Atkins 2015-02-12 19:22:56 +00:00
commit 455e2c0535
16 changed files with 468 additions and 126 deletions

View File

@ -591,7 +591,7 @@ function boot() {
window.setupDialogs();
window.setupMap();
window.setupOMS();
window.setupGeosearch();
window.search.setup();
window.setupRedeem();
window.setupLargeImagePreview();
window.setupSidebarToggle();

View File

@ -1,71 +0,0 @@
// GEOSEARCH /////////////////////////////////////////////////////////
window.setupGeosearch = function() {
$('#geosearch').keypress(function(e) {
if((e.keyCode ? e.keyCode : e.which) != 13) return;
var search = $(this).val();
if ( window.search(search) ) return;
e.preventDefault();
});
$('#geosearchwrapper img').click(function(){
map.locate({setView : true, maxZoom: 13});
});
$('#geosearch').keyup(function(){$(this).removeClass('search_not_found')});
window.searchResultLayer = L.layerGroup();
map.addLayer(window.searchResultLayer);
}
window.search = function(search) {
window.searchResultLayer.clearLayers();
var searchMarkerOptions = {color:'red', weight:3, opacity: 0.5, fill:false, dashArray:"5,5", clickable:false};
if (!runHooks('geoSearch', search)) {
return true;
}
if(search.split(",").length == 2) {
var ll = search.split(",");
if(!isNaN(ll[0]) && !isNaN(ll[1])) {
ll = [parseFloat(ll[0]), parseFloat(ll[1])];
if(ll[0] >= -90 && ll[0] <= 90 && ll[1] >= -180 && ll[1] <= 180) {
var ll = L.latLng(ll);
window.map.setView(ll, 17);
window.searchResultLayer.clearLayers();
window.searchResultLayer.addLayer(L.circleMarker(ll,searchMarkerOptions));
if(window.isSmartphone()) window.show('map');
return true;
}
}
}
$.getJSON(NOMINATIM + encodeURIComponent(search), function(data) {
if(!data || !data[0]) {
$('#geosearch').addClass('search_not_found');
return true;
}
var b = data[0].boundingbox;
if(!b) return true;
var southWest = new L.LatLng(b[0], b[2]),
northEast = new L.LatLng(b[1], b[3]),
bounds = new L.LatLngBounds(southWest, northEast);
window.searchResultLayer.clearLayers();
if (southWest.equals(northEast)) {
window.searchResultLayer.addLayer(L.circleMarker(southWest,searchMarkerOptions));
} else {
window.searchResultLayer.addLayer(L.rectangle(bounds,searchMarkerOptions));
}
window.map.fitBounds(bounds, {maxZoom: 17});
if(window.isSmartphone()) window.show('map');
});
}

View File

@ -59,7 +59,7 @@ window.VALID_HOOKS = [
'portalAdded', 'linkAdded', 'fieldAdded',
'publicChatDataAvailable', 'factionChatDataAvailable',
'requestFinished', 'nicknameClicked',
'geoSearch', 'iitcLoaded',
'geoSearch', 'search', 'iitcLoaded',
'portalDetailLoaded', 'paneChanged'];
window.runHooks = function(event, data) {

290
code/search.js Normal file
View File

@ -0,0 +1,290 @@
// SEARCH /////////////////////////////////////////////////////////
/*
you can implement your own result provider by listing to the search hook:
addHook('search', function(query) {});
`query` is an object with the following members:
- `term` is the term for which the user has searched
- `confirmed` is a boolean indicating if the user has pressed enter after searching. You should not search online or
heavy processing unless the user has confirmed the search term
- `addResult(result)` can be called to add a result to the query.
`result` may have the following members (`title` is required, as well as one of `position` and `bounds`):
- `title`: the label for this result
- `description`: secondary information for this result
- `position`: a L.LatLng object describing the position of this result
- `bounds`: a L.LatLngBounds object describing the bounds of this result
- `layer`: a ILayer to be added to the map when the user selects this search result. Will be generated if not set.
Set to `null` to prevent the result from being added to the map.
- `icon`: a URL to a icon to display in the result list. Should be 12x12.
- `onSelected(result, event)`: a handler to be called when the result is selected. May return `true` to prevent the map
from being repositioned. You may reposition the map yourself or do other work.
- `onRemove(result)`: a handler to be called when the result is removed from the map (because another result has been
selected or the search was cancelled by the user).
*/
window.search = {
lastSearch: null,
};
window.search.Query = function(term, confirmed) {
this.term = term;
this.confirmed = confirmed;
this.init();
};
window.search.Query.prototype.init = function() {
this.results = [];
this.container = $('<div>').addClass('searchquery');
this.header = $('<h3>')
.text(this.confirmed
? this.term
: ((this.term.length > 16
? this.term.substr(0,8) + '…' + this.term.substr(this.term.length-8,8)
: this.term)
+ ' (Return to load more)'))
.appendTo(this.container);
this.list = $('<ul>')
.appendTo(this.container)
.append($('<li>').text('No results'));
this.container.accordion({
collapsible: true,
heightStyle: 'content',
});
runHooks('search', this);
};
window.search.Query.prototype.show = function() {
this.container.appendTo('#searchwrapper');
};
window.search.Query.prototype.hide = function() {
this.container.remove();
this.removeSelectedResult();
};
window.search.Query.prototype.addResult = function(result) {
if(this.results.length == 0) {
// remove 'No results'
this.list.empty();
}
this.results.push(result);
var item = $('<li>')
.appendTo(this.list)
.attr('tabindex', '0')
.on('click dblclick', function(ev) {
this.onResultSelected(result, ev);
}.bind(this))
.keypress(function(ev) {
if((ev.keyCode || ev.charCode || ev.which) == 32) {
ev.preventDefault();
ev.type = 'click';
$(this).trigger(ev);
return;
}
if((ev.keyCode || ev.charCode || ev.which) == 13) {
ev.preventDefault();
ev.type = 'dblclick';
$(this).trigger(ev);
return;
}
});
var link = $('<a>')
.text(result.title)
.appendTo(item);
if(result.icon) {
link.css('background-image', 'url("'+result.icon+'")');
item.css('list-style', 'none');
}
if(result.description) {
item
.append($('<br>'))
.append($('<em>')
.text(result.description));
}
};
window.search.Query.prototype.onResultSelected = function(result, ev) {
this.removeSelectedResult();
this.selectedResult = result;
if(result.onSelected) {
if(result.onSelected(result, ev)) return;
}
if(ev.type == 'dblclick') {
if(result.position) {
map.setView(result.position, 17);
} else if(result.bounds) {
map.fitBounds(result.bounds, {maxZoom: 17});
}
} else { // ev.type != 'dblclick'
if(result.bounds) {
map.fitBounds(result.bounds, {maxZoom: 17});
} else if(result.position) {
map.setView(result.position);
}
}
if(result.layer !== null && !result.layer) {
result.layer = L.layerGroup();
if(result.position) {
var markerTemplate = '@@INCLUDESTRING:images/marker-icon.svg.template@@';
L.marker(result.position, {
icon: L.divIcon({
iconSize: new L.Point(25, 41),
iconAnchor: new L.Point(12, 41),
html: markerTemplate.replace(/%COLOR%/g, 'red'),
className: 'leaflet-iitc-search-result-icon',
}),
title: result.title,
}).addTo(result.layer);
}
if(result.bounds) {
L.rectangle(result.bounds, {
title: result.title,
clickable: false,
color: 'red',
fill: false,
}).addTo(result.layer);
}
}
if(result.layer)
map.addLayer(result.layer);
if(window.isSmartphone()) window.show('map');
}
window.search.Query.prototype.removeSelectedResult = function() {
if(this.selectedResult) {
if(this.selectedResult.layer) map.removeLayer(this.selectedResult.layer);
if(this.selectedResult.onRemove) this.selectedResult.onRemove(this.selectedResult);
}
}
window.search.doSearch = function(term, confirmed) {
term = term.trim();
// minimum 3 characters for automatic search
if(term.length < 3 && !confirmed) return;
// don't clear last confirmed search
if(window.search.lastSearch
&& window.search.lastSearch.confirmed
&& !confirmed)
return;
// don't make the same query again
if(window.search.lastSearch
&& window.search.lastSearch.confirmed == confirmed
&& window.search.lastSearch.term == term)
return;
if(window.search.lastSearch) window.search.lastSearch.hide();
window.search.lastSearch = null;
// clear results
if(term == '') return;
$('#search').tooltip().tooltip('close');
window.search.lastSearch = new window.search.Query(term, confirmed);
window.search.lastSearch.show();
};
window.search.setup = function() {
$('#search')
.keypress(function(e) {
if((e.keyCode ? e.keyCode : e.which) != 13) return;
e.preventDefault();
var term = $(this).val();
clearTimeout(window.search.timer);
window.search.doSearch(term, true);
})
.on('keyup keypress change paste', function(e) {
clearTimeout(window.search.timer);
window.search.timer = setTimeout(function() {
var term = $(this).val();
window.search.doSearch(term, false);
}.bind(this), 500);
});
$('#buttongeolocation').click(function(){
map.locate({setView : true, maxZoom: 13});
});
};
addHook('search', function(query) {
var term = query.term.toLowerCase();
var teams = ['NEU','RES','ENL'];
$.each(portals, function(guid, portal) {
var data = portal.options.data;
if(data.title.toLowerCase().indexOf(term) !== -1) {
var team = portal.options.team;
var color = team==TEAM_NONE ? '#CCC' : COLORS[team];
query.addResult({
title: data.title,
description: teams[team] + ', L' + data.level + ', ' + data.health + '%, ' + data.resCount + ' Resonators',
position: portal.getLatLng(),
icon: 'data:image/svg+xml;base64,'+btoa('@@INCLUDESTRING:images/icon-portal.svg@@'.replace(/%COLOR%/g, color)),
onSelected: function(result, event) {
if(event.type == 'dblclick')
zoomToAndShowPortal(guid, portal.getLatLng());
else if(window.portals[guid])
renderPortalDetails(guid);
else
window.selectPortalByLatLng(portal.getLatLng());
return true; // prevent default behavior
},
});
}
});
});
// TODO: recognize 50°31'03.8"N 7°59'05.3"E and similar formats
addHook('search', function(query) {
if(query.term.split(',').length == 2) {
var ll = query.term.split(',');
if(!isNaN(ll[0]) && !isNaN(ll[1])) {
query.addResult({
title: query.term,
position: L.latLng(parseFloat(ll[0]), parseFloat(ll[1])),
});
}
}
});
addHook('search', function(query) {
if(!query.confirmed) return;
$.getJSON(NOMINATIM + encodeURIComponent(query.term), function(data) {
data.forEach(function(item) {
var result = {
title: item.display_name,
description: 'Type: ' + item.type,
position: L.latLng(parseFloat(item.lat), parseFloat(item.lon)),
};
var b = item.boundingbox;
if(b) {
var southWest = new L.LatLng(b[0], b[2]),
northEast = new L.LatLng(b[1], b[3]);
result.bounds = new L.LatLngBounds(southWest, northEast);
}
query.addResult(result);
});
});
});

View File

@ -273,6 +273,9 @@ window.selectPortalByLatLng = function(lat, lng) {
if(lng === undefined && lat instanceof Array) {
lng = lat[1];
lat = lat[0];
} else if(lng === undefined && lat instanceof L.LatLng) {
lng = lat.lng;
lat = lat.lat;
}
for(var guid in window.portals) {
var latlng = window.portals[guid].getLatLng();

View File

Before

Width:  |  Height:  |  Size: 730 B

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

BIN
images/icon-bookmark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

7
images/icon-portal.svg Normal file
View File

@ -0,0 +1,7 @@
<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" width="12" height="12" version="1.1">
<g style="fill:%COLOR%;stroke:none">
<path d="m 6,12 -2,-12 4,0 z" />
<path d="m 6,12 -4, -8 8,0 z" />
<path d="m 6,12 -6, -4 12,0 z" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 280 B

View File

@ -91,9 +91,9 @@ document.getElementsByTagName('body')[0].innerHTML = ''
+ ' <div id="sidebar" style="display: none">'
+ ' <div id="playerstat">t</div>'
+ ' <div id="gamestat">&nbsp;loading global control stats</div>'
+ ' <div id="geosearchwrapper">'
+ ' <input id="geosearch" placeholder="Search location…" type="text" accesskey="f" title="Search for a place [f]"/>'
+ ' <img src="@@INCLUDEIMAGE:images/current-location.png@@"/ title="Current Location">'
+ ' <div id="searchwrapper">'
+ ' <img src="@@INCLUDEIMAGE:images/current-location.png@@"/ title="Current Location" id="buttongeolocation">'
+ ' <input id="search" placeholder="Search location…" type="search" accesskey="f" title="Search for a place [f]"/>'
+ ' </div>'
+ ' <div id="portaldetails"></div>'
+ ' <input id="redeem" placeholder="Redeem code…" type="text"/>'
@ -167,7 +167,7 @@ window.PORTAL_RADIUS_ENLARGE_MOBILE = 5;
window.DEFAULT_PORTAL_IMG = '//commondatastorage.googleapis.com/ingress.com/img/default-portal-image.png';
//window.NOMINATIM = '//nominatim.openstreetmap.org/search?format=json&limit=1&q=';
window.NOMINATIM = '//open.mapquestapi.com/nominatim/v1/search.php?format=json&limit=1&q=';
window.NOMINATIM = '//open.mapquestapi.com/nominatim/v1/search.php?format=json&q=';
// INGRESS CONSTANTS /////////////////////////////////////////////////
// http://decodeingress.me/2012/11/18/ingress-portal-levels-and-link-range/

View File

@ -276,7 +276,7 @@ public class IITC_Mobile extends Activity
searchView.clearFocus();
switchToPane(Pane.MAP);
mIitcWebView.loadUrl("javascript:search('" + query + "');");
mIitcWebView.loadUrl("javascript:if(window.search&&window.search.doSearch){window.search.doSearch('" + query + "',true);window.show('info')}");
return;
}

View File

@ -283,7 +283,7 @@
cursor:pointer;
}
#bkmrksTrigger, .bkmrksStar span, .portal-list-bookmark span {
background-image:url(@@INCLUDEIMAGE:plugins/bookmarks-img.png@@);
background-image:url(@@INCLUDEIMAGE:images/bookmarks-img.png@@);
}
.bkmrksStar span{
display:inline-block;

View File

@ -479,6 +479,55 @@
console.log('Move Bookmarks '+type+' ID:'+idBkmrk+' from folder ID:'+oldFold+' to folder ID:'+newFold);
}
window.plugin.bookmarks.onSearch = function(query) {
var term = query.term.toLowerCase();
$.each(plugin.bookmarks.bkmrksObj.maps, function(id, folder) {
$.each(folder.bkmrk, function(id, bookmark) {
if(bookmark.label.toLowerCase().indexOf(term) === -1) return;
query.addResult({
title: bookmark.label,
description: 'Map in folder "' + folder.label + '"',
icon: '@@INCLUDEIMAGE:images/icon-bookmark-map.png@@',
position: L.latLng(bookmark.latlng.split(",")),
zoom: bookmark.z,
onSelected: window.plugin.bookmarks.onSearchResultSelected,
});
});
});
$.each(plugin.bookmarks.bkmrksObj.portals, function(id, folder) {
$.each(folder.bkmrk, function(id, bookmark) {
if(bookmark.label.toLowerCase().indexOf(term) === -1) return;
query.addResult({
title: bookmark.label,
description: 'Bookmark in folder "' + folder.label + '"',
icon: '@@INCLUDEIMAGE:images/icon-bookmark.png@@',
position: L.latLng(bookmark.latlng.split(",")),
guid: bookmark.guid,
onSelected: window.plugin.bookmarks.onSearchResultSelected,
});
});
});
};
window.plugin.bookmarks.onSearchResultSelected = function(result, event) {
if(result.guid) { // portal
var guid = result.guid;
if(event.type == 'dblclick')
zoomToAndShowPortal(guid, result.position);
else if(window.portals[guid])
renderPortalDetails(guid);
else
window.selectPortalByLatLng(result.position);
} else if(result.zoom) { // map
map.setView(result.position, result.zoom);
}
return true; // prevent default behavior
};
/***************************************************************************************************************************************************************/
// Saved the new sort of the folders (in the localStorage)
@ -1060,7 +1109,7 @@
/***************************************************************************************************************************************************************/
window.plugin.bookmarks.setupCSS = function() {
$('<style>').prop('type', 'text/css').html('@@INCLUDESTRING:plugins/bookmarks-css.css@@').appendTo('head');
$('<style>').prop('type', 'text/css').html('@@INCLUDESTRING:plugins/bookmarks-by-zaso.css@@').appendTo('head');
}
window.plugin.bookmarks.setupPortalsList = function() {
@ -1219,6 +1268,7 @@
if(window.plugin.bookmarks.statusBox['page'] === 1) { $('#bookmarksBox h5.bkmrk_portals').trigger('click'); }
window.addHook('portalSelected', window.plugin.bookmarks.onPortalSelected);
window.addHook('search', window.plugin.bookmarks.onSearch);
// Sync
window.addHook('pluginBkmrksEdit', window.plugin.bookmarks.syncBkmrks);

View File

@ -27,6 +27,8 @@ window.PLAYER_TRACKER_LINE_COLOUR = '#FF00FD';
window.plugin.playerTracker = function() {};
window.plugin.playerTracker.setup = function() {
$('<style>').prop('type', 'text/css').html('@@INCLUDESTRING:plugins/player-tracker.css@@').appendTo('head');
var iconEnlImage = '@@INCLUDEIMAGE:images/marker-green.png@@';
var iconEnlRetImage = '@@INCLUDEIMAGE:images/marker-green-2x.png@@';
var iconResImage = '@@INCLUDEIMAGE:images/marker-blue.png@@';
@ -407,6 +409,8 @@ window.plugin.playerTracker.drawData = function() {
m.on('mouseout', function() { $(this._icon).tooltip('close'); });
}
playerData.marker = m;
m.addTo(playerData.team === 'RESISTANCE' ? plugin.playerTracker.drawnTracesRes : plugin.playerTracker.drawnTracesEnl);
window.registerMarkerForOMS(m);
@ -485,34 +489,39 @@ window.plugin.playerTracker.handleData = function(data) {
plugin.playerTracker.drawData();
}
window.plugin.playerTracker.findUserPosition = function(nick) {
window.plugin.playerTracker.findUser = function(nick) {
nick = nick.toLowerCase();
var foundPlayerData = undefined;
var foundPlayerData = false;
$.each(plugin.playerTracker.stored, function(plrname, playerData) {
if (playerData.nick.toLowerCase() === nick) {
foundPlayerData = playerData;
return false;
}
});
return foundPlayerData;
}
if (!foundPlayerData) {
return false;
}
window.plugin.playerTracker.findUserPosition = function(nick) {
var data = window.plugin.playerTracker.findUser(nick);
if (!data) return false;
var evtsLength = foundPlayerData.events.length;
var last = foundPlayerData.events[evtsLength-1];
var last = data.events[data.events.length - 1];
return plugin.playerTracker.getLatLngFromEvent(last);
}
window.plugin.playerTracker.centerMapOnUser = function(nick) {
var position = plugin.playerTracker.findUserPosition(nick);
var data = plugin.playerTracker.findUser(nick);
if(!data) return false;
if (position === false) {
return false;
}
var last = data.events[data.events.length - 1];
var position = plugin.playerTracker.getLatLngFromEvent(last);
if(window.isSmartphone()) window.smartphone.mapButton.click();
if(window.isSmartphone()) window.show('map');
window.map.setView(position, map.getZoom());
if(data.marker) {
window.plugin.playerTracker.onClickListener({target: data.marker});
}
}
window.plugin.playerTracker.onNicknameClicked = function(info) {
@ -522,22 +531,39 @@ window.plugin.playerTracker.onNicknameClicked = function(info) {
}
}
window.plugin.playerTracker.onGeoSearch = function(search) {
if (/^@/.test(search)) {
plugin.playerTracker.centerMapOnUser(search.replace(/^@/, ''));
return false;
}
window.plugin.playerTracker.onSearchResultSelected = function(result, event) {
if(window.isSmartphone()) window.show('map');
// if the user moved since the search was started, check if we have a new set of data
if(false === window.plugin.playerTracker.centerMapOnUser(result.title))
map.setView(result.position);
if(event.type == 'dblclick')
map.setZoom(17);
return true;
};
window.plugin.playerTracker.onSearch = function(query) {
var term = query.term.toLowerCase();
$.each(plugin.playerTracker.stored, function(nick, data) {
if(nick.toLowerCase().indexOf(term) === -1) return;
var event = data.events[data.events.length - 1];
query.addResult({
title: nick,
description: data.team.substr(0,3) + ', last seen ' + unixTimeToDateTimeString(event.time),
position: plugin.playerTracker.getLatLngFromEvent(event),
onSelected: window.plugin.playerTracker.onSearchResultSelected,
});
});
}
window.plugin.playerTracker.setupUserSearch = function() {
$('<style>').prop('type', 'text/css').html('@@INCLUDESTRING:plugins/player-tracker.css@@').appendTo('head');
addHook('nicknameClicked', window.plugin.playerTracker.onNicknameClicked);
addHook('geoSearch', window.plugin.playerTracker.onGeoSearch);
var geoSearch = $('#geosearch');
var beforeEllipsis = /(.*)…/.exec(geoSearch.attr('placeholder'))[1];
geoSearch.attr('placeholder', beforeEllipsis + ' or @player…');
addHook('search', window.plugin.playerTracker.onSearch);
}

View File

@ -22,10 +22,10 @@ window.plugin.speechSearch = function() {};
window.plugin.speechSearch.setup = function() {
// Give the search input the speech attribute
$("#geosearch").attr("x-webkit-speech", "");
$("#search").attr("x-webkit-speech", "");
// Immediately search without further input
$("#geosearch").bind("webkitspeechchange", function() {
$("#geosearch").trigger($.Event("keypress", {keyCode: 13}));
$("#search").bind("webkitspeechchange", function() {
$("#search").trigger($.Event("keypress", {keyCode: 13}));
});
};

View File

@ -485,7 +485,7 @@ h2 sup, h2 sub {
}
/* geosearch input, and others */
/* search input, and others */
input:not([type]), .input,
input[type="text"], input[type="password"],
input[type="number"], input[type="email"],
@ -502,23 +502,60 @@ input[type="search"], input[type="url"] {
box-sizing: border-box;
}
#geosearch{
width:272px;
background-color: transparent;
#searchwrapper {
position: relative;
}
#geosearchwrapper {
height:25px;
background-color: rgba(0, 0, 0, 0.3);
#search {
width: 100%;
padding-right: 24px;
}
#geosearchwrapper img{
vertical-align: bottom;
margin-bottom: 2px;
#buttongeolocation {
position: absolute;
top: 2px;
right: 2px;
cursor: pointer;
}
.search_not_found{
color:red;
font-style: italic;
#searchwrapper h3 {
font-size: 1em;
height: auto;
cursor: pointer;
}
.searchquery {
max-height: 25em;
overflow-y: auto;
}
#searchwrapper .ui-accordion-header::before {
font-size: 18px;
margin-right: 2px;
font-weight: normal;
line-height: 1em;
content: "⊞";
}
#searchwrapper .ui-accordion-header-active::before {
content: "⊟";
}
#searchwrapper .ui-accordion-content {
margin: 0;
overflow: hidden;
}
#searchwrapper ul {
padding-left: 14px;
}
#searchwrapper li {
cursor: pointer;
}
#searchwrapper li a {
margin-left: -14px;
padding-left: 14px;
background-position: 1px center;
background-repeat: no-repeat;
}
#searchwrapper li:focus a, #searchwrapper li:hover a {
text-decoration: underline;
}
#searchwrapper li em {
color: #ccc;
font-size: 0.9em;
}
::-webkit-input-placeholder {
@ -546,7 +583,7 @@ h3 {
margin:0;
height: 23px;
width: 100%;
overflow:hidden;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
-webkit-box-sizing: border-box;