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 {TileHierarchyAggregator} from "./UI/ShowDataLayer/PerTileCountAggregator"; | ||||
| import {BBox} from "./Logic/GeoOperations"; | ||||
| import StaticFeatureSource from "./Logic/FeatureSource/Sources/StaticFeatureSource"; | ||||
| 
 | ||||
| export class InitUiElements { | ||||
|     static InitAll( | ||||
|  | @ -421,9 +422,6 @@ export class InitUiElements { | |||
|                 const flayer = { | ||||
|                     isDisplayed: isDisplayed, | ||||
|                     layerDef: layer, | ||||
|                     isSufficientlyZoomed: state.locationControl.map(l => { | ||||
|                         return l.zoom >= (layer.minzoomVisible ?? layer.minzoom) | ||||
|                     }), | ||||
|                     appliedFilters: new UIEventSource<TagsFilter>(undefined), | ||||
|                 }; | ||||
|                 flayers.push(flayer); | ||||
|  | @ -491,7 +489,7 @@ export class InitUiElements { | |||
|                         return true | ||||
|                     }, [State.state.locationControl, State.state.currentBounds] | ||||
|                 ) | ||||
|                 | ||||
|                  | ||||
|                 new ShowDataLayer( | ||||
|                     { | ||||
|                         features: source, | ||||
|  | @ -502,7 +500,6 @@ export class InitUiElements { | |||
|                 ); | ||||
|             }, state | ||||
|         ); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private static setupAllLayerElements() { | ||||
|  |  | |||
|  | @ -388,10 +388,10 @@ export class BBox { | |||
|     static global: BBox = new BBox([[-180, -90], [180, 90]]); | ||||
| 
 | ||||
|     constructor(coordinates) { | ||||
|         this.maxLat = Number.MIN_VALUE; | ||||
|         this.maxLon = Number.MIN_VALUE; | ||||
|         this.minLat = Number.MAX_VALUE; | ||||
|         this.minLon = Number.MAX_VALUE; | ||||
|         this.maxLat = -90; | ||||
|         this.maxLon = -180; | ||||
|         this.minLat = 90; | ||||
|         this.minLon = 180; | ||||
| 
 | ||||
| 
 | ||||
|         for (const coordinate of coordinates) { | ||||
|  | @ -491,4 +491,23 @@ export class BBox { | |||
|     toLeaflet() { | ||||
|        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; | ||||
|                 } | ||||
|                 for (const unit of units) { | ||||
|                     if(unit === undefined){ | ||||
|                         continue | ||||
|                     } | ||||
|                     if (unit.appliesToKeys === undefined) { | ||||
|                         console.error("The unit ", unit, "has no appliesToKey defined") | ||||
|                         continue | ||||
|  |  | |||
|  | @ -30,6 +30,8 @@ export default class 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 FilteredLayer from "./Models/FilteredLayer"; | ||||
| 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(layout) | ||||
| State.state = new State(undefined) | ||||
| 
 | ||||
| const leafletMap = new UIEventSource(undefined) | ||||
| MinimapImplementation.initialize() | ||||
| const feature = { | ||||
|     "type": "Feature", | ||||
|     "properties": { | ||||
|         id: "way/1234", | ||||
|         "highway":"residential", | ||||
|         "cyclestreet":"yes" | ||||
|     }, | ||||
|     "geometry": { | ||||
|         "type": "LineString", | ||||
|         "coordinates": [ | ||||
|             [ | ||||
|                 3.2207107543945312, | ||||
|                 51.21978729870313 | ||||
|             ], | ||||
|             [ | ||||
|                 3.2198524475097656, | ||||
|                 51.21899435057332 | ||||
|             ], | ||||
|             [ | ||||
|                 3.2155394554138184, | ||||
|                 51.21617188199714 | ||||
|             ] | ||||
|         ] | ||||
|     } | ||||
| } | ||||
| Minimap.createMiniMap({ | ||||
|     leafletMap: leafletMap, | ||||
| }).SetStyle("height: 600px; width: 600px") | ||||
|     .AttachTo("maindiv") | ||||
| 
 | ||||
| State.state.allElements.addOrGetElement(feature) | ||||
| State.state.filteredLayers = new UIEventSource<FilteredLayer[]>( | ||||
|     layout.layers.map( l => ({ | ||||
|         layerDef :l, | ||||
|         appliedFilters: new UIEventSource<And>(undefined), | ||||
|         isDisplayed: new UIEventSource<boolean>(undefined) | ||||
|     })) | ||||
| ) | ||||
| const bbox = BBox.fromTile(16,32754,21785).asGeoJson({ | ||||
|     count: 42, | ||||
|     tileId: 42 | ||||
| }) | ||||
| 
 | ||||
| const splitroad = new SplitRoadWizard("way/1234") | ||||
|     splitroad.AttachTo("maindiv") | ||||
| 
 | ||||
| splitroad.dialogIsOpened.setData(true) | ||||
| console.log(bbox) | ||||
| new ShowDataLayer({ | ||||
|     layerToShow: ShowTileInfo.styling, | ||||
|     leafletMap: leafletMap, | ||||
|     features: new StaticFeatureSource([ bbox], false) | ||||
| }) | ||||
|  | @ -1,7 +1,8 @@ | |||
| import {Utils} from "../Utils"; | ||||
| import * as Assert from "assert"; | ||||
| import T from "./TestHelper"; | ||||
| import {GeoOperations} from "../Logic/GeoOperations"; | ||||
| import {BBox, GeoOperations} from "../Logic/GeoOperations"; | ||||
| import {equal} from "assert"; | ||||
| 
 | ||||
| Utils.runningFromConsole = true; | ||||
| 
 | ||||
|  | @ -176,7 +177,16 @@ export default class GeoOperationsSpec extends T { | |||
| 
 | ||||
|                     const overlap = GeoOperations.calculateOverlap(point, [GeoOperationsSpec.polygon]); | ||||
|                     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