Skip to content

Commit

Permalink
Merge pull request #18 from camptocamp/example6-html
Browse files Browse the repository at this point in the history
Turn custom elements example into HTML
  • Loading branch information
jahow authored Oct 28, 2024
2 parents a5dfb83 + c64c065 commit 63deafc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
24 changes: 19 additions & 5 deletions apps/examples/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@ 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 ExampleCustomElements from '@/examples/Example-CustomElements.vue'
import ExampleCustomElementsRaw from '@/examples/Example-CustomElements.vue?raw'
import { onMounted } from 'vue'
import ExampleCustomElementsHtml from '@/examples/Example-CustomElements.html?raw'
import { onMounted, ref } from 'vue'
import hljs from 'highlight.js'
import '@geospatial-sdk/elements'
function loadHtmlExample(html: string, root: HTMLElement) {
const template = document.createElement('template')
template.innerHTML = html
const geosdkMap = template.content.querySelector('geosdk-map')!
const geosdkScript = template.content.querySelector('script')!
const script = document.createElement('script')
script.type = 'text/javascript'
script.textContent = geosdkScript.textContent
root.appendChild(geosdkMap)
root.appendChild(script)
}
const example06_root = ref<HTMLElement>()
onMounted(() => {
loadHtmlExample(ExampleCustomElementsHtml as string, example06_root.value!)
hljs.highlightAll()
})
</script>
Expand Down Expand Up @@ -67,9 +81,9 @@ onMounted(() => {
<ExampleContainer
example-name="Example 6: show a map using a custom element"
example-id="example06"
:source-code="ExampleCustomElementsRaw"
:source-code="ExampleCustomElementsHtml"
>
<ExampleCustomElements></ExampleCustomElements>
<div class="w-full h-full" ref="example06_root"></div>
</ExampleContainer>
</div>
</template>
Expand Down
18 changes: 18 additions & 0 deletions apps/examples/src/examples/Example-CustomElements.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<geosdk-map id="map"></geosdk-map>

<script type="text/javascript">
const geosdkMap = document.getElementById('map')
geosdkMap.context = {
layers: [
{
type: 'maplibre-style',
styleUrl:
'https://data.geopf.fr/annexes/ressources/vectorTiles/styles/PLAN.IGN/standard.json'
}
],
view: {
zoom: 12,
center: [2.33, 48.86]
}
}
</script>
27 changes: 0 additions & 27 deletions apps/examples/src/examples/Example-CustomElements.vue

This file was deleted.

0 comments on commit 63deafc

Please sign in to comment.