Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

Commit

Permalink
Issue #175 ongoing src/core folder ongoing
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwouaiebe committed Jul 22, 2021
1 parent e93418a commit 294d2d3
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 160 deletions.
30 changes: 15 additions & 15 deletions src/core/MapIconDataBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,44 +292,44 @@ class MapIconDataBuilder {
#setDirectionArrowAndTooltip ( ) {
if ( null !== this.#direction ) {
if ( this.#direction < theConfig.note.svgIcon.angleDirection.right ) {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Turn right' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Turn right' );
this.#directionArrow = '🢂';
}
else if ( this.#direction < theConfig.note.svgIcon.angleDirection.slightRight ) {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Turn slight right' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Turn slight right' );
this.#directionArrow = '🢅';
}
else if ( this.#direction < theConfig.note.svgIcon.angleDirection.continue ) {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Continue' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Continue' );
this.#directionArrow = '🢁';
}
else if ( this.#direction < theConfig.note.svgIcon.angleDirection.slightLeft ) {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Turn slight left' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Turn slight left' );
this.#directionArrow = '🢄';
}
else if ( this.#direction < theConfig.note.svgIcon.angleDirection.left ) {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Turn left' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Turn left' );
this.#directionArrow = '🢀';
}
else if ( this.#direction < theConfig.note.svgIcon.angleDirection.sharpLeft ) {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Turn sharp left' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Turn sharp left' );
this.#directionArrow = '🢇';
}
else if ( this.#direction < theConfig.note.svgIcon.angleDirection.sharpRight ) {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Turn sharp right' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Turn sharp right' );
this.#directionArrow = '🢆';
}
else {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Turn right' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Turn right' );
this.#directionArrow = '🢂';
}
}

if ( ICON_POSITION.atStart === this.#positionOnRoute ) {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Start' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Start' );
}
else if ( ICON_POSITION.atEnd === this.#positionOnRoute ) {
this.#mapIconData.tooltip = theTranslator.getText ( 'SvgIconFromOsmFactory - Stop' );
this.#mapIconData.tooltip = theTranslator.getText ( 'MapIconDataBuilder - Stop' );
}
}

Expand Down Expand Up @@ -421,7 +421,7 @@ class MapIconDataBuilder {
) {
this.#mapIconData.rcnRef = iconNode.tags.rcn_ref;
this.#mapIconData.tooltip +=
theTranslator.getText ( 'SvgIconFromOsmFactory - rcnRef', { rcnRef : this.#mapIconData.rcnRef } );
theTranslator.getText ( 'MapIconDataBuilder - rcnRef', { rcnRef : this.#mapIconData.rcnRef } );
}

let incomingStreet = '';
Expand Down Expand Up @@ -511,18 +511,18 @@ class MapIconDataBuilder {

// adding roundabout info
if ( isRoundaboutEntry && ! isRoundaboutExit ) {
this.#mapIconData.tooltip += theTranslator.getText ( 'SvgIconFromOsmFactory - entry roundabout' );
this.#mapIconData.tooltip += theTranslator.getText ( 'MapIconDataBuilder - entry roundabout' );
}
else if ( ! isRoundaboutEntry && isRoundaboutExit ) {
this.#mapIconData.tooltip += theTranslator.getText ( 'SvgIconFromOsmFactory - exit roundabout' );
this.#mapIconData.tooltip += theTranslator.getText ( 'MapIconDataBuilder - exit roundabout' );
}
else if ( isRoundaboutEntry && isRoundaboutExit ) {
this.#mapIconData.tooltip +=
theTranslator.getText ( 'SvgIconFromOsmFactory - continue roundabout' ); // strange but correct
theTranslator.getText ( 'MapIconDataBuilder - continue roundabout' ); // strange but correct
}
if ( isMiniRoundabout ) {
this.#mapIconData.tooltip +=
theTranslator.getText ( 'SvgIconFromOsmFactory - at the small roundabout on the ground' );
theTranslator.getText ( 'MapIconDataBuilder - at the small roundabout on the ground' );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Tests ...
/**
@------------------------------------------------------------------------------------------------------------------------------
@file SvgIconFromOsmFactory.js
@file MapIconFromOsmFactory.js
@copyright Copyright - 2017 2021 - wwwouaiebe - Contact: https://www.ouaie.be/
@license GNU General Public License
@private
Expand Down Expand Up @@ -63,7 +63,7 @@ This will be used for the note address
/**
@------------------------------------------------------------------------------------------------------------------------------
@module SvgIconFromOsmFactory
@module MapIconFromOsmFactory
@private
@------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -72,7 +72,7 @@ This will be used for the note address
import theConfig from '../data/Config.js';
import theDataSearchEngine from '../data/DataSearchEngine.js';
import { theSphericalTrigonometry } from '../util/SphericalTrigonometry.js';
import SvgMapBuilder from '../core/SvgMapBuilder.js';
import MapIconSvgBuilder from '../core/MapIconSvgBuilder.js';
import OverpassAPIDataLoader from '../core/OverpassAPIDataLoader.js';
import MapIconDataBuilder from '../core/MapIconDataBuilder.js';

Expand All @@ -90,7 +90,7 @@ const SEARCH_AROUND_FACTOR = 1.5;
@--------------------------------------------------------------------------------------------------------------------------
*/

class SvgIconFromOsmFactory {
class MapIconFromOsmFactory {

#route = null;
#overpassAPIDataLoader = new OverpassAPIDataLoader ( { searchRelations : false } );
Expand Down Expand Up @@ -154,11 +154,17 @@ class SvgIconFromOsmFactory {

#buildIconAndAdress ( ) {

let mapIconDataBuilder = new MapIconDataBuilder ( );
let mapIconData = mapIconDataBuilder.buildData ( this.#route, this.#overpassAPIDataLoader, this.#mapIconPosition );
let mapIconData = new MapIconDataBuilder ( ).buildData (
this.#route,
this.#overpassAPIDataLoader,
this.#mapIconPosition
);

let svgMapBuilder = new SvgMapBuilder ( );
let svgElement = svgMapBuilder.buildSvg ( this.#route, this.#overpassAPIDataLoader, mapIconData );
let svgElement = new MapIconSvgBuilder ( ).buildSvg (
this.#route,
this.#overpassAPIDataLoader,
mapIconData
);

this.#requestStarted = false;

Expand Down Expand Up @@ -227,8 +233,8 @@ class SvgIconFromOsmFactory {
}
}

export default SvgIconFromOsmFactory;
export default MapIconFromOsmFactory;

/*
--- End of svgIconFromOsmFactory.js file --------------------------------------------------------------------------------------
--- End of MapIconFromOsmFactory.js file --------------------------------------------------------------------------------------
*/
8 changes: 4 additions & 4 deletions src/core/SvgMapBuilder.js → src/core/MapIconSvgBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Tests ...
/**
@------------------------------------------------------------------------------------------------------------------------------
@file SvgMapBuilder.js
@file MapIconSvgBuilder.js
@copyright Copyright - 2017 2021 - wwwouaiebe - Contact: https://www.ouaie.be/
@license GNU General Public License
@private
Expand Down Expand Up @@ -58,7 +58,7 @@ import { SVG_NS, ICON_DIMENSIONS, ZERO, ONE, TWO, NOT_FOUND } from '../util/Cons
@--------------------------------------------------------------------------------------------------------------------------
*/

class SvgMapBuilder {
class MapIconSvgBuilder {

#route = null;
#overpassAPIDataLoader = null;
Expand Down Expand Up @@ -266,8 +266,8 @@ class SvgMapBuilder {
}
}

export default SvgMapBuilder;
export default MapIconSvgBuilder;

/*
--- End of SvgMapBuilder.js file ----------------------------------------------------------------------------------------------
--- End of MapIconSvgBuilder.js file ------------------------------------------------------------------------------------------
*/
4 changes: 2 additions & 2 deletions src/core/NoteEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import theDataSearchEngine from '../data/DataSearchEngine.js';
import { theEventDispatcher } from '../util/EventDispatcher.js';
import { theGeometry } from '../util/Geometry.js';
import { theSphericalTrigonometry } from '../util/SphericalTrigonometry.js';
import SvgIconFromOsmFactory from '../core/SvgIconFromOsmFactory.js';
import MapIconFromOsmFactory from '../core/MapIconFromOsmFactory.js';
import theConfig from '../data/Config.js';
import { newWaitUI } from '../UI/WaitUI.js';
import { newTwoButtonsDialog } from '../dialogs/TwoButtonsDialog.js';
Expand Down Expand Up @@ -161,7 +161,7 @@ class NoteEditor {
);

let latLng = route.itinerary.itineraryPoints.getAt ( maneuverIterator.value.itineraryPointObjId ).latLng;
await new SvgIconFromOsmFactory ( ).getPromiseIconAndAdress ( latLng, route.objId )
await new MapIconFromOsmFactory ( ).getPromiseIconAndAdress ( latLng, route.objId )
.then (
osmNoteData => {
this.#newNoteFromOsmData ( osmNoteData, route );
Expand Down
78 changes: 63 additions & 15 deletions src/core/OverpassAPIDataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class OverpassAPIDataLoader {
searchRelations : true
}

#nodes = new Map ( );
#ways = new Map ( );
#relations = new Map ( );

#adminNames = null;
#osmCityAdminLevel = null;
#place = null;
Expand All @@ -90,15 +94,15 @@ class OverpassAPIDataLoader {
*/

#setGeometry ( ) {
this.ways.forEach (
this.#ways.forEach (
way => {
way.geometry = [ [ ] ];
way.lat = LAT_LNG.defaultValue;
way.lon = LAT_LNG.defaultValue;
let nodesCounter = ZERO;
way.nodes.forEach (
nodeId => {
let node = this.nodes.get ( nodeId );
let node = this.#nodes.get ( nodeId );
way.geometry [ ZERO ].push ( [ node.lat, node.lon ] );
way.lat += node.lat;
way.lon += node.lon;
Expand All @@ -111,7 +115,7 @@ class OverpassAPIDataLoader {
}
}
);
this.relations.forEach (
this.#relations.forEach (
relation => {
relation.geometry = [ [ ] ];
relation.lat = LAT_LNG.defaultValue;
Expand All @@ -120,7 +124,7 @@ class OverpassAPIDataLoader {
relation.members.forEach (
member => {
if ( 'way' === member.type ) {
let way = this.ways.get ( member.ref );
let way = this.#ways.get ( member.ref );
relation.geometry.push ( way.geometry [ ZERO ] );
relation.lat += way.lat;
relation.lon += way.lon;
Expand All @@ -146,7 +150,7 @@ class OverpassAPIDataLoader {
osmElement => {
switch ( osmElement.type ) {
case 'node' :
this.nodes.set ( osmElement.id, osmElement );
this.#nodes.set ( osmElement.id, osmElement );
if (
osmElement.tags &&
this.#options.searchPlaces &&
Expand All @@ -167,12 +171,12 @@ class OverpassAPIDataLoader {
break;
case 'way' :
if ( this.#options.searchWays ) {
this.ways.set ( osmElement.id, osmElement );
this.#ways.set ( osmElement.id, osmElement );
}
break;
case 'relation' :
if ( this.#options.searchRelations ) {
this.relations.set ( osmElement.id, osmElement );
this.#relations.set ( osmElement.id, osmElement );
}
break;
case 'area' :
Expand Down Expand Up @@ -284,9 +288,6 @@ class OverpassAPIDataLoader {
this.#options [ key ] = value;
}
}
this.nodes = new Map ( );
this.ways = new Map ( );
this.relations = new Map ( );
}

/**
Expand Down Expand Up @@ -325,9 +326,9 @@ class OverpassAPIDataLoader {
this.#latLngDistance.distance = DISTANCE.defaultValue;
this.#city = null;

this.nodes.clear ( );
this.ways.clear ( );
this.relations.clear ( );
this.#nodes.clear ( );
this.#ways.clear ( );
this.#relations.clear ( );

await this.#overpassAPICall ( queries );
this.#setGeometry ( );
Expand All @@ -336,13 +337,60 @@ class OverpassAPIDataLoader {
}
}

/*
getter...
/**
A map with the osm nodes
@type {Map}
@readonly
*/

get nodes ( ) { return this.#nodes; }

/**
A map with the osm ways
@type {Map}
@readonly
*/

get ways ( ) { return this.#ways; }

/**
A map with the osm relations
@type {Map}
@readonly
*/

get relations ( ) { return this.#relations; }

/**
The osm place ( hamlet or village )
@type {String}
@readonly
*/

get place ( ) { return this.#place; }

/**
The osm city
@type {String}
@readonly
*/

get city ( ) { return this.#city; }

/**
The osm country
@type {String}
@readonly
*/

get country ( ) { return this.#adminNames [ OSM_COUNTRY_ADMIN_LEVEL ]; }

/**
The final status
@type {boolean}
@readonly
*/

get statusOk ( ) { return this.#statusOk; }
}

Expand Down
4 changes: 2 additions & 2 deletions src/dialogs/NoteDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import theConfig from '../data/Config.js';
import { newBaseDialog } from '../dialogs/BaseDialog.js';
import { theHTMLElementsFactory } from '../util/HTMLElementsFactory.js';
import { theHTMLSanitizer } from '../util/HTMLSanitizer.js';
import SvgIconFromOsmFactory from '../core/SvgIconFromOsmFactory.js';
import MapIconFromOsmFactory from '../core/MapIconFromOsmFactory.js';
import GeoCoder from '../core/GeoCoder.js';
import { theNoteDialogToolbar } from '../dialogs/NoteDialogToolbar.js';
import Note from '../data/Note.js';
Expand Down Expand Up @@ -352,7 +352,7 @@ function ourNewNoteDialog ( note, routeObjId, startGeoCoder ) {
}
else {
myNoteDialog.showWait ( );
let svgIconData = await new SvgIconFromOsmFactory ( ).getIconAndAdress ( note.latLng, routeObjId );
let svgIconData = await new MapIconFromOsmFactory ( ).getIconAndAdress ( note.latLng, routeObjId );
if ( svgIconData.statusOk ) {
myOnSvgIconSuccess ( svgIconData );
}
Expand Down
Loading

0 comments on commit 294d2d3

Please sign in to comment.