Skip to content

Commit 067a588

Browse files
authored
Merge pull request #355 from NickPhura/PRC-1048
PRC-1048: Change shape border weight based on shape size and map zoom level.
2 parents 0961d1a + 12d4107 commit 067a588

File tree

1 file changed

+68
-41
lines changed

1 file changed

+68
-41
lines changed

src/app/applications/application-aside/application-aside.component.ts

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, OnChanges, OnDestroy, Input, SimpleChanges } from '@angular/core';
1+
import { Component, OnInit, OnDestroy, Input } from '@angular/core';
22
import { Subject } from 'rxjs';
33
import { takeUntil } from 'rxjs/operators';
44
import * as L from 'leaflet';
@@ -13,7 +13,7 @@ import { FeatureService } from 'app/services/feature.service';
1313
templateUrl: './application-aside.component.html',
1414
styleUrls: ['./application-aside.component.scss']
1515
})
16-
export class ApplicationAsideComponent implements OnInit, OnChanges, OnDestroy {
16+
export class ApplicationAsideComponent implements OnInit, OnDestroy {
1717
@Input() application: Application = null;
1818

1919
private ngUnsubscribe: Subject<boolean> = new Subject<boolean>();
@@ -138,13 +138,6 @@ export class ApplicationAsideComponent implements OnInit, OnChanges, OnDestroy {
138138
this.updateData();
139139
}
140140

141-
ngOnChanges(changes: SimpleChanges) {
142-
// guard against null application
143-
if (changes.application.currentValue) {
144-
this.updateData();
145-
}
146-
}
147-
148141
private updateData() {
149142
if (this.application) {
150143
if (this.fg) {
@@ -172,6 +165,11 @@ export class ApplicationAsideComponent implements OnInit, OnChanges, OnDestroy {
172165
const layer = L.geoJSON(featureObj);
173166
this.fg.addLayer(layer);
174167
layer.addTo(this.map);
168+
169+
this.map.on('zoomend', () => {
170+
const weight = this.getWeight(feature.properties.TENURE_AREA_IN_HECTARES, this.map.getZoom());
171+
layer.setStyle({ weight });
172+
});
175173
});
176174

177175
const bounds = this.fg.getBounds();
@@ -185,39 +183,68 @@ export class ApplicationAsideComponent implements OnInit, OnChanges, OnDestroy {
185183
}
186184
}
187185

188-
// called from parent component
189-
public drawMap(app: Application) {
190-
if (app.tantalisID) {
191-
this.featureService
192-
.getByTantalisId(app.tantalisID)
193-
.pipe(takeUntil(this.ngUnsubscribe))
194-
.subscribe(
195-
features => {
196-
if (this.fg) {
197-
_.each(this.layers, layer => {
198-
this.map.removeLayer(layer);
199-
});
200-
this.fg.clearLayers();
201-
}
202-
203-
_.each(features, function(feature) {
204-
const f = JSON.parse(JSON.stringify(feature));
205-
// needs to be valid GeoJSON
206-
delete f.geometry_name;
207-
const featureObj: GeoJSON.Feature<any> = f;
208-
const layer = L.geoJSON(featureObj);
209-
this.fg.addLayer(layer);
210-
layer.addTo(this.map);
211-
});
212-
213-
const bounds = this.fg.getBounds();
214-
if (bounds && bounds.isValid()) {
215-
this.map.fitBounds(bounds, this.maxZoom);
216-
}
217-
},
218-
error => console.log('error =', error)
219-
);
186+
/**
187+
* Given a features size in hectares and the maps zoom level, returns the weight to use when rendering the shape.
188+
* Increasing the weight is used to allow features to remain visible on the map when zoomed out far.
189+
*
190+
* @private
191+
* @param {number} size size of the feature, in hectares.
192+
* @param {number} zoom zoom level of the map.
193+
* @returns {number} a positive non-null weight for the layer to use when rendering the shape (default: 3)
194+
* @memberof DetailsMapComponent
195+
*/
196+
private getWeight(size: number, zoom: number): number {
197+
if (!size || !zoom) {
198+
return 3; // default
220199
}
200+
201+
if (size < 2) {
202+
if (zoom < 3) {
203+
return 6;
204+
}
205+
if (zoom < 10) {
206+
return 7;
207+
}
208+
if (zoom < 14) {
209+
return 6;
210+
}
211+
}
212+
213+
if (size < 15) {
214+
if (zoom < 12) {
215+
return 6;
216+
}
217+
}
218+
219+
if (size < 30) {
220+
if (zoom < 9) {
221+
return 6;
222+
}
223+
}
224+
225+
if (size < 60) {
226+
if (zoom < 12) {
227+
return 5;
228+
}
229+
}
230+
231+
if (size < 150) {
232+
if (zoom < 9) {
233+
return 6;
234+
}
235+
}
236+
237+
if (size < 1000) {
238+
if (zoom < 6) {
239+
return 6;
240+
}
241+
}
242+
243+
if (zoom < 5) {
244+
return 5;
245+
}
246+
247+
return 3; // default
221248
}
222249

223250
ngOnDestroy() {

0 commit comments

Comments
 (0)