Skip to content

Instantly share code, notes, and snippets.

@AlanJenkinsVS
Created April 16, 2018 16:11
Show Gist options
  • Save AlanJenkinsVS/2099ea6f1e4ba034f6d902224d05750c to your computer and use it in GitHub Desktop.
Save AlanJenkinsVS/2099ea6f1e4ba034f6d902224d05750c to your computer and use it in GitHub Desktop.
7. Rendering non-HTML - Vue JS Optimisation
const map = new mapboxgl.Map(/* ... */);
map.on('load', () => {
// Data
map.addSource(/* ... */);
// Layers
map.addLayer(/* ... */);
map.addLayer(/* ... */);
// Hover Effects
map.on('mousemove', /* ... */);
map.on('mouseleave', /* ... */);
});
<MapboxMap>
<MapboxMapMarkers :items="cities" primary>
<template slot-scope="city">
<h3>{{ city.name }}</h3>
</template>
</MapboxMapMarkers>
</MapboxNavigation/>
</MapboxMap>
<script>
// Abstract component
...
created () {
const { map } = this.$parent;
map.on('load', () => {
map.addSource(/* ... */);
map.addLayer(/* ... */);
});
},
beforeDestroy () {
const { map } = this.$parent;
map.on('load', () => {
map.removeSource(/* ... */);
map.removeLayer(/* ... */);
});
},
render(h) {
// returns nothing
return null;
}
...
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment