Skip to content

Commit

Permalink
Add clusters type
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpereira committed Sep 19, 2023
1 parent bb6ef83 commit 3938e11
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/components/Map/VMap.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ const props = defineProps({
maxClusterRadius: {
type: Number,
default: 20
},
clusterIconCreateFunction: {
type: Function,
default: undefined
}
})
Expand Down Expand Up @@ -155,6 +160,22 @@ watch(
}
)
function makeClusterOptions() {
const opt = {
maxClusterRadius: props.maxClusterRadius
}
if (props.clusterIconCreateFunction) {
Object.assign(opt, {
iconCreateFunction: (cluster) => {
return props.clusterIconCreateFunction({ L, cluster })
}
})
}
return opt
}
onMounted(() => {
const tiles = makeTileFromConfiguration(L, {
maxZoom: props.maxZoom,
Expand Down Expand Up @@ -184,7 +205,7 @@ onMounted(() => {
drawnItems = new L.FeatureGroup()
geoJSONGroup = props.cluster
? new L.markerClusterGroup({ maxClusterRadius: props.maxClusterRadius })
? new L.markerClusterGroup(makeClusterOptions())
: new L.FeatureGroup()
mapObject = L.map(leafletMap.value, options)
Expand Down
6 changes: 4 additions & 2 deletions src/modules/otus/components/Panel/PanelMap/PanelMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
cluster
:zoom="zoom"
:geojson="store.distribution.geojson"
:cluster-icon-create-function="makeClusterIconFor"
@geojson:ready="() => (isLoading = false)"
/>

Expand Down Expand Up @@ -61,8 +62,9 @@
<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { useDistributionStore } from '@/modules/otus/store/useDistributionStore.js'
import CachedMap from './CachedMap.vue'
import OtuSearch from '../../Search/OtuSearch.vue'
import { makeClusterIconFor } from './clusters/makeClusterIconFor'
import CachedMap from './components/CachedMap.vue'
import OtuSearch from './components/Search/OtuSearch.vue'
const props = defineProps({
otuId: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function CollectionObject(cluster) {
return {
html: `<div class="bg-map-collection-object"><span>${cluster.getChildCount()}</span></div>`,
className:
'leaflet-marker-icon leaflet-zoom-animated leaflet-interactive bg-map-collection-object bg-opacity-60 marker-cluster text-white',
iconSize: [40, 40]
}
}
18 changes: 18 additions & 0 deletions src/modules/otus/components/Panel/PanelMap/clusters/Mixed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function Mixed(cluster) {
return {
html: `
<div class="relative flex w-[40px] h-[40px]">
<div class="rounded-l-full bg-map-collection-object bg-opacity-60">
<div class="w-[15px] h-[30px] rounded-l-full bg-map-collection-object ml-[5px] mt-[5px]"></div>
</div>
<div class="rounded-r-full bg-map-type-material bg-opacity-60">
<div class="w-[15px] h-[30px] rounded-r-full bg-map-type-material mr-[5px] mt-[5px]"></div>
</div>
<span class="absolute text-xs top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-white">
${cluster.getChildCount()}
</span>
</div>`,
className: 'leaflet-marker-icon leaflet-zoom-animated leaflet-interactive',
iconSize: [40, 40]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function TypeMaterial(cluster) {
return {
html: `<div class="bg-map-type-material"><span>${cluster.getChildCount()}</span></div>`,
className:
'leaflet-marker-icon leaflet-zoom-animated leaflet-interactive marker-cluster bg-map-type-material bg-opacity-60 text-white',
iconSize: [40, 40]
}
}
3 changes: 3 additions & 0 deletions src/modules/otus/components/Panel/PanelMap/clusters/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './CollectionObject'
export * from './Mixed'
export * from './TypeMaterial'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as ClusterType from '../clusters'

export function makeClusterIconFor({ L, cluster }) {
const items = cluster
.getAllChildMarkers()
.map((item) => item.feature.properties.base.map((i) => i.type))
.flat()

const types = [...new Set(items)]
const currentType = types.pop()

const makeClusterOptions = types.length
? ClusterType.Mixed
: ClusterType[currentType] || ClusterType.CollectionObject

return L.divIcon(makeClusterOptions(cluster))
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<script setup>
import { computed, ref, onMounted, onUnmounted } from 'vue'
import TaxonWorks from '../../services/TaxonWorks'
import TaxonWorks from '../../../../../services/TaxonWorks.js'
import SearchBar from './SearchBar.vue'
import ListResults from './ListResults.vue'
Expand Down

0 comments on commit 3938e11

Please sign in to comment.