Skip to content

Commit

Permalink
wip: Support new map styling #816
Browse files Browse the repository at this point in the history
  • Loading branch information
cnouguier committed Feb 9, 2024
1 parent 4f9e0f1 commit ea9de3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 10 additions & 8 deletions map/client/mixins/map/mixin.geojson-layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GradientPath } from '../../leaflet/GradientPath.js'
import { MaskLayer } from '../../leaflet/MaskLayer.js'
import { TiledFeatureLayer } from '../../leaflet/TiledFeatureLayer.js'
import {
fetchGeoJson, LeafletEvents, bindLeafletEvents, unbindLeafletEvents, getFeatureId, isInMemoryLayer,
fetchGeoJson, LeafletEvents, bindLeafletEvents, unbindLeafletEvents, getFeatureId, isInMemoryLayer, getFeatureStyleType,
convertSimpleStyleToPointStyle, convertSimpleStyleToLineStyle, convertSimpleStyleToPolygonStyle, createMarkerFromPointStyle
} from '../../utils.map.js'
import * as wfs from '../../../common/wfs-utils.js'
Expand Down Expand Up @@ -400,17 +400,19 @@ export const geojsonLayers = {
bindLeafletEvents(layer, LeafletEvents.Feature, this, options)
},
style: (feature) => {
if (['LineString', 'MultiLineString'].includes(feature.geometry.type)) {
return this.generateStyle('line', feature, options, _.get(this, 'activityOptions.engine'))
}
if (['Polygon', 'MultiPolygon'].includes(feature.geometry.type)) {
return this.generateStyle('polygon', feature, options, _.get(this, 'activityOptions.engine'))
} else {
logger.warn(`[KDK] the geometry of type of ${feature.geometry.type} is not supported`)
const styleType = getFeatureStyleType(feature)
if (!styleType) {
logger.warn(`[KDK] cannot get a style type from the feature of geometry type ${feature.geometry.type}`)
return
}
return this.generateStyle(styleType, feature, options, _.get(this, 'activityOptions.engine'))
},
pointToLayer: (feature, latlng) => {
const style = this.generateStyle('point', feature, options, _.get(this, 'activityOptions.engine'))
if (!style) {
logger.warn('[KDK] cannot generate point style from a feature')
return
}
return createMarkerFromPointStyle(latlng, style)
}
}
Expand Down
14 changes: 14 additions & 0 deletions map/client/utils/utils.features.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash'
import logger from 'loglevel'
import moment from 'moment'
import { getType } from '@turf/invariant'
import explode from '@turf/explode'
Expand Down Expand Up @@ -361,3 +362,16 @@ export async function fetchGeoJson (dataSource, options = {}) {
}
return data
}

export function getFeatureStyleType (feature) {
const geometryType = _.get(feature, 'geometry.type')
if (!geometryType) {
logger.warn('[KDK] feature has undefined geometry')
return
}
if (geometryType === 'Point') return 'point'
if (['LineString', 'MultiLineString'].includes(geometryType)) return 'line'
if (['Polygon', 'MultiPolygon'].includes(geometryType)) return 'polygon'
logger.warn(`[KDK] unsupported geometry of type of ${geometryType}`)
return
}

0 comments on commit ea9de3d

Please sign in to comment.