Skip to content

Commit

Permalink
Merge pull request #863 from geoadmin/feat_PB-506_send_event_regardle…
Browse files Browse the repository at this point in the history
…ss_of_embed

PB-506 : send feature event regardless of embed mode
  • Loading branch information
pakb authored May 27, 2024
2 parents 7c5a603 + 0b79a0a commit 34ac7e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/store/modules/features.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { containsCoordinate } from 'ol/extent'
import EditableFeature, { EditableFeatureTypes } from '@/api/features/EditableFeature.class'
import { identify, identifyOnGeomAdminLayer } from '@/api/features/features.api'
import LayerFeature from '@/api/features/LayerFeature.class'
import { sendFeatureInformationToIFrameParent } from '@/api/iframeFeatureEvent.api'
import getProfile from '@/api/profile/profile.api'
import {
DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION,
Expand Down Expand Up @@ -222,6 +223,11 @@ export default {
layerFeatures.featureCountForMoreData =
layerFeatures.features.length % paginationSize === 0 ? paginationSize : 0
})

// as described by this example on our documentation : https://codepen.io/geoadmin/pen/yOBzqM?editors=0010
// our app should send a message (see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)
// when a feature is selected while embedded, so that the parent can get the selected feature(s) ID(s)
sendFeatureInformationToIFrameParent(layerFeatures)
}
commit('setSelectedFeatures', {
drawingFeatures,
Expand Down
11 changes: 1 addition & 10 deletions src/views/EmbedView.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script setup>
import { computed, onBeforeMount, onMounted, watch } from 'vue'
import { computed, onBeforeMount, onMounted } from 'vue'
import { useStore } from 'vuex'
import { sendFeatureInformationToIFrameParent } from '@/api/iframeFeatureEvent.api'
import I18nModule from '@/modules/i18n/I18nModule.vue'
import InfoboxModule from '@/modules/infobox/InfoboxModule.vue'
import MapFooter from '@/modules/map/components/footer/MapFooter.vue'
Expand All @@ -18,7 +17,6 @@ const dispatcher = { dispatcher: 'EmbedView.vue' }
const store = useStore()
const is3DActive = computed(() => store.state.cesium.active)
const selectedLayerFeatures = computed(() => store.getters.selectedLayerFeatures)
onBeforeMount(() => {
store.dispatch('setEmbed', { embed: true, ...dispatcher })
Expand All @@ -27,13 +25,6 @@ onBeforeMount(() => {
onMounted(() => {
log.info(`Embedded map view mounted`)
})
// as described by this example on our documentation : https://codepen.io/geoadmin/pen/yOBzqM?editors=0010
// our embed view should send a message (see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)
// when a feature is selected while in embedded mode, so that the parent can get the selected feature(s) ID(s)
watch(selectedLayerFeatures, () =>
sendFeatureInformationToIFrameParent(selectedLayerFeatures.value)
)
</script>

<template>
Expand Down

0 comments on commit 34ac7e1

Please sign in to comment.