Mercurial > hg > batmud > maputils
changeset 2114:2b9b9e0f89b3
Add maxMatches argument to nearby location search.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 10 Sep 2019 19:26:04 +0300 |
parents | 282f84c10f97 |
children | a302e99398f1 |
files | mapsearch.c www/search.js |
diffstat | 2 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mapsearch.c Tue Sep 10 17:52:56 2019 +0300 +++ b/mapsearch.c Tue Sep 10 19:26:04 2019 +0300 @@ -1316,7 +1316,7 @@ { MAPMatch matches[SET_MAX_MATCHES]; LocMarker **nearest = NULL; - int findXC, findYC, maxDist, nnearest = 0; + int findXC, findYC, maxDist, nnearest = 0, maxMatches = SET_MAX_MATCHES; size_t offs = 0; // Get coordinates @@ -1339,6 +1339,14 @@ // Get max distance, default to some value if (!mapParseIntValue(data, len, &offs, &maxDist)) maxDist = 50; + else + { + offs++; + + // Get max matches amount + if (!mapParseIntValue(data, len, &offs, &maxMatches)) + maxMatches = SET_MAX_MATCHES; + } // Check values if (findXC < 0 || findYC < 0) @@ -1353,13 +1361,19 @@ goto out; } + if (maxMatches < 1) + maxMatches = 1; + else + if (maxMatches > SET_MAX_MATCHES) + maxMatches = SET_MAX_MATCHES; + // Find nearest locations nnearest = mapNearbyLocationSearch(&nearest, findXC, findYC, maxDist, verr); if (*verr != NULL) goto out; - if (nnearest >= SET_MAX_MATCHES) - nnearest = SET_MAX_MATCHES; + if (nnearest >= maxMatches) + nnearest = maxMatches; for (int nloc = 0; nloc < nnearest; nloc++) {
--- a/www/search.js Tue Sep 10 17:52:56 2019 +0300 +++ b/www/search.js Tue Sep 10 19:26:04 2019 +0300 @@ -356,6 +356,7 @@ // Check the search pattern for some sanity before // submitting to the server .. though we do checks there also. + var nearby = false; var tmp = fieldLocPattern.value.trim(); if (tmp == "") { @@ -369,6 +370,12 @@ return; } + if (tmp.substr(0, 1) == "#") + { + nearby = true; + tmp = tmp.substr(1).trim(); + } + // Are we running an old query? if (locWS) return; @@ -384,7 +391,7 @@ locWS.onopen = function() { // Web Socket is connected, send data using send() - locWS.send("LOCSEARCH:*"+ tmp +"*"); + locWS.send(nearby ? "LOCNEAR:"+ tmp +":" : "LOCSEARCH:*"+ tmp +"*"); }; // Register events