-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GSREN3D-161: Station Primitives & Arcs #60
Open
bkuster
wants to merge
5
commits into
camptocamp:main
Choose a base branch
from
virtualcitySYSTEMS:feature-primitives
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { | ||
AbstractInteraction, | ||
vcsLayerName, | ||
EventType, | ||
ModificationKeyType, | ||
VectorLayer, | ||
type InteractionEvent, | ||
type VcsApp, | ||
ArcStyle, | ||
GeoJSONLayer, | ||
markVolatile, | ||
mercatorProjection, | ||
} from '@vcmap/core' | ||
import { useStationsStore } from '@/stores/stations' | ||
import { Feature } from 'ol' | ||
import { type Point, LineString } from 'ol/geom' | ||
import type { StationsModel } from '@/model/stations.model' | ||
import { DeclarativeStyleItem } from '@vcmap/core' | ||
|
||
class SelectStationInteraction extends AbstractInteraction { | ||
private readonly _stationsLayerName: string | ||
|
||
constructor(stationsLayerName: string) { | ||
super(EventType.CLICKMOVE, ModificationKeyType.NONE) | ||
|
||
this._stationsLayerName = stationsLayerName | ||
} | ||
|
||
async pipe(event: InteractionEvent): Promise<InteractionEvent> { | ||
const isLayerFeature = | ||
event.feature?.[vcsLayerName] === this._stationsLayerName | ||
|
||
if (event.type & EventType.CLICK) { | ||
const store = useStationsStore() | ||
if (event.feature && isLayerFeature) { | ||
store.selectStation(event.feature as Feature<Point>) | ||
} else if (store.selectedStation) { | ||
store.selectStation() | ||
} | ||
} else if (isLayerFeature) { | ||
document.body.style.cursor = 'pointer' | ||
} else { | ||
document.body.style.cursor = 'auto' | ||
} | ||
|
||
return event | ||
} | ||
} | ||
|
||
export default SelectStationInteraction | ||
|
||
const scratchPoiLayerName = '_poiScracthLayer' | ||
|
||
const scratchArcLayerName = '_poiArcLayer' | ||
|
||
const stationToPoi: Map<number, [Feature<Point>]> = new Map() | ||
|
||
function getPoisForStation( | ||
stationId: number, | ||
vcsApp: VcsApp | ||
): [Feature<Point>] | [] { | ||
if (stationToPoi.size === 0) { | ||
const stationsLayer = vcsApp.layers.getByKey('trambusStops') as GeoJSONLayer | ||
const poiLayer = vcsApp.layers.getByKey('poi') as GeoJSONLayer | ||
const source = stationsLayer.getSource() | ||
const features = poiLayer.getFeatures() as [Feature<Point>] | ||
features.map((poiFeature) => { | ||
const geom = poiFeature.getGeometry() as Point | ||
const station = source.getClosestFeatureToCoordinate( | ||
geom.getCoordinates() | ||
) | ||
|
||
const stationId = station.get('id') as number | ||
if (!stationToPoi.has(stationId)) { | ||
stationToPoi.set(stationId, [poiFeature]) | ||
} else { | ||
const featuresArray = stationToPoi.get(stationId) as [Feature<Point>] | ||
featuresArray.push(poiFeature) | ||
} | ||
}) | ||
} | ||
return stationToPoi.get(stationId) ?? [] | ||
} | ||
|
||
function getScratchLayer( | ||
app: VcsApp, | ||
layerName: string, | ||
arc?: boolean | ||
): VectorLayer { | ||
if (app.layers.hasKey(layerName)) { | ||
return app.layers.getByKey(layerName) as VectorLayer | ||
} | ||
|
||
const layer = new VectorLayer({ | ||
name: layerName, | ||
projection: mercatorProjection.toJSON(), | ||
}) | ||
if (arc) { | ||
layer.setStyle(new ArcStyle()) | ||
} else { | ||
layer.setStyle( | ||
new DeclarativeStyleItem({ | ||
declarativeStyle: { | ||
pointOutlineColor: "color('#6B23C9')", | ||
pointOutlineWidth: '2', | ||
labelText: { | ||
conditions: [ | ||
['${ordre}===1', "'${nom_site}'"], | ||
['true', "''"], | ||
], | ||
}, | ||
labelOutlineColor: "color('#ffffff')", | ||
labelColor: "color('#6B23C9')", | ||
labelOutlineWidth: '2', | ||
font: "'13px sans-serif'", | ||
}, | ||
}) | ||
) | ||
} | ||
markVolatile(layer) | ||
app.layers.add(layer) | ||
layer.activate() | ||
return layer | ||
} | ||
|
||
export async function explodeStationPOIs( | ||
app: VcsApp, | ||
poiLayerName: string, | ||
station?: StationsModel | null | ||
): Promise<void> { | ||
const poiScratchLayer = getScratchLayer(app, scratchPoiLayerName) | ||
const arcLayer = getScratchLayer(app, scratchArcLayerName, true) | ||
poiScratchLayer.removeAllFeatures() | ||
arcLayer.removeAllFeatures() | ||
if (station) { | ||
const poiLayer = app.layers.getByKey(poiLayerName) as GeoJSONLayer | ||
if (poiLayer) { | ||
await poiLayer.fetchData() | ||
const features = getPoisForStation(station.id, app) | ||
// TODO drape onto terrain | ||
poiScratchLayer.addFeatures(features) | ||
const arcFeatures = features.map((f) => { | ||
const geometry = f.getGeometry() as Point | ||
const lineString = new LineString([ | ||
station.position, | ||
geometry.getCoordinates(), | ||
]) | ||
return new Feature(lineString) | ||
}) | ||
arcLayer.addFeatures(arcFeatures) | ||
} else { | ||
console.warn(`Could not find POI layer with name: ${poiLayerName}`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { LineNumber } from '@/model/lines.model' | ||
import type { Feature } from 'ol' | ||
import type { Point } from 'ol/geom' | ||
import type { Coordinate } from 'ol/coordinate' | ||
|
||
export interface StationsModel { | ||
id: number | ||
version: string | ||
trace_type: string // FIXME this is probably an enum | ||
li_code: LineNumber | ||
nom: string | ||
position: Coordinate | ||
} | ||
|
||
function lineCodeFromString(stringLineCode: string): LineNumber { | ||
if (stringLineCode === 'T1') { | ||
return 1 | ||
} | ||
|
||
if (stringLineCode === 'T2') { | ||
return 2 | ||
} | ||
|
||
if (stringLineCode === 'T3') { | ||
return 3 | ||
} | ||
|
||
return 4 | ||
} | ||
|
||
export function getStationModelFromFeature( | ||
feature: Feature<Point> | ||
): StationsModel { | ||
const properties = feature.getProperties() | ||
const geometry = feature.getGeometry() | ||
if (!geometry) { | ||
throw new Error('Cannot set station from a Feature without a geometry') | ||
} | ||
|
||
return { | ||
id: properties.id, | ||
version: properties.version, | ||
trace_type: properties.trace_type, | ||
li_code: lineCodeFromString(properties.li_code), | ||
nom: properties.nom, | ||
position: geometry.getCoordinates(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ref } from 'vue' | ||
import type { Ref } from 'vue' | ||
import { defineStore } from 'pinia' | ||
import type { Feature } from 'ol' | ||
import type { Point } from 'ol/geom' | ||
import { | ||
type StationsModel, | ||
getStationModelFromFeature, | ||
} from '@/model/stations.model' | ||
|
||
export const useStationsStore = defineStore('stores', () => { | ||
const selectedStation: Ref<StationsModel | null> = ref(null) | ||
|
||
function selectStation(stationFeature?: Feature<Point>) { | ||
selectedStation.value = stationFeature | ||
? getStationModelFromFeature(stationFeature) | ||
: null | ||
} | ||
|
||
return { selectStation, selectedStation } | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
publish before merging