Skip to content

Commit

Permalink
Merge pull request #177 from davidmtech/master
Browse files Browse the repository at this point in the history
Fixed search
  • Loading branch information
davidmtech authored Mar 26, 2020
2 parents 8fdd34b + fea303b commit 56e8f89
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/browser/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Browser.prototype.initConfig = function() {
controlSearch : true,
controlSearchSrs : null,
controlSearchUrl : null,
controlSearchFilter : true,
controlSearchFilter : false,
controlMeasure : false,
controlMeasureLite : false,
controlLink : false,
Expand Down
18 changes: 9 additions & 9 deletions src/browser/ui/control/search-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ function nofilterSearch(data, lon, lat) {
hit = hits[i];

rtrnHit = {
lat: +hit.lat,
lon: +hit.lon,
title: hit.display_name,
rank: hit.importance || 1,
country: '',
region: '',
state: '',
lat: +hit['lat'],
lon: +hit['lon'],
title: hit['title'],
rank: 1, //hit.importance || 1,
country: hit['country'],
region: hit['region'],
state: hit['state'],
cc: '',
type: '',
bounds: hit.boundingbox,
bounds: null, //hit.boundingbox,
polygon : [],
bbox : hit.boundingbox
bbox : null //hit.boundingbox
}

// Calculate distance
Expand Down
33 changes: 29 additions & 4 deletions src/browser/ui/control/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ var UIControlSearch = function(ui, visible, visibleLock) {

this.ignoreDrag = false;

this.urlTemplate = '//cdn.melown.com/vtsapi/geocode?q={value}&format=json&lang=en-US&addressdetails=1&limit=20';
//old template '//cdn.melown.com/vtsapi/geocode?q={value}&format=json&lang=en-US&addressdetails=1&limit=20';
//this.urlTemplate = '//cdn.melown.com/vtsapi/geocode/v3.0/{lat}/{long}/{value}';
//this.urlTemplate = '//node.windy.com/search/v3.0/{lat}/{long}/{value}';
this.urlTemplate = '//cdn.melown.com/vtsapi/geocode/v3.0/{lat}/{long}/{value}';
this.urlTemplate2 = this.urlTemplate;
this.data = [];
this.lastSearch = '';
Expand Down Expand Up @@ -336,10 +339,15 @@ UIControlSearch.prototype.onListLoaded = function(counter, data) {

var coords = proj4(navigationSrs['srsDef'], srs, pos.getCoords());

//check data format
if (!(data['data'] && Array.isArray(data['data']) && data['header'] && data['header']['type'] == 'search')) {
return;
}

if (this.browser.config.controlSearchFilter) {
data = filterSearch(data, coords[0], coords[1]);
data = filterSearch(data['data'], coords[0], coords[1]);
} else {
data = nofilterSearch(data, coords[0], coords[1]);
data = nofilterSearch(data['data'], coords[0], coords[1]);
}

if (this.coords) {
Expand Down Expand Up @@ -568,9 +576,26 @@ UIControlSearch.prototype.onChange = function() {
this.hideList();
}

var map = this.browser.getMap();
if (!map) {
return;
}

//sort list with polygons
var pos = map.getPosition();
var refFrame = map.getReferenceFrame();
var navigationSrsId = refFrame['navigationSrs'];
var navigationSrs = map.getSrsInfo(navigationSrsId);
var proj4 = this.browser.getProj4();
var srs = this.browser.config.controlSearchSrs || this.coordsSrs;
srs = this.solveSRS(srs);

var coords = proj4(navigationSrs['srsDef'], srs, pos.getCoords());


this.coords = this.parseLatLon(value);

var url = this.processTemplate(this.browser.config.controlSearchUrl || this.urlTemplate, { 'value' : value });
var url = this.processTemplate(this.browser.config.controlSearchUrl || this.urlTemplate, { 'value':value, 'lat':coords[1], 'long':coords[0] });
//console.log(url);
this.searchCounter++;
this.itemIndex = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ string getCoreVersion()
*/

function getCoreVersion(full) {
return (full ? 'Core: ' : '') + '2.22.6';
return (full ? 'Core: ' : '') + '2.22.7';
}


Expand Down
133 changes: 68 additions & 65 deletions src/core/map/geodata-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,95 +1446,98 @@ MapGeodataBuilder.prototype.processHeights = function(heightsSource, precision,
//var item = this.heightsProcessBuffer, lastItem;
var p, res, nodeOnly, heightsLod, nodeOnly, coords, noSource;

switch (heightsSource) {
case "node-by-precision":
nodeOnly = true;
case "heightmap-by-precision":
if (item) {

coords = item.coords;
switch (heightsSource) {
case "node-by-precision":
nodeOnly = true;
case "heightmap-by-precision":

if (coords[3].srs) {
p = this.navSrs.convertCoordsFrom(coords, coords[3].srs);
} else {
p = coords;
}
coords = item.coords;

heightsLod = this.map.measure.getOptimalHeightLodBySampleSize(p, precision);
break;
if (coords[3].srs) {
p = this.navSrs.convertCoordsFrom(coords, coords[3].srs);
} else {
p = coords;
}

case "node-by-lod":
nodeOnly = true;
precision -= 8;
case "heightmap-by-lod":
heightsLod = precision;
break;
case "none":
noSource = true;
break;
}
heightsLod = this.map.measure.getOptimalHeightLodBySampleSize(p, precision);
break;

case "node-by-lod":
nodeOnly = true;
precision -= 8;
case "heightmap-by-lod":
heightsLod = precision;
break;
case "none":
noSource = true;
break;
}

do {
coords = item.coords;
do {
coords = item.coords;

if (!noSource && coords[4] == null) {
if (coords[3].srs) {
p = this.navSrs.convertCoordsFrom(coords, coords[3].srs);
} else {
p = coords;
}
if (!noSource && coords[4] == null) {
if (coords[3].srs) {
p = this.navSrs.convertCoordsFrom(coords, coords[3].srs);
} else {
p = coords;
}

res = this.map.measure.getSpatialDivisionNode(p);
res = this.map.measure.getSpatialDivisionNode(p);

coords[4] = res[0];
coords[5] = res[1];
coords[4] = res[0];
coords[5] = res[1];

//coords[4] = p;
}
//coords[4] = p;
}


if (noSource) {
res = [0,true,true];
} else {
res = this.map.measure.getSurfaceHeight(coords, heightsLod, null, coords[4], coords[5], null, nodeOnly);
}
if (noSource) {
res = [0,true,true];
} else {
res = this.map.measure.getSurfaceHeight(coords, heightsLod, null, coords[4], coords[5], null, nodeOnly);
}

//res = this.map.measure.getSurfaceHeight(coords[4], heightsLod, null, null, null, null, nodeOnly);
//res = this.map.measure.getSurfaceHeight(coords[4], heightsLod, null, null, null, null, nodeOnly);

//console.log(JSON.stringify(res));
//console.log(JSON.stringify(res));

//if (res[1] || res[2]) { //precisin reached or not aviable
//res = this.map.measure.getSurfaceHeight(coords[4], heightsLod, null, null, null, null, nodeOnly);
//res = this.map.measure.getSurfaceHeight(coords, heightsLod, null, coords[4], coords[5], null, nodeOnly);
//}
//if (res[1] || res[2]) { //precisin reached or not aviable
//res = this.map.measure.getSurfaceHeight(coords[4], heightsLod, null, null, null, null, nodeOnly);
//res = this.map.measure.getSurfaceHeight(coords, heightsLod, null, coords[4], coords[5], null, nodeOnly);
//}

if (res[1] || res[2]) { //precision reached or not aviable
if (res[1] || res[2]) { //precision reached or not aviable

//console.log(JSON.stringify(res));
//console.log(JSON.stringify(res));

coords[2] += res[0]; //convet float height to fixed
this.removeFromHeightsBuffer(item, lastItem);
coords[3].heightsToProcess--;
this.heightsToProcess--;
coords[2] += res[0]; //convet float height to fixed
this.removeFromHeightsBuffer(item, lastItem);
coords[3].heightsToProcess--;
this.heightsToProcess--;

if (coords[3].heightsToProcess <= 0) { //this prevents multiple conversions
coords[3].floatHeights = false;
}
if (coords[3].heightsToProcess <= 0) { //this prevents multiple conversions
coords[3].floatHeights = false;
}

p = [coords[0], coords[1], coords[2]];
p = [coords[0], coords[1], coords[2]];

//console.log(JSON.stringify(p) + " srs " + coords[3].srs);
//console.log(JSON.stringify(p) + " srs " + coords[3].srs);

p = this.physSrs.convertCoordsFrom(p, coords[3].srs);
p = this.physSrs.convertCoordsFrom(p, coords[3].srs);

coords[0] = p[0];
coords[1] = p[1];
coords[2] = p[2];
}
coords[0] = p[0];
coords[1] = p[1];
coords[2] = p[2];
}

lastItem = item;
item = item.next;
lastItem = item;
item = item.next;

} while(item);
} while(item);
}

if (this.heightsToProcess <= 0) {
if (this.updateCallback) {
Expand Down

0 comments on commit 56e8f89

Please sign in to comment.