From 842a8b0473f58e2e6a8eee18765910a8cfee6c88 Mon Sep 17 00:00:00 2001 From: David Levinsky Date: Tue, 16 May 2017 15:03:41 +0200 Subject: [PATCH 1/6] stop autorotate when compass is used --- src/browser/ui/control/compass.js | 10 ++++++++++ src/browser/ui/control/space.js | 5 +++++ src/browser/ui/control/zoom.js | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/src/browser/ui/control/compass.js b/src/browser/ui/control/compass.js index 927bf0a3..8b48ed80 100755 --- a/src/browser/ui/control/compass.js +++ b/src/browser/ui/control/compass.js @@ -62,6 +62,11 @@ UIControlCompass.prototype.onDrag = function(event) { return; } + if (this.browser.autopilot) { //stop autorotation + this.browser.autopilot.setAutorotate(0); + this.browser.autopilot.setAutopan(0,0); + } + var delta = event.getDragDelta(); var sensitivity = 0.4; @@ -80,6 +85,11 @@ UIControlCompass.prototype.onDoubleClick = function(event) { return; } + if (this.browser.autopilot) { //stop autorotation + this.browser.autopilot.setAutorotate(0); + this.browser.autopilot.setAutopan(0,0); + } + var pos = map.getPosition(); var orientation = pos.getOrientation(); orientation[0] = 0; diff --git a/src/browser/ui/control/space.js b/src/browser/ui/control/space.js index bfaaa771..c7a8fa18 100755 --- a/src/browser/ui/control/space.js +++ b/src/browser/ui/control/space.js @@ -57,6 +57,11 @@ UIControlSpace.prototype.onSwitch = function() { return; } + if (this.browser.autopilot) { //stop autorotation + this.browser.autopilot.setAutorotate(0); + this.browser.autopilot.setAutopan(0,0); + } + var pos = map.getPosition(); var orientation = pos.getOrientation(); diff --git a/src/browser/ui/control/zoom.js b/src/browser/ui/control/zoom.js index af436ff1..42940322 100755 --- a/src/browser/ui/control/zoom.js +++ b/src/browser/ui/control/zoom.js @@ -57,6 +57,11 @@ UIControlZoom.prototype.repeat = function(count, factor, delay) { if (map == null) { return; } + + if (this.browser.autopilot) { //stop autorotation + this.browser.autopilot.setAutorotate(0); + this.browser.autopilot.setAutopan(0,0); + } var controller = this.browser.controlMode.getCurrentController(); From fd585e4e68a1f3541c31a7ac4306c4e85c944c4f Mon Sep 17 00:00:00 2001 From: David Levinsky Date: Tue, 16 May 2017 17:50:10 +0200 Subject: [PATCH 2/6] fixed search position height mode --- src/browser/ui/control/search.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/browser/ui/control/search.js b/src/browser/ui/control/search.js index ca587a95..098f7e29 100755 --- a/src/browser/ui/control/search.js +++ b/src/browser/ui/control/search.js @@ -143,6 +143,7 @@ UIControlSearch.prototype.onSelectItem = function(index) { var pos = map.getPosition(); //var coords = map.getPositionCoords(pos); + pos = map.convertPositionHeightMode(pos, "float", true); var item = this.data[index]; if (item) { From 085917fd4b765826581d3eee003a8d5c48ae5c6f Mon Sep 17 00:00:00 2001 From: David Levinsky Date: Thu, 18 May 2017 17:33:33 +0200 Subject: [PATCH 3/6] filtering search results --- src/browser/browser.js | 2 +- src/browser/control-mode/map-observer.js | 2 +- src/browser/control-mode/pano.js | 4 +- src/browser/ui/control/compass.js | 6 +- src/browser/ui/control/credits.js | 2 +- src/browser/ui/control/loading.js | 2 +- src/browser/ui/control/search-filter.js | 240 +++++++++++++++++++++++ src/browser/ui/control/search.js | 39 +++- src/browser/ui/control/space.js | 4 +- src/browser/ui/control/zoom.js | 2 +- src/core/inspector/graphs.js | 10 +- src/core/inspector/input.js | 2 +- 12 files changed, 288 insertions(+), 27 deletions(-) create mode 100644 src/browser/ui/control/search-filter.js diff --git a/src/browser/browser.js b/src/browser/browser.js index b4ea7d9e..b60ffad7 100755 --- a/src/browser/browser.js +++ b/src/browser/browser.js @@ -140,7 +140,7 @@ Browser.prototype.onMapLoaded = function(event) { Browser.prototype.getLinkWithCurrentPos = function() { var map = this.getMap(); - if (map == null) { + if (!map) { return ''; } diff --git a/src/browser/control-mode/map-observer.js b/src/browser/control-mode/map-observer.js index bcbaf123..f5bd6446 100755 --- a/src/browser/control-mode/map-observer.js +++ b/src/browser/control-mode/map-observer.js @@ -234,7 +234,7 @@ ControlModeMapObserver.prototype.getAzimuthAndDistance = function(dx, dy) { ControlModeMapObserver.prototype.tick = function() { var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } diff --git a/src/browser/control-mode/pano.js b/src/browser/control-mode/pano.js index 81798870..383dcca9 100755 --- a/src/browser/control-mode/pano.js +++ b/src/browser/control-mode/pano.js @@ -61,7 +61,7 @@ ControlModePano.prototype.up = function(event) { ControlModePano.prototype.wheel = function(event) { var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } @@ -93,7 +93,7 @@ ControlModePano.prototype.tick = function() { } var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } diff --git a/src/browser/ui/control/compass.js b/src/browser/ui/control/compass.js index 8b48ed80..012bc546 100755 --- a/src/browser/ui/control/compass.js +++ b/src/browser/ui/control/compass.js @@ -39,7 +39,7 @@ var UIControlCompass = function(ui, visible) { UIControlCompass.prototype.update = function() { var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } @@ -58,7 +58,7 @@ UIControlCompass.prototype.update = function() { UIControlCompass.prototype.onDrag = function(event) { var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } @@ -81,7 +81,7 @@ UIControlCompass.prototype.onDrag = function(event) { UIControlCompass.prototype.onDoubleClick = function(event) { var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } diff --git a/src/browser/ui/control/credits.js b/src/browser/ui/control/credits.js index 3b3f79ce..e553588d 100755 --- a/src/browser/ui/control/credits.js +++ b/src/browser/ui/control/credits.js @@ -54,7 +54,7 @@ UIControlCredits.prototype.getCreditsString = function(array, separator, full) { UIControlCredits.prototype.update = function() { var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } diff --git a/src/browser/ui/control/loading.js b/src/browser/ui/control/loading.js index 6f9c1951..d4b877cb 100755 --- a/src/browser/ui/control/loading.js +++ b/src/browser/ui/control/loading.js @@ -103,7 +103,7 @@ UIControlLoading.prototype.update = function() { } var map = this.ui.browser.getMap(); - if (map == null) { + if (!map) { return; } diff --git a/src/browser/ui/control/search-filter.js b/src/browser/ui/control/search-filter.js new file mode 100644 index 00000000..f292035c --- /dev/null +++ b/src/browser/ui/control/search-filter.js @@ -0,0 +1,240 @@ + +import {math as math_} from '../../../core/utils/math'; + +//get rid of compiler mess +var math = math_; + +// Deduplication of hits, that have the same display_name +// and are subsequent in a result set. +function dedupe(hits) { + var hit, result = [], dupes = []; + + // Helper function, that takes set of duplicities + // and returns just one hit. + // + // we return first populated place - if exist + // or if not exist we return just first one + var filterHits = (function(dupes){ + for (var j = 0; j < dupes.length; j++) { + switch (dupes[j].type) { + case 'hamlet': + case 'village': + case 'town': + case 'city': + return dupes[j]; + } + } + + return dupes[0]; + }); + + // We go through all hits and separate results + // and duplicities + for (var i = 0; i < hits.length - 1; i++) { + hit = hits[i]; + + if (hit.display_name === hits[ i + 1 ].display_name) { + dupes.push(hit); + } else { + if (dupes.length > 0) { + dupes.push(hit); + result.push(filterHits(dupes)); + dupes.length = 0; + } else { + result.push(hit); + } + } + } + + // Make sure filterHits is called + if (dupes.length) { + result.push(filterHits(dupes)); + } + + return result; +} + +function getDistance(lon1, lat1, lon2, lat2) { + var r = 6371e3; // metres + var l1 = math.radians(lat1); + var l2 = math.radians(lat2); + var dlat = math.radians(lat2-lat1); + var dlon = math.radians(lon2-lon1); + + var a = Math.sin(dlat/2) * Math.sin(dlat/2) + + Math.cos(l1) * Math.cos(l2) * + Math.sin(dlon/2) * Math.sin(dlon/2); + var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); + + return r * c; +} + +// Stupid unprecise comparsion of two points, if +// they lay close to each other (less than 10km) +function layClose(A, B) { + //return ruler.distance([ A.lon, A.lat ], [ B.lon, B.lat ] ) < 10 + var diff = 0.1; + + return ( +B.lat > +A.lat - diff ) && ( +B.lat < +A.lat + diff ) + && ( +B.lon > +A.lon - diff ) && ( +B.lon < +A.lon + diff ); +} + +// Hits with low importance can be reshaked by its distance +function reshakeHits(hits) { + var maxDiff = 0.06; + var maxRank = 0.4; + var temp, done; + + do { + done = true; + + for (var i = 0; i < hits.length - 1; i++ ) { + var h1 = hits[i]; + var h2 = hits[i + 1]; + + if (( h1.rank < maxRank && h2.rank < maxRank ) // both hits have lowRank + && ( Math.abs( h1.rank - h2.rank ) < maxDiff ) // ...and diff in their rank is small + && ( h1.distance > h2.distance ) // ...and h1 has bigger distance + ) { + + // Switch both hits + h1.note = 'reshaked-down' + h2.note = 'reshaked-up' + + temp = h1; + hits[i] = h2; + hits[i + 1] = temp; + done = false; + } + } + } while (!done); +} + + +// Return Promise, that resolves nice deduplicated results from +// Nominatim (on particular keyword) +function filterSearch(data, lon, lat) { + var rtrn = []; + var hasLocation = lat && lon; + var hits = data; + + /* + // Should we search ZIP code? + var querySubString = ( /^\d{3,5}$/.test( query ) ) ? + `postalcode=${ query }` : `q=${ encodeURIComponent( query ) }` + + var url = `${ searchServer }search.php?format=json&limit=20&addressdetails=1&${ querySubString }&accept-language=${lang}`; + + if( program.dev ) log.info(url); + */ + + var rtrnHit, hit, adr, region, county, display, bounds; + + // Deduplication number 1: Deduplicate consequent + // results with same name + if( hits.length > 1) { + hits = dedupe( hits ); + } + + //Cycle each hit and reduce uts size + for (var i = 0; i < hits.length; i++) { + + // Shortcuts + hit = hits[i]; + + bounds = hit.boundingbox; + + adr = hit.address; + + display = hit.display_name.replace(/,.*/,''); + + region = adr.state && adr.state + || ( adr.state_district && adr.state_district || + ( adr.county && adr.county || '' ) ); + + county = adr.county && adr.county + || ( adr.state_district && adr.state_district || region ); + + // If county is same as title, find + // something better + if (county === display) { + county = adr.state_district && adr.state_district || region; + } + + // Deduplication number 2: Simple process of throwing away hits + // that have lower importance, and lay in vicinity + // of previous hit + if (rtrnHit && layClose(rtrnHit, hit)) continue; + + // Filter out results with low, low low importance + // but only if there is more results + if (hit.importance < 0.01 && i > 5) continue; + + // Rewrite these types of regions + // "Graubünden - Grigioni - Grischun" --> "Graubunder" + if (new RegExp(/ - /).test( region )) { + region = region.replace(/ -.*/,''); + } + + // Should we display bounds instead of dot in a map? + if (hit.type === 'archipelago' || + ( hit.type === 'administrative' && + (display === adr.country || display === region ))) { + + // Repair undefined lon values in bounds + if( bounds[2] === '-180' ) { + bounds[2] = bounds[3] = hit.lon; + } + + } else { + bounds = null; + } + + // Changes display name in adress querries like "Kopeckeho 27" + if (display === adr.house_number && adr.road ) { + display = adr.road; + } + + rtrnHit = { + lat: +hit.lat, + lon: +hit.lon, + title: display, + + rank: hit.importance, + + // for US we use State as country + country: adr.country_code === 'us' ? region : ( adr.country && adr.country.replace(/,.*/,'') ), + + region: county || '', + state: region || '', + cc: adr.country_code, + type: hit.type, + bounds: bounds + } + + // Calculate distance + if (hasLocation) { + rtrnHit.distance = getDistance(lon, lat, rtrnHit.lon, rtrnHit.lat); + } + + + rtrn.push(rtrnHit) + } + + // Reshake hits by distance + if (hasLocation) { + reshakeHits(rtrn); + } + + return rtrn; +} + +// return query on reverse search +/* +function geoSearch = ( { lat,lon,zoom,lang } ) => { + var url = `${ searchServer }reverse.php?format=json&lat=${ lat }&lon=${ lon }&zoom=${ zoom }&addressdetails=1&accept-language=${ lang }` + return rp.get(url,{ timeout: 3000, json: true }) +} +*/ + +export {filterSearch}; diff --git a/src/browser/ui/control/search.js b/src/browser/ui/control/search.js index 098f7e29..eecc6572 100755 --- a/src/browser/ui/control/search.js +++ b/src/browser/ui/control/search.js @@ -1,11 +1,12 @@ import Dom_ from '../../utility/dom'; import {utils as utils_} from '../../../core/utils/utils'; +import {filterSearch as filterSearch_} from './search-filter'; //get rid of compiler mess var dom = Dom_; var utils = utils_; - +var filterSearch = filterSearch_; var UIControlSearch = function(ui, visible) { this.ui = ui; @@ -44,13 +45,20 @@ var UIControlSearch = function(ui, visible) { this.ignoreDrag = false; - this.urlTemplate = 'https://www.windy.com/search/get/v1.0/{value}?lang=en-US&hash=b0f07fGWSGdsx-l'; +// this.urlTemplate = 'https://www.windy.com/search/get/v1.0/{value}?lang=en-US&hash=b0f07fGWSGdsx-l'; +// this.urlTemplate = 'http://nominatim.openstreetmap.org/search?q={value}&addressdetails=1&format=json&limit=20'; + this.urlTemplate = 'http://n1.windyty.com/search.php?q={value}&format=json&lang=en-US&addressdetails=1&limit=20'; this.data = []; this.lastSearch = ''; this.itemIndex = -1; this.searchCounter = 0; this.coordsSrs = '+proj=longlat +datum=WGS84 +nodefs'; + //http://n1.windyty.com/search.php?q=praha&format=json&polygon=1&lang=en-US + //http://n1.windyty.com/reverse.php?format=json&lat=50&lon=14&lang=en-US + //http://nominatim.openstreetmap.org/search?q=praha&addressdetails=1&format=json + + this.initialValueUsed = false; if (this.browser.config.controlSearchValue) { @@ -91,15 +99,13 @@ UIControlSearch.prototype.moveSelector = function(delta) { this.itemIndex = 0; } - this.updateList({'data' : this.data}); + this.updateList(this.data); }; UIControlSearch.prototype.updateList = function(json) { - if (json['data']) { - var item; - var list = ''; - var data = json['data']; + if (Array.isArray(json)) { + var data = json, item, list = ''; data = data.slice(0,10); this.data = data; @@ -137,7 +143,7 @@ UIControlSearch.prototype.updateList = function(json) { UIControlSearch.prototype.onSelectItem = function(index) { var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } @@ -193,12 +199,27 @@ UIControlSearch.prototype.onHoverItem = function(index) { } this.itemIndex = index; - this.updateList({'data' : this.data}); + this.updateList(this.data); }; UIControlSearch.prototype.onListLoaded = function(counter, data) { + var map = this.browser.getMap(); + if (!map) { + return; + } + if (this.searchCounter == counter) { + + var pos = map.getPosition(); + var refFrame = map.getReferenceFrame(); + var navigationSrsId = refFrame['navigationSrs']; + var navigationSrs = map.getSrsInfo(navigationSrsId); + + var proj4 = this.browser.getProj4(); + var coords = proj4(navigationSrs['srsDef'], this.coordsSrs, pos.getCoords()); + + data = filterSearch(data, coords[0], coords[1]); this.updateList(data); } }; diff --git a/src/browser/ui/control/space.js b/src/browser/ui/control/space.js index c7a8fa18..f5138305 100755 --- a/src/browser/ui/control/space.js +++ b/src/browser/ui/control/space.js @@ -53,7 +53,7 @@ UIControlSpace.prototype.onSwitch = function() { this.space3D = !this.space3D; var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } @@ -86,7 +86,7 @@ UIControlSpace.prototype.onSwitch = function() { UIControlSpace.prototype.update = function() { var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } diff --git a/src/browser/ui/control/zoom.js b/src/browser/ui/control/zoom.js index 42940322..7e6a0115 100755 --- a/src/browser/ui/control/zoom.js +++ b/src/browser/ui/control/zoom.js @@ -54,7 +54,7 @@ UIControlZoom.prototype.repeat = function(count, factor, delay) { } var map = this.browser.getMap(); - if (map == null) { + if (!map) { return; } diff --git a/src/core/inspector/graphs.js b/src/core/inspector/graphs.js index ba030013..d5f96e12 100755 --- a/src/core/inspector/graphs.js +++ b/src/core/inspector/graphs.js @@ -120,7 +120,7 @@ InspectorGraphs.prototype.switchPanel = function() { InspectorGraphs.prototype.recordingPressed = function(state) { var map = this.core.getMap(); - if (map == null) { + if (!map) { return; } @@ -140,7 +140,7 @@ InspectorGraphs.prototype.refreshPressed = function() { InspectorGraphs.prototype.resetPressed = function() { var map = this.core.getMap(); - if (map == null) { + if (!map) { return; } @@ -200,7 +200,7 @@ InspectorGraphs.prototype.magnifyPressed = function() { InspectorGraphs.prototype.updateGraphsPanel = function() { var map = this.core.getMap(); - if (map == null) { + if (!map) { return; } @@ -245,7 +245,7 @@ InspectorGraphs.prototype.onMouseMove = function(event) { this.cursorIndex = x; var map = this.core.getMap(); - if (map == null) { + if (!map) { return; } @@ -264,7 +264,7 @@ InspectorGraphs.prototype.onMouseOut = function() { InspectorGraphs.prototype.updateGraphs = function(stats, ignoreRefresh) { var map = this.core.getMap(); - if (map == null || (!this.refresh && !ignoreRefresh) || !this.panelVisible) { + if (!map || (!this.refresh && !ignoreRefresh) || !this.panelVisible) { return; } diff --git a/src/core/inspector/input.js b/src/core/inspector/input.js index a45a5567..87d4642d 100755 --- a/src/core/inspector/input.js +++ b/src/core/inspector/input.js @@ -50,7 +50,7 @@ InspectorInput.prototype.onKeyUp = function(event, press) { var map = this.core.getMap(); var inspector = this.inspector; - if (map == null) { + if (!map) { return; } From b170a10975fc596712f876556ec2a0a2b2599d6b Mon Sep 17 00:00:00 2001 From: David Levinsky Date: Fri, 19 May 2017 14:51:25 +0200 Subject: [PATCH 4/6] working view extent extraction from search result --- src/browser/control-mode/map-observer.js | 4 +- src/browser/ui/control/search-filter.js | 4 +- src/browser/ui/control/search.js | 106 +++++++++++++++++++---- 3 files changed, 95 insertions(+), 19 deletions(-) diff --git a/src/browser/control-mode/map-observer.js b/src/browser/control-mode/map-observer.js index f5bd6446..aa214d54 100755 --- a/src/browser/control-mode/map-observer.js +++ b/src/browser/control-mode/map-observer.js @@ -432,7 +432,7 @@ function constrainMapPosition(browser, pos) { var distance = (pos.getViewExtent()*0.5) / Math.tan(math.radians(pos.getFov()*0.5)); - //reduce tilt whe you are far off the planet + //reduce tilt when you are far off the planet if (pos.getViewMode() == 'obj') { var rf = map.getReferenceFrame(); var srs = map.getSrsInfo(rf['navigationSrs']); @@ -453,7 +453,7 @@ function constrainMapPosition(browser, pos) { o[1] = minTilt; } - pos = pos.setOrientation(o); + pos.setOrientation(o); } } diff --git a/src/browser/ui/control/search-filter.js b/src/browser/ui/control/search-filter.js index f292035c..16c316ce 100644 --- a/src/browser/ui/control/search-filter.js +++ b/src/browser/ui/control/search-filter.js @@ -209,7 +209,9 @@ function filterSearch(data, lon, lat) { state: region || '', cc: adr.country_code, type: hit.type, - bounds: bounds + bounds: bounds, + polygon : hit.polygonpoints || [], + bbox : hit.boundingbox } // Calculate distance diff --git a/src/browser/ui/control/search.js b/src/browser/ui/control/search.js index eecc6572..eec7a0f2 100755 --- a/src/browser/ui/control/search.js +++ b/src/browser/ui/control/search.js @@ -2,9 +2,13 @@ import Dom_ from '../../utility/dom'; import {utils as utils_} from '../../../core/utils/utils'; import {filterSearch as filterSearch_} from './search-filter'; +import {vec3 as vec3_} from '../../../core/utils/matrix'; +import {math as math_} from '../../../core/utils/math'; //get rid of compiler mess var dom = Dom_; +var vec3 = vec3_; +var math = math_; var utils = utils_; var filterSearch = filterSearch_; @@ -48,6 +52,7 @@ var UIControlSearch = function(ui, visible) { // this.urlTemplate = 'https://www.windy.com/search/get/v1.0/{value}?lang=en-US&hash=b0f07fGWSGdsx-l'; // this.urlTemplate = 'http://nominatim.openstreetmap.org/search?q={value}&addressdetails=1&format=json&limit=20'; this.urlTemplate = 'http://n1.windyty.com/search.php?q={value}&format=json&lang=en-US&addressdetails=1&limit=20'; + this.urlTemplate2 = 'http://n1.windyty.com/search.php?q={value}&format=json&lang=en-US&addressdetails=1&limit=20&polygon=1'; this.data = []; this.lastSearch = ''; this.itemIndex = -1; @@ -140,15 +145,33 @@ UIControlSearch.prototype.updateList = function(json) { } }; - UIControlSearch.prototype.onSelectItem = function(index) { + var url = this.processTemplate(this.urlTemplate2, { 'value' : this.lastSearch }); + + //load data with polygons + utils.loadJSON(url, this.onDisplayItem.bind(this, index), this.onListLoadError.bind(this)); +}; + +UIControlSearch.prototype.onDisplayItem = function(index, data) { var map = this.browser.getMap(); if (!map) { return; } - + + //sort list with polygons var pos = map.getPosition(); - //var coords = map.getPositionCoords(pos); + var refFrame = map.getReferenceFrame(); + var navigationSrsId = refFrame['navigationSrs']; + var navigationSrs = map.getSrsInfo(navigationSrsId); + var physicalSrsId = refFrame['physicalSrs']; + var physicalSrs = map.getSrsInfo(physicalSrsId); + + var proj4 = this.browser.getProj4(); + var coords = proj4(navigationSrs['srsDef'], this.coordsSrs, pos.getCoords()); + + this.data = filterSearch(data, coords[0], coords[1]); + + pos = map.convertPositionHeightMode(pos, "float", true); var item = this.data[index]; @@ -156,29 +179,80 @@ UIControlSearch.prototype.onSelectItem = function(index) { var coords = [item['lon'], item['lat']]; //conver coords from location srs to map navigation srs - var refFrame = map.getReferenceFrame(); - var navigationSrsId = refFrame['navigationSrs']; - var navigationSrs = map.getSrsInfo(navigationSrsId); - - var proj4 = this.browser.getProj4(); coords = proj4(this.coordsSrs, navigationSrs['srsDef'], coords); coords[2] = 0; pos.setCoords(coords); - - //try to guess view extent from location type + var viewExtent = 10000; - switch(item['type']) { - case 'peak': viewExtent = 20000; break; - case 'city': viewExtent = 30000; break; - case 'street': viewExtent = 4000; break; - case 'residential': viewExtent = 3000; break; + if (item.polygon) { + var points = item.polygon; + //var cameraInfo = map.getCameraInfo(); + //var cameraVector = cameraInfo.vector; + //var cameraPosition = cameraInfo.position; + + //convert point to physical coords + var cameraPosition = proj4(this.coordsSrs, physicalSrs['srsDef'], coords); + var cameraVector = [-cameraPosition[0], -cameraPosition[1], -cameraPosition[2]]; + vec3.normalize(cameraVector); + + for (var i = 0, li = points.length; i < li; i++) { + //convert point to physical coords + coords = proj4(this.coordsSrs, physicalSrs['srsDef'], [points[i][0], points[i][1], 0]); + + var ab = cameraVector; + var av = [coords[0] - cameraPosition[0], coords[1] - cameraPosition[1], coords[2] - cameraPosition[2]]; + + //final R3 bv = v.sub( b ) ; + var b = [cameraPosition[0] + cameraVector[0], cameraPosition[1] + cameraVector[1], cameraPosition[2] + cameraVector[2]]; + var bv = [coords[0] - b[0], coords[1] - b[1], coords[2] - b[2]]; + + var af = [0,0,0]; + vec3.cross(ab, av, af); + + var d = (vec3.length(bv) / vec3.length(ab)) * 2; + + if (d > viewExtent) { + viewExtent = d; + } + } + } else { + //try to guess view extent from location type + switch(item['type']) { + case 'peak': viewExtent = 20000; break; + case 'city': viewExtent = 30000; break; + case 'street': viewExtent = 4000; break; + case 'residential': viewExtent = 3000; break; + } } pos.setViewExtent(viewExtent); - pos.setOrientation([0,-60,0]); + var orientation = [0,-60,0]; + + //reduce tilt when you are far off the planet + if (pos.getViewMode() == 'obj') { + if (navigationSrs['a']) { + var distance = (pos.getViewExtent()*0.5) / Math.tan(math.radians(pos.getFov()*0.5)); + var factor = Math.min(distance / (navigationSrs['a']*0.5), 1.0); + var maxTilt = 20 + ((-90) - 20) * factor; + var minTilt = -90; + + orientation = pos.getOrientation(); + + if (orientation[1] > maxTilt) { + orientation[1] = maxTilt; + } + + if (orientation[1] < minTilt) { + orientation[1] = minTilt; + } + + } + } + + pos.setOrientation(orientation); map.setPosition(pos); this.itemIndex = index; From c10e66bebf50058167bed855b92a856fa1a5fb6e Mon Sep 17 00:00:00 2001 From: David Levinsky Date: Fri, 19 May 2017 16:34:08 +0200 Subject: [PATCH 5/6] search uses lat lon extents for view extent determination --- src/browser/ui/control/search.js | 54 ++++++++++++++------------------ 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/browser/ui/control/search.js b/src/browser/ui/control/search.js index eec7a0f2..82b7dbac 100755 --- a/src/browser/ui/control/search.js +++ b/src/browser/ui/control/search.js @@ -49,21 +49,14 @@ var UIControlSearch = function(ui, visible) { this.ignoreDrag = false; -// this.urlTemplate = 'https://www.windy.com/search/get/v1.0/{value}?lang=en-US&hash=b0f07fGWSGdsx-l'; -// this.urlTemplate = 'http://nominatim.openstreetmap.org/search?q={value}&addressdetails=1&format=json&limit=20'; this.urlTemplate = 'http://n1.windyty.com/search.php?q={value}&format=json&lang=en-US&addressdetails=1&limit=20'; - this.urlTemplate2 = 'http://n1.windyty.com/search.php?q={value}&format=json&lang=en-US&addressdetails=1&limit=20&polygon=1'; + this.urlTemplate2 = this.urlTemplate; this.data = []; this.lastSearch = ''; this.itemIndex = -1; this.searchCounter = 0; this.coordsSrs = '+proj=longlat +datum=WGS84 +nodefs'; - //http://n1.windyty.com/search.php?q=praha&format=json&polygon=1&lang=en-US - //http://n1.windyty.com/reverse.php?format=json&lat=50&lon=14&lang=en-US - //http://nominatim.openstreetmap.org/search?q=praha&addressdetails=1&format=json - - this.initialValueUsed = false; if (this.browser.config.controlSearchValue) { @@ -145,14 +138,8 @@ UIControlSearch.prototype.updateList = function(json) { } }; -UIControlSearch.prototype.onSelectItem = function(index) { - var url = this.processTemplate(this.urlTemplate2, { 'value' : this.lastSearch }); - //load data with polygons - utils.loadJSON(url, this.onDisplayItem.bind(this, index), this.onListLoadError.bind(this)); -}; - -UIControlSearch.prototype.onDisplayItem = function(index, data) { +UIControlSearch.prototype.onSelectItem = function(index) { var map = this.browser.getMap(); if (!map) { return; @@ -169,9 +156,6 @@ UIControlSearch.prototype.onDisplayItem = function(index, data) { var proj4 = this.browser.getProj4(); var coords = proj4(navigationSrs['srsDef'], this.coordsSrs, pos.getCoords()); - this.data = filterSearch(data, coords[0], coords[1]); - - pos = map.convertPositionHeightMode(pos, "float", true); var item = this.data[index]; @@ -184,13 +168,23 @@ UIControlSearch.prototype.onDisplayItem = function(index, data) { pos.setCoords(coords); - var viewExtent = 10000; + var viewExtent = 6667; + + if (item.bbox) { + var lat1 = item.bbox[0]; + var lat2 = item.bbox[1]; + var lon1 = item.bbox[2]; + var lon2 = item.bbox[3]; + + item.polygon = [ + [lon1, lat1], [(lon2+lon1)*0.5, lat1], [lon2, lat1], + [lon1, (lat2+lat1)*0.5], [lon2, (lat2+lat1)*0.5], + [lon1, lat2], [(lon2+lon1)*0.5, lat2], [lon2, lat2] + ]; + } - if (item.polygon) { + if (item.polygon && item.type != 'continent') { var points = item.polygon; - //var cameraInfo = map.getCameraInfo(); - //var cameraVector = cameraInfo.vector; - //var cameraPosition = cameraInfo.position; //convert point to physical coords var cameraPosition = proj4(this.coordsSrs, physicalSrs['srsDef'], coords); @@ -219,11 +213,12 @@ UIControlSearch.prototype.onDisplayItem = function(index, data) { } } else { //try to guess view extent from location type - switch(item['type']) { - case 'peak': viewExtent = 20000; break; - case 'city': viewExtent = 30000; break; - case 'street': viewExtent = 4000; break; - case 'residential': viewExtent = 3000; break; + switch(item.type) { + case 'peak': viewExtent = 20000; break; + case 'city': viewExtent = 30000; break; + case 'street': viewExtent = 4000; break; + case 'residential': viewExtent = 3000; break; + case 'continent': viewExtent = 8550000; break; } } @@ -239,8 +234,6 @@ UIControlSearch.prototype.onDisplayItem = function(index, data) { var maxTilt = 20 + ((-90) - 20) * factor; var minTilt = -90; - orientation = pos.getOrientation(); - if (orientation[1] > maxTilt) { orientation[1] = maxTilt; } @@ -248,7 +241,6 @@ UIControlSearch.prototype.onDisplayItem = function(index, data) { if (orientation[1] < minTilt) { orientation[1] = minTilt; } - } } From d9644376ba64e7dbc24d506deda2de5c74e9e16e Mon Sep 17 00:00:00 2001 From: David Levinsky Date: Fri, 19 May 2017 16:36:54 +0200 Subject: [PATCH 6/6] version update --- package.json | 2 +- src/core/core.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 29b3330f..5f9168a2 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vts-browser-js", - "version": "2.3.0", + "version": "2.4.0", "description": "JavaScript WebGL 3D maps rendering engine", "main": "src/browser/index.js", "scripts": { diff --git a/src/core/core.js b/src/core/core.js index 9a844743..6faa7df9 100755 --- a/src/core/core.js +++ b/src/core/core.js @@ -468,7 +468,7 @@ string getCoreVersion() */ function getCoreVersion(full) { - return (full ? 'Core: ' : '') + '2.3.0'; + return (full ? 'Core: ' : '') + '2.4.0'; }