Skip to content

Commit

Permalink
Merge pull request #11 from camptocamp/add-feature-clicked-event
Browse files Browse the repository at this point in the history
Add basic click/hover events on the OpenLayers map
  • Loading branch information
jahow authored Aug 19, 2024
2 parents 4001375 + 4aae3dd commit e758ce3
Show file tree
Hide file tree
Showing 53 changed files with 856 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
"rules": {
"@typescript-eslint/no-explicit-any": 1
},
"ignorePatterns": ["**/*.test.ts", "apps"]
"ignorePatterns": ["**/*.test.ts", "apps", "**/mocks"]
}
36 changes: 36 additions & 0 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Quality Assurance
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, ready_for_review]

jobs:
format-typecheck-test:
name: Formatting, types and tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node & NPM
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install lib dependencies
run: npm ci

- name: Formatting
run: npm run format:check

- name: Type check
run: npm run typecheck

- name: Linting
run: npm run lint

- name: Run tests
run: npm test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
**/.vitepress/cache
**/.vitepress/dist
packages/*/dist
.idea
.idea
11 changes: 10 additions & 1 deletion apps/examples/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import ExampleGeocoding from '@/examples/Example-Geocoding.vue'
import ExampleGeocodingRaw from '@/examples/Example-Geocoding.vue?raw'
import ExampleZoomToLayer from '@/examples/Example-ZoomToLayer.vue'
import ExampleZoomToLayerRaw from '@/examples/Example-ZoomToLayer.vue?raw'
import ExampleMapEvents from '@/examples/Example-MapEvents.vue'
import ExampleMapEventsRaw from '@/examples/Example-MapEvents.vue?raw'
import { onMounted } from 'vue'
import hljs from 'highlight.js'
Expand Down Expand Up @@ -42,8 +44,15 @@ onMounted(() => {
<ExampleZoomToLayer></ExampleZoomToLayer>
</ExampleContainer>
<ExampleContainer
example-name="Example 4: geocoding"
example-name="Example 4: map events"
example-id="example04"
:source-code="ExampleMapEventsRaw"
>
<ExampleMapEvents></ExampleMapEvents>
</ExampleContainer>
<ExampleContainer
example-name="Example 5: geocoding"
example-id="example05"
:source-code="ExampleGeocodingRaw"
>
<ExampleGeocoding></ExampleGeocoding>
Expand Down
9 changes: 9 additions & 0 deletions apps/examples/src/components/Panel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts"></script>

<template>
<div class="p-3 text-xs text-gray-900 bg-white rounded-md shadow-xl">
<slot />
</div>
</template>

<style scoped></style>
56 changes: 56 additions & 0 deletions apps/examples/src/examples/Example-MapEvents.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import Map from 'ol/Map'
import { createMapFromContext, listen } from '@geospatial-sdk/openlayers'
import type { FeaturesHoverEvent, MapClickEvent, MapContext } from '@geospatial-sdk/core'
import { DEFAULT_CONTEXT } from '@/constants'
import Panel from '@/components/Panel.vue'
import type { Feature } from 'geojson'
const Layers = {
wms: {
type: 'wms',
url: 'https://ows.emodnet-bathymetry.eu/wms',
name: 'emodnet:mean_rainbowcolour'
},
geojson: {
type: 'geojson',
url: 'https://france-geojson.gregoiredavid.fr/repo/regions.geojson'
}
}
const mapRoot = ref<HTMLElement>()
let map: Map
let context = {
...DEFAULT_CONTEXT,
layers: [...DEFAULT_CONTEXT.layers, Layers.wms, Layers.geojson]
} as MapContext
let features = ref<Feature[]>([])
let clickCoordinates = ref<[number, number] | null>(null)
onMounted(async () => {
map = await createMapFromContext(context, mapRoot.value)
listen(map, 'features-hover', (event: FeaturesHoverEvent) => (features.value = event.features))
listen(map, 'map-click', (event: MapClickEvent) => (clickCoordinates.value = event.coordinate))
})
</script>

<template>
<div ref="mapRoot" class="w-full h-full relative">
<div class="absolute top-3 right-3 flex flex-col gap-3 z-50 w-56">
<Panel v-if="clickCoordinates">
<strong>Last click coordinates</strong>
{{ clickCoordinates.join(', ') }}
</Panel>
<Panel v-for="(feature, index) in features" v-bind:key="index">
<h4 class="font-bold mb-1">Feature</h4>
<ul>
<li v-for="(value, key) in feature.properties" v-bind:key="key">
<strong>{{ key }}</strong
>:&nbsp;{{ value }}
</li>
</ul>
</Panel>
</div>
</div>
</template>
4 changes: 3 additions & 1 deletion docs/api/core/functions/computeMapContextDiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ The following logic is produced by identifying layers in both context
and determining whether they have been added, removed, changed or reordered.

Identifying layers to determine if they have been added/removed/reordered is done like so:

1. For layers with an `id` property, use non-strict equality on it (e.g. '2' and 2 are equivalent);
2. For layers without `id`, compute a hash of their base properties _excluding the `extras` property_

Determining whether layers have changed is done like so:

1. For layers with an `id` property, the value of the `version` field is compared;
if values are different (using non-strict equality), then the layer is considered to have changed; otherwise
it is considered to have remained the same
Expand All @@ -35,6 +37,6 @@ Determining whether layers have changed is done like so:

[packages/core/lib/utils/map-context-diff.ts:72](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/utils/map-context-diff.ts#L72)

***
---

Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
2 changes: 1 addition & 1 deletion docs/api/core/functions/deepFreeze.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ deepFreeze<U>(obj): U

[packages/core/lib/utils/freeze.ts:1](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/utils/freeze.ts#L1)

***
---

Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
2 changes: 1 addition & 1 deletion docs/api/core/functions/removeSearchParams.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Removes the given search params from the URL completely; this is case-insensitiv

[packages/core/lib/utils/url.ts:6](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/utils/url.ts#L6)

***
---

Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
50 changes: 25 additions & 25 deletions docs/api/core/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@

### Interfaces

| Interface | Description |
| :------ | :------ |
| [MapContext](interfaces/MapContext.md) | - |
| [MapContextBaseLayer](interfaces/MapContextBaseLayer.md) | - |
| [MapContextDiff](interfaces/MapContextDiff.md) | Describes a delta between two contexts, in order to be |
| [MapContextLayer](interfaces/MapContextLayer.md) | - |
| [MapContextLayerGeojson](interfaces/MapContextLayerGeojson.md) | - |
| Interface | Description |
| :------------------------------------------------------------------- | :------------------------------------------------------------- |
| [MapContext](interfaces/MapContext.md) | - |
| [MapContextBaseLayer](interfaces/MapContextBaseLayer.md) | - |
| [MapContextDiff](interfaces/MapContextDiff.md) | Describes a delta between two contexts, in order to be |
| [MapContextLayer](interfaces/MapContextLayer.md) | - |
| [MapContextLayerGeojson](interfaces/MapContextLayerGeojson.md) | - |
| [MapContextLayerPositioned](interfaces/MapContextLayerPositioned.md) | Associates a position to a layer; the position is the index of |
| [MapContextLayerReordered](interfaces/MapContextLayerReordered.md) | Describes a layer being moved to a different position |
| [MapContextLayerWfs](interfaces/MapContextLayerWfs.md) | - |
| [MapContextLayerWms](interfaces/MapContextLayerWms.md) | - |
| [MapContextLayerWmts](interfaces/MapContextLayerWmts.md) | - |
| [MapContextLayerXyz](interfaces/MapContextLayerXyz.md) | - |
| [MapContextView](interfaces/MapContextView.md) | - |
| [MapContextLayerReordered](interfaces/MapContextLayerReordered.md) | Describes a layer being moved to a different position |
| [MapContextLayerWfs](interfaces/MapContextLayerWfs.md) | - |
| [MapContextLayerWms](interfaces/MapContextLayerWms.md) | - |
| [MapContextLayerWmts](interfaces/MapContextLayerWmts.md) | - |
| [MapContextLayerXyz](interfaces/MapContextLayerXyz.md) | - |
| [MapContextView](interfaces/MapContextView.md) | - |

### Type Aliases

| Type alias | Description |
| :------ | :------ |
| [Coordinate](type-aliases/Coordinate.md) | - |
| [Extent](type-aliases/Extent.md) | Min X, min Y, max X, max Y |
| [LayerDimensions](type-aliases/LayerDimensions.md) | - |
| [LayerExtras](type-aliases/LayerExtras.md) | - |
| Type alias | Description |
| :------------------------------------------------- | :------------------------- |
| [Coordinate](type-aliases/Coordinate.md) | - |
| [Extent](type-aliases/Extent.md) | Min X, min Y, max X, max Y |
| [LayerDimensions](type-aliases/LayerDimensions.md) | - |
| [LayerExtras](type-aliases/LayerExtras.md) | - |

### Functions

| Function | Description |
| :------ | :------ |
| [computeMapContextDiff](functions/computeMapContextDiff.md) | The following logic is produced by identifying layers in both context |
| [deepFreeze](functions/deepFreeze.md) | - |
| [removeSearchParams](functions/removeSearchParams.md) | Removes the given search params from the URL completely; this is case-insensitive |
| Function | Description |
| :---------------------------------------------------------- | :-------------------------------------------------------------------------------- |
| [computeMapContextDiff](functions/computeMapContextDiff.md) | The following logic is produced by identifying layers in both context |
| [deepFreeze](functions/deepFreeze.md) | - |
| [removeSearchParams](functions/removeSearchParams.md) | Removes the given search params from the URL completely; this is case-insensitive |

***
---

Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
4 changes: 2 additions & 2 deletions docs/api/core/interfaces/MapContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ layers: MapContextLayer[];

[packages/core/lib/model/map-context.ts:94](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L94)

***
---

### view

Expand All @@ -26,6 +26,6 @@ view: MapContextView;

[packages/core/lib/model/map-context.ts:95](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L95)

***
---

Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
6 changes: 3 additions & 3 deletions docs/api/core/interfaces/MapContextBaseLayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ non-serializable entities

[packages/core/lib/model/map-context.ts:16](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L16)

***
---

### id?

Expand All @@ -37,7 +37,7 @@ id?: string | number;

[packages/core/lib/model/map-context.ts:8](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L8)

***
---

### version?

Expand All @@ -49,6 +49,6 @@ version?: number;

[packages/core/lib/model/map-context.ts:9](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L9)

***
---

Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
11 changes: 6 additions & 5 deletions docs/api/core/interfaces/MapContextDiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Describes a delta between two contexts, in order to be
applied to an existing map.

For positions to be correct the order of operations should be:

1. change layers
2. remove layers
3. add layers
Expand All @@ -23,7 +24,7 @@ layersAdded: MapContextLayerPositioned[];

[packages/core/lib/model/map-context-diff.ts:35](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context-diff.ts#L35)

***
---

### layersChanged

Expand All @@ -35,7 +36,7 @@ layersChanged: MapContextLayerPositioned[];

[packages/core/lib/model/map-context-diff.ts:32](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context-diff.ts#L32)

***
---

### layersRemoved

Expand All @@ -47,7 +48,7 @@ layersRemoved: MapContextLayerPositioned[];

[packages/core/lib/model/map-context-diff.ts:34](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context-diff.ts#L34)

***
---

### layersReordered

Expand All @@ -59,7 +60,7 @@ layersReordered: MapContextLayerReordered[];

[packages/core/lib/model/map-context-diff.ts:33](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context-diff.ts#L33)

***
---

### viewChanges

Expand All @@ -71,6 +72,6 @@ viewChanges: MapContextView;

[packages/core/lib/model/map-context-diff.ts:36](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context-diff.ts#L36)

***
---

Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
12 changes: 6 additions & 6 deletions docs/api/core/interfaces/MapContextLayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ non-serializable entities

[packages/core/lib/model/map-context.ts:16](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L16)

***
---

### id?

Expand All @@ -30,12 +30,12 @@ id?: string | number;

[packages/core/lib/model/map-context.ts:8](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L8)

***
---

### type

```ts
type:
type:
| "wms"
| "wmts"
| "wfs"
Expand All @@ -47,7 +47,7 @@ type:

[packages/core/lib/model/map-context.ts:20](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L20)

***
---

### url?

Expand All @@ -59,7 +59,7 @@ url?: string;

[packages/core/lib/model/map-context.ts:21](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L21)

***
---

### version?

Expand All @@ -71,6 +71,6 @@ version?: number;

[packages/core/lib/model/map-context.ts:9](https://github.com/jahow/geospatial-sdk/blob/eda8b4f/packages/core/lib/model/map-context.ts#L9)

***
---

Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
Loading

0 comments on commit e758ce3

Please sign in to comment.