Skip to content

Commit

Permalink
feat (wip): reference point on map
Browse files Browse the repository at this point in the history
  • Loading branch information
tylercchase committed Nov 13, 2024
1 parent 77d61d0 commit 96873ff
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/app/components/map/map.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<div (dragover)="onFileHovered($event)"
id="map" class="map w100 h100" #map>

<div class="test" #referencepreview>
<mat-icon>home</mat-icon>
</div>
</div>

<div class="map-header">
Expand Down Expand Up @@ -90,3 +94,4 @@
map
</mat-icon>
</span>

14 changes: 14 additions & 0 deletions src/app/components/map/map.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,17 @@ button {
right: 1px;
top: 1px;
}
.test {
background: white;
border: 7px solid #c9cac5;
position: absolute;
top: 5%;
left:10%;
width: 35px;
height: 35px;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
border-radius: 80%;
}
40 changes: 40 additions & 0 deletions src/app/components/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class MapComponent implements OnInit, OnDestroy {
@Output() loadUrlState = new EventEmitter<void>();
@ViewChild('overlay', { static: true }) overlayRef: ElementRef;
@ViewChild('map', { static: true }) mapRef: ElementRef;
@ViewChild('referencepreview', { static: true }) referencePreview: ElementRef;
@ViewChild('browsetooltip', {static: false}) browseDisclaimer: ElementRef;

public drawMode$ = this.store$.select(mapStore.getMapDrawMode);
Expand Down Expand Up @@ -264,7 +265,46 @@ export class MapComponent implements OnInit, OnDestroy {
isOpen => this.isFiltersMenuOpen = isOpen
)
);
this.subs.add(
this.mapService.referencePointRelation.subscribe((thing: any) => {
if(thing === null) {
this.referencePreview.nativeElement.style.visibility = "hidden";

return
}
let mapExtent = thing[0];
let referencePointCoords = thing[1];

let left_offset = 50;
let top_offset = 50;
// if(referencePointCoords[1] < mapExtent[3] && referencePointCoords[1] > mapExtent[1]) {
// top_offset = ((referencePointCoords[1] - mapExtent[1]) / (mapExtent[3] - mapExtent[1])) * 100
// }
// 44% top
// 95% left
// probably need a better calc of this actually
if(referencePointCoords[0] < 0) {
left_offset = 0;
} else if(referencePointCoords[0] > mapExtent[0]) {
left_offset = mapExtent[0] - 50;
} else {
left_offset = referencePointCoords[0] - 21
}
if(referencePointCoords[1] < 0) {
top_offset = 0;
} else if(referencePointCoords[1] > mapExtent[1]) {
top_offset = mapExtent[1] - 50
} else {
top_offset = referencePointCoords[1] - 21
}



let a = this.referencePreview.nativeElement;
a.style.visibility = "shown"
a.style = `left: ${left_offset}px; top: ${top_offset}px;`;
})
)
}

public onFileHovered(e): void {
Expand Down
34 changes: 32 additions & 2 deletions src/app/services/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { SetGeocode } from '@store/filters';
import { Extent } from 'ol/extent';
import { MultiPolygon } from 'ol/geom';
import GeoJSON from 'ol/format/GeoJSON.js';
import * as olExtent from 'ol/extent';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -155,6 +156,8 @@ export class MapService {
)
);

private referencePoint;
public referencePointRelation = new Subject<Number[]>();
constructor(
private wktService: WktService,
private legacyAreaFormat: LegacyAreaFormatService,
Expand Down Expand Up @@ -476,6 +479,7 @@ export class MapService {
this.onMapReady(this.map);
});
}
private referencePointLayer;

private createNewMap(overlay): Map {
this.overviewMap = new OverviewMap({
Expand All @@ -486,6 +490,10 @@ export class MapService {
className: 'ol-overviewmap ol-custom-overviewmap',
});

const source = new VectorSource();
this.referencePointLayer = new VectorLayer({
source
})

const newMap = new Map({
layers: [
Expand All @@ -495,6 +503,7 @@ export class MapService {
this.selectedLayer,
this.mapView?.gridlines,
this.pinnedProducts,
this.referencePointLayer
],
target: 'map',
view: this.mapView.view,
Expand All @@ -506,6 +515,8 @@ export class MapService {
newMap.addInteraction(this.timeseriesClick);
newMap.addInteraction(this.selectHover);
newMap.addInteraction(this.selectSarviewEventHover);

this.referencePoint = new Feature(new Point([-13636084.632833757, 4583385.933366808]));
this.selectClick.on('select', e => {
// netcdf-layer
// if (this.drawService.in)
Expand Down Expand Up @@ -534,6 +545,11 @@ export class MapService {
const [lon, lat] = proj.toLonLat(e.coordinate, this.epsg());
this.mousePositionSubject$.next({ lon, lat });
});
newMap.on('pointerdrag', (_e) => {
if(this.referencePoint) {
this.updateReferencePreview();
}
})

newMap.on('movestart', () => {
newMap.getViewport().style.cursor = 'crosshair';
Expand Down Expand Up @@ -563,7 +579,7 @@ export class MapService {
this.drawService.getLayer().setZIndex(100);
this.focusLayer.setZIndex(99);
this.selectedLayer.setZIndex(98);

this.referencePointLayer.getSource().addFeature(this.referencePoint)

newMap.on('moveend', e => {
const currentMap = e.map;
Expand All @@ -579,7 +595,21 @@ export class MapService {

return newMap;
}

private updateReferencePreview() {
let mapExtent = this.map.getView().calculateExtent()
let referencePointCoords = this.referencePoint.getGeometry().getCoordinates();
let result = olExtent.containsCoordinate(
mapExtent,
referencePointCoords
)
referencePointCoords = this.map.getPixelFromCoordinate(referencePointCoords)
if(!result) {
this.referencePointRelation.next([this.map.getSize(), referencePointCoords, ])
}
else {
this.referencePointRelation.next(null)
}
}
private updatedMap(): Map {
if (this.map.getView().getProjection().getCode() !== this.mapView.projection.epsg) {
this.map.setView(this.mapView.view);
Expand Down

0 comments on commit 96873ff

Please sign in to comment.