forked from MapComplete/MapComplete
		
	Fix bug in bounds calculation for negative lats/lons
This commit is contained in:
		
							parent
							
								
									215aebce19
								
							
						
					
					
						commit
						38037014b0
					
				
					 6 changed files with 65 additions and 51 deletions
				
			
		|  | @ -41,6 +41,7 @@ import ShowTileInfo from "./UI/ShowDataLayer/ShowTileInfo"; | ||||||
| import {Tiles} from "./Models/TileRange"; | import {Tiles} from "./Models/TileRange"; | ||||||
| import {TileHierarchyAggregator} from "./UI/ShowDataLayer/PerTileCountAggregator"; | import {TileHierarchyAggregator} from "./UI/ShowDataLayer/PerTileCountAggregator"; | ||||||
| import {BBox} from "./Logic/GeoOperations"; | import {BBox} from "./Logic/GeoOperations"; | ||||||
|  | import StaticFeatureSource from "./Logic/FeatureSource/Sources/StaticFeatureSource"; | ||||||
| 
 | 
 | ||||||
| export class InitUiElements { | export class InitUiElements { | ||||||
|     static InitAll( |     static InitAll( | ||||||
|  | @ -421,9 +422,6 @@ export class InitUiElements { | ||||||
|                 const flayer = { |                 const flayer = { | ||||||
|                     isDisplayed: isDisplayed, |                     isDisplayed: isDisplayed, | ||||||
|                     layerDef: layer, |                     layerDef: layer, | ||||||
|                     isSufficientlyZoomed: state.locationControl.map(l => { |  | ||||||
|                         return l.zoom >= (layer.minzoomVisible ?? layer.minzoom) |  | ||||||
|                     }), |  | ||||||
|                     appliedFilters: new UIEventSource<TagsFilter>(undefined), |                     appliedFilters: new UIEventSource<TagsFilter>(undefined), | ||||||
|                 }; |                 }; | ||||||
|                 flayers.push(flayer); |                 flayers.push(flayer); | ||||||
|  | @ -502,7 +500,6 @@ export class InitUiElements { | ||||||
|                 ); |                 ); | ||||||
|             }, state |             }, state | ||||||
|         ); |         ); | ||||||
| 
 |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private static setupAllLayerElements() { |     private static setupAllLayerElements() { | ||||||
|  |  | ||||||
|  | @ -388,10 +388,10 @@ export class BBox { | ||||||
|     static global: BBox = new BBox([[-180, -90], [180, 90]]); |     static global: BBox = new BBox([[-180, -90], [180, 90]]); | ||||||
| 
 | 
 | ||||||
|     constructor(coordinates) { |     constructor(coordinates) { | ||||||
|         this.maxLat = Number.MIN_VALUE; |         this.maxLat = -90; | ||||||
|         this.maxLon = Number.MIN_VALUE; |         this.maxLon = -180; | ||||||
|         this.minLat = Number.MAX_VALUE; |         this.minLat = 90; | ||||||
|         this.minLon = Number.MAX_VALUE; |         this.minLon = 180; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         for (const coordinate of coordinates) { |         for (const coordinate of coordinates) { | ||||||
|  | @ -491,4 +491,23 @@ export class BBox { | ||||||
|     toLeaflet() { |     toLeaflet() { | ||||||
|        return [[this.minLat, this.minLon], [this.maxLat, this.maxLon]] |        return [[this.minLat, this.minLon], [this.maxLat, this.maxLon]] | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     asGeoJson(properties: any) : any{ | ||||||
|  |         return { | ||||||
|  |             type:"Feature", | ||||||
|  |             properties: properties, | ||||||
|  |             geometry:{ | ||||||
|  |                 type:"Polygon", | ||||||
|  |                 coordinates:[[ | ||||||
|  |                      | ||||||
|  |                     [this.minLon, this.minLat], | ||||||
|  |                         [this.maxLon, this.minLat], | ||||||
|  |                         [this.maxLon, this.maxLat], | ||||||
|  |                         [this.minLon, this.maxLat], | ||||||
|  |                         [this.minLon, this.minLat], | ||||||
|  | 
 | ||||||
|  |                 ]] | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | @ -97,6 +97,9 @@ export default class SimpleMetaTagger { | ||||||
|                     continue; |                     continue; | ||||||
|                 } |                 } | ||||||
|                 for (const unit of units) { |                 for (const unit of units) { | ||||||
|  |                     if(unit === undefined){ | ||||||
|  |                         continue | ||||||
|  |                     } | ||||||
|                     if (unit.appliesToKeys === undefined) { |                     if (unit.appliesToKeys === undefined) { | ||||||
|                         console.error("The unit ", unit, "has no appliesToKey defined") |                         console.error("The unit ", unit, "has no appliesToKey defined") | ||||||
|                         continue |                         continue | ||||||
|  |  | ||||||
|  | @ -30,6 +30,8 @@ export default class Minimap { | ||||||
|     /** |     /** | ||||||
|      * Construct a minimap |      * Construct a minimap | ||||||
|      */ |      */ | ||||||
|     public static createMiniMap: (options: MinimapOptions) => (BaseUIElement & MinimapObj) |     public static createMiniMap: (options: MinimapOptions) => (BaseUIElement & MinimapObj) = (_) => { | ||||||
|  |         throw "CreateMinimap hasn't been initialized yet. Please call MinimapImplementation.initialize()" | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
							
								
								
									
										61
									
								
								test.ts
									
										
									
									
									
								
							
							
						
						
									
										61
									
								
								test.ts
									
										
									
									
									
								
							|  | @ -5,46 +5,29 @@ import MinimapImplementation from "./UI/Base/MinimapImplementation"; | ||||||
| import {UIEventSource} from "./Logic/UIEventSource"; | import {UIEventSource} from "./Logic/UIEventSource"; | ||||||
| import FilteredLayer from "./Models/FilteredLayer"; | import FilteredLayer from "./Models/FilteredLayer"; | ||||||
| import {And} from "./Logic/Tags/And"; | import {And} from "./Logic/Tags/And"; | ||||||
|  | import ShowDataLayer from "./UI/ShowDataLayer/ShowDataLayer"; | ||||||
|  | import ShowTileInfo from "./UI/ShowDataLayer/ShowTileInfo"; | ||||||
|  | import StaticFeatureSource from "./Logic/FeatureSource/Sources/StaticFeatureSource"; | ||||||
|  | import {BBox} from "./Logic/GeoOperations"; | ||||||
|  | import Minimap from "./UI/Base/Minimap"; | ||||||
| 
 | 
 | ||||||
| const layout = AllKnownLayouts.allKnownLayouts.get("cyclestreets") | State.state = new State(undefined) | ||||||
| State.state = new State(layout) | 
 | ||||||
|  | const leafletMap = new UIEventSource(undefined) | ||||||
| MinimapImplementation.initialize() | MinimapImplementation.initialize() | ||||||
| const feature = { | Minimap.createMiniMap({ | ||||||
|     "type": "Feature", |     leafletMap: leafletMap, | ||||||
|     "properties": { | }).SetStyle("height: 600px; width: 600px") | ||||||
|         id: "way/1234", |     .AttachTo("maindiv") | ||||||
|         "highway":"residential", |  | ||||||
|         "cyclestreet":"yes" |  | ||||||
|     }, |  | ||||||
|     "geometry": { |  | ||||||
|         "type": "LineString", |  | ||||||
|         "coordinates": [ |  | ||||||
|             [ |  | ||||||
|                 3.2207107543945312, |  | ||||||
|                 51.21978729870313 |  | ||||||
|             ], |  | ||||||
|             [ |  | ||||||
|                 3.2198524475097656, |  | ||||||
|                 51.21899435057332 |  | ||||||
|             ], |  | ||||||
|             [ |  | ||||||
|                 3.2155394554138184, |  | ||||||
|                 51.21617188199714 |  | ||||||
|             ] |  | ||||||
|         ] |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| State.state.allElements.addOrGetElement(feature) | const bbox = BBox.fromTile(16,32754,21785).asGeoJson({ | ||||||
| State.state.filteredLayers = new UIEventSource<FilteredLayer[]>( |     count: 42, | ||||||
|     layout.layers.map( l => ({ |     tileId: 42 | ||||||
|         layerDef :l, | }) | ||||||
|         appliedFilters: new UIEventSource<And>(undefined), |  | ||||||
|         isDisplayed: new UIEventSource<boolean>(undefined) |  | ||||||
|     })) |  | ||||||
| ) |  | ||||||
| 
 | 
 | ||||||
| const splitroad = new SplitRoadWizard("way/1234") | console.log(bbox) | ||||||
|     splitroad.AttachTo("maindiv") | new ShowDataLayer({ | ||||||
| 
 |     layerToShow: ShowTileInfo.styling, | ||||||
| splitroad.dialogIsOpened.setData(true) |     leafletMap: leafletMap, | ||||||
|  |     features: new StaticFeatureSource([ bbox], false) | ||||||
|  | }) | ||||||
|  | @ -1,7 +1,8 @@ | ||||||
| import {Utils} from "../Utils"; | import {Utils} from "../Utils"; | ||||||
| import * as Assert from "assert"; | import * as Assert from "assert"; | ||||||
| import T from "./TestHelper"; | import T from "./TestHelper"; | ||||||
| import {GeoOperations} from "../Logic/GeoOperations"; | import {BBox, GeoOperations} from "../Logic/GeoOperations"; | ||||||
|  | import {equal} from "assert"; | ||||||
| 
 | 
 | ||||||
| Utils.runningFromConsole = true; | Utils.runningFromConsole = true; | ||||||
| 
 | 
 | ||||||
|  | @ -176,7 +177,16 @@ export default class GeoOperationsSpec extends T { | ||||||
| 
 | 
 | ||||||
|                     const overlap = GeoOperations.calculateOverlap(point, [GeoOperationsSpec.polygon]); |                     const overlap = GeoOperations.calculateOverlap(point, [GeoOperationsSpec.polygon]); | ||||||
|                     Assert.equal(1, overlap.length) |                     Assert.equal(1, overlap.length) | ||||||
|                 }] |                 }], | ||||||
|  |                 ["bbox bounds test", | ||||||
|  |                     () => { | ||||||
|  |                         const bbox = BBox.fromTile(16, 32754, 21785) | ||||||
|  |                         equal(-0.0714111328125, bbox.minLon) | ||||||
|  |                         equal(-0.076904296875, bbox.maxLon) | ||||||
|  |                         equal(51.53266860674158, bbox.minLat) | ||||||
|  |                         equal(51.5292513551899, bbox.maxLat) | ||||||
|  |                     } | ||||||
|  |                 ] | ||||||
|             ] |             ] | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue