Skip to content

Commit

Permalink
feature: limit zoom to selected maps.
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj committed Jul 6, 2023
1 parent 6487c67 commit afa7b34
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 19 deletions.
12 changes: 12 additions & 0 deletions projects/fb-openlayers/src/lib/view.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ export class ViewDirective
} else {
properties[key] = fromLonLat(changes[key].currentValue);
}
} else if (key === 'minZoom') {
if (this.view) {
this.view.setMinZoom(changes[key].currentValue);
} else {
properties[key] = changes[key].currentValue;
}
} else if (key === 'maxZoom') {
if (this.view) {
this.view.setMaxZoom(changes[key].currentValue);
} else {
properties[key] = changes[key].currentValue;
}
} else {
properties[key] = changes[key].currentValue;
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/app.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ mat-nav-list {
background-color: rgba(130,130,130,.3);
padding: 10px 2px 2px 2px;
}
.rightUtilsPanel div {
height: 60px;
}

.mapButton {
position: fixed;
Expand Down
14 changes: 14 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,20 @@
<br />&nbsp;<br />
</div>

<!-- constrain zoom to selected map(s) extent -->
<div>
<button
mat-mini-fab
[color]="app.config.map.limitZoom ? 'accent' : ''"
(click)="toggleLimitMapZoom()"
matTooltip="Constrain map zoom."
matTooltipPosition="left"
>
<mat-icon>zoom_in_map</mat-icon>
</button>
<br />&nbsp;<br />
</div>

<!-- Drop Waypoint button -->
<div>
<button
Expand Down
8 changes: 8 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ export class AppComponent {
: 'rotate(' + (0 - this.app.data.vessels.active.orientation) + 'rad)';
}

public toggleLimitMapZoom() {
this.app.config.map.limitZoom = this.app.config.map.limitZoom
? false
: true;
this.skres.setMapZoomRange();
this.app.saveConfig();
}

public toggleFullscreen() {
const docel = document.documentElement;
const fscreen =
Expand Down
36 changes: 28 additions & 8 deletions src/app/app.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const FreeboardConfig = {
rotation: 0,
moveMap: false,
northUp: true,
animate: false
animate: false,
limitZoom: false
},
vesselTrail: false, // display trail
vesselWindVectors: true, // display vessel TWD, AWD vectors
Expand Down Expand Up @@ -165,11 +166,17 @@ interface PluginInfo {
@Injectable({ providedIn: 'root' })
export class AppInfo extends Info {
private DEV_SERVER = {
host: 'localhost', // host name || ip address
host: '192.168.86.32', //'localhost', // host name || ip address
port: 3000, // port number
ssl: false
};

// controls map zoom limits
public MAP_ZOOM_EXTENT = {
min: 2,
max: 28
};

public hostName: string;
public hostPort: number;
public hostSSL: boolean;
Expand Down Expand Up @@ -223,28 +230,37 @@ export class AppInfo extends Info {
? this.DEV_SERVER.host
: window.location.hostname;

this.hostSSL =
window.location.protocol === 'https:' ||
(this.devMode && this.DEV_SERVER.ssl)
? true
: false;

this.hostPort =
typeof this.hostParams.port !== 'undefined'
? parseInt(this.hostParams.port)
: this.devMode && this.DEV_SERVER.port
? this.DEV_SERVER.port
: parseInt(window.location.port);

this.hostSSL =
window.location.protocol === 'https:' ||
(this.devMode && this.DEV_SERVER.ssl)
? true
: false;
// if no port specified then set to 80 | 443
this.hostPort = isNaN(this.hostPort)
? this.hostSSL
? 443
: 80
: this.hostPort;

this.host = `${this.hostSSL ? 'https:' : 'http:'}//${this.hostName}:${
this.hostPort
}`;

this.debug('host:', this.host);

this.id = 'freeboard';
this.name = 'Freeboard';
this.shortName = 'freeboard';
this.description = `Signal K Chart Plotter.`;
this.version = '2.0.2';
this.version = '2.1.0';
this.url = 'https://github.com/signalk/freeboard-sk';
this.logo = './assets/img/app_logo.png';

Expand Down Expand Up @@ -556,6 +572,10 @@ export class AppInfo extends Info {
cleanConfig(settings) {
this.debug('Cleaning config keys...');

if (typeof settings.map.limitZoom === 'undefined') {
settings.map.limitZoom = false;
}

if (typeof settings.anchorRadius === 'undefined') {
settings.anchorRadius = 40;
}
Expand Down
7 changes: 4 additions & 3 deletions src/app/modules/map/fb-map.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
[zoom]="fbMap.zoomLevel"
[center]="fbMap.center"
[rotation]="fbMap.rotation"
[minZoom]="fbMap.minZoom"
[minZoom]="app.MAP_ZOOM_EXTENT.min"
[maxZoom]="app.MAP_ZOOM_EXTENT.max"
[enableAnimation]="false"
>
<!-- Draw / modify -->
Expand Down Expand Up @@ -48,7 +49,7 @@
<button
mat-mini-fab
(click)="zoomMap(false)"
[disabled]="fbMap.zoomLevel <= fbMap.minZoom"
[disabled]="fbMap.zoomLevel <= app.MAP_ZOOM_EXTENT.min"
matTooltip="Zoom out"
>
<mat-icon>remove</mat-icon>
Expand All @@ -57,7 +58,7 @@
<button
mat-mini-fab
(click)="zoomMap(true)"
[disabled]="fbMap.zoomLevel >= fbMap.maxZoom"
[disabled]="fbMap.zoomLevel >= app.MAP_ZOOM_EXTENT.max"
matTooltip="Zoom in"
>
<mat-icon>add</mat-icon>
Expand Down
9 changes: 2 additions & 7 deletions src/app/modules/map/fb-map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ interface IDrawInfo {
properties: { [key: string]: any };
}

const MAP_MAX_ZOOM = 28;
const MAP_MIN_ZOOM = 2;

enum INTERACTION_MODE {
MEASURE,
DRAW,
Expand Down Expand Up @@ -207,8 +204,6 @@ export class FBMapComponent implements OnInit, OnDestroy {

// ** map ctrl **
fbMap = {
minZoom: MAP_MIN_ZOOM,
maxZoom: MAP_MAX_ZOOM,
rotation: 0,
center: [0, 0],
zoomLevel: 1,
Expand Down Expand Up @@ -924,11 +919,11 @@ export class FBMapComponent implements OnInit, OnDestroy {
// ** handle map zoom controls
public zoomMap(zoomIn: boolean) {
if (zoomIn) {
if (this.app.config.map.zoomLevel < MAP_MAX_ZOOM) {
if (this.app.config.map.zoomLevel < this.app.MAP_ZOOM_EXTENT.max) {
++this.app.config.map.zoomLevel;
}
} else {
if (this.app.config.map.zoomLevel > MAP_MIN_ZOOM) {
if (this.app.config.map.zoomLevel > this.app.MAP_ZOOM_EXTENT.min) {
--this.app.config.map.zoomLevel;
}
}
Expand Down
42 changes: 41 additions & 1 deletion src/app/modules/skresources/resources.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ export class SKResources {
this.app.config.selections.charts = t.filter((i) => {
return i ? true : false;
});
// set map zoom extent
this.setMapZoomRange();
this.app.saveConfig();
this.updateSource.next({ action: 'selected', mode: 'chart' });
}
Expand Down Expand Up @@ -687,10 +689,43 @@ export class SKResources {
}

// **** CHARTS ****

/** calc aggregated min-max zoom from selected charts */
setMapZoomRange(useDefault?: boolean) {
const defaultExtent = {
min: 2,
max: 28
};
if (useDefault || !this.app.config.map.limitZoom) {
this.app.MAP_ZOOM_EXTENT = defaultExtent;
} else {
const derivedExtent = {
min: 1000,
max: -1
};
this.app.data.charts.forEach((c) => {
if (c[2]) {
// selected
if (c[1].minZoom < derivedExtent.min) {
derivedExtent.min = c[1].minZoom;
}
if (c[1].maxZoom > derivedExtent.max) {
derivedExtent.max = c[1].maxZoom;
}
}
this.app.MAP_ZOOM_EXTENT.min =
derivedExtent.min === 1000 ? defaultExtent.min : derivedExtent.min;
this.app.MAP_ZOOM_EXTENT.max =
derivedExtent.max === -1 ? defaultExtent.max : derivedExtent.max;
});
this.app.debug('*** MAP_ZOOM_EXTENT', this.app.MAP_ZOOM_EXTENT);
}
}

OSMCharts = [].concat(OSM);
// ** get charts from sk server
getCharts(apiVersion = this.app.config.chartApi ?? 1) {
// ** fetch charts from server
// fetch charts from server
this.signalk.api.get(apiVersion, `/resources/charts`).subscribe(
(res: Charts) => {
this.app.data.charts = [];
Expand Down Expand Up @@ -750,6 +785,9 @@ export class SKResources {
// arrange the chart layers
this.arrangeChartLayers();

// set map zoom extent
this.setMapZoomRange();

// emit update
this.updateSource.next({ action: 'get', mode: 'chart' });
},
Expand All @@ -770,6 +808,8 @@ export class SKResources {
: false;
dc.push(this.OSMCharts[1]);
this.app.data.charts = dc;
// set map zoom extent
this.setMapZoomRange();
}
);
}
Expand Down

0 comments on commit afa7b34

Please sign in to comment.