@@ -157,7 +157,11 @@ export function processGeospatial(config, geospatial, index) {
157157 const { map, interactPlugin } = createMap ( mapId , initConfig , config )
158158 const featuresManager = getFeaturesManager ( geojson )
159159 const activeFeatureManager = getActiveFeatureManager ( )
160- const uiManager = getUIManager ( geojson , map , mapId , listEl , geospatialInput )
160+ const geometryTypes = geospatial . dataset . geometryTypes ?? 'point,line,shape'
161+ const options = {
162+ geometryTypes
163+ }
164+ const uiManager = getUIManager ( geojson , map , mapId , listEl , geospatialInput , options )
161165
162166 /**
163167 * @type {Context }
@@ -492,16 +496,32 @@ function getValueRenderer(geojson, geospatialInput) {
492496 * @param {string } mapId - the ID of the map
493497 * @param {HTMLDivElement } listEl - where to render the feature list
494498 * @param {HTMLTextAreaElement } geospatialInput - the geospatial textarea
499+ * @param {UIManagerOptions } options - extra options such as allowable geometry types
495500 */
496- function getUIManager ( geojson , map , mapId , listEl , geospatialInput ) {
501+ function getUIManager ( geojson , map , mapId , listEl , geospatialInput , options ) {
502+ /**
503+ * Get a CSV list of geometry types the user can create
504+ * @returns {string }
505+ */
506+ function getAllowableGeometryTypes ( ) {
507+ return options . geometryTypes ?? ''
508+ }
509+
497510 /**
498511 * Toggle the hidden state of the action buttons
499512 * @type {ToggleActionButtons }
500513 */
501514 function toggleActionButtons ( hidden ) {
502- map . toggleButtonState ( 'btnAddPoint' , 'hidden' , hidden )
503- map . toggleButtonState ( 'btnAddPolygon' , 'hidden' , hidden )
504- map . toggleButtonState ( 'btnAddLine' , 'hidden' , hidden )
515+ const types = getAllowableGeometryTypes ( )
516+ if ( types . includes ( 'point' ) ) {
517+ map . toggleButtonState ( 'btnAddPoint' , 'hidden' , hidden )
518+ }
519+ if ( types . includes ( 'shape' ) ) {
520+ map . toggleButtonState ( 'btnAddPolygon' , 'hidden' , hidden )
521+ }
522+ if ( types . includes ( 'line' ) ) {
523+ map . toggleButtonState ( 'btnAddLine' , 'hidden' , hidden )
524+ }
505525 }
506526
507527 /**
@@ -528,7 +548,8 @@ function getUIManager(geojson, map, mapId, listEl, geospatialInput) {
528548 renderValue,
529549 listEl,
530550 toggleActionButtons,
531- focusDescriptionInput
551+ focusDescriptionInput,
552+ getAllowableGeometryTypes
532553 }
533554}
534555
@@ -572,7 +593,7 @@ function createContainers(geospatialInput, index) {
572593function onMapReadyFactory ( context ) {
573594 const { map, activeFeatureManager, uiManager, interactPlugin, drawPlugin } =
574595 context
575- const { toggleActionButtons, renderList } = uiManager
596+ const { toggleActionButtons, renderList, getAllowableGeometryTypes } = uiManager
576597 const { resetActiveFeature } = activeFeatureManager
577598
578599 /**
@@ -584,50 +605,71 @@ function onMapReadyFactory(context) {
584605 // Add info panel
585606 map . addPanel ( 'info' , helpPanelConfig )
586607
587- map . addButton ( 'btnAddPoint' , {
588- variant : 'tertiary' ,
589- label : 'Add point' ,
590- iconSvgContent : POINT_SVG ,
591- onClick : ( ) => {
592- resetActiveFeature ( )
593- toggleActionButtons ( true )
594- renderList ( true )
595- interactPlugin . enable ( )
596- } ,
597- mobile : { slot : 'actions' } ,
598- tablet : { slot : 'actions' } ,
599- desktop : { slot : 'actions' }
600- } )
608+ const types = getAllowableGeometryTypes ( )
609+ const allowPoint = types . includes ( 'point' )
610+ const allowLine = types . includes ( 'line' )
611+ const allowShape = types . includes ( 'shape' )
601612
602- map . addButton ( 'btnAddPolygon' , {
603- variant : 'tertiary' ,
604- label : 'Add shape' ,
605- iconSvgContent : POLYGON_SVG ,
606- onClick : ( ) => {
607- resetActiveFeature ( )
608- toggleActionButtons ( true )
609- renderList ( true )
610- drawPlugin . newPolygon ( generateID ( ) , polygonFeatureProperties )
611- } ,
612- mobile : { slot : 'actions' } ,
613- tablet : { slot : 'actions' } ,
614- desktop : { slot : 'actions' }
615- } )
613+ // If only a single geometry type, don't show any buttons as will default to that geometry operation
614+ if ( types . split ( ',' ) . length === 1 ) {
615+ resetActiveFeature ( )
616+ toggleActionButtons ( true )
617+ renderList ( true )
618+ if ( allowPoint ) interactPlugin . enable ( )
619+ if ( allowLine ) drawPlugin . newLine ( generateID ( ) , lineFeatureProperties )
620+ if ( allowShape ) drawPlugin . newPolygon ( generateID ( ) , polygonFeatureProperties )
621+ } else {
622+ if ( allowPoint ) {
623+ map . addButton ( 'btnAddPoint' , {
624+ variant : 'tertiary' ,
625+ label : 'Add point' ,
626+ iconSvgContent : POINT_SVG ,
627+ onClick : ( ) => {
628+ resetActiveFeature ( )
629+ toggleActionButtons ( true )
630+ renderList ( true )
631+ interactPlugin . enable ( )
632+ } ,
633+ mobile : { slot : 'actions' } ,
634+ tablet : { slot : 'actions' } ,
635+ desktop : { slot : 'actions' }
636+ } )
637+ }
616638
617- map . addButton ( 'btnAddLine' , {
618- variant : 'tertiary' ,
619- label : 'Add line' ,
620- iconSvgContent : LINE_SVG ,
621- onClick : ( ) => {
622- resetActiveFeature ( )
623- toggleActionButtons ( true )
624- renderList ( true )
625- drawPlugin . newLine ( generateID ( ) , lineFeatureProperties )
626- } ,
627- mobile : { slot : 'actions' } ,
628- tablet : { slot : 'actions' } ,
629- desktop : { slot : 'actions' }
630- } )
639+ if ( allowShape ) {
640+ map . addButton ( 'btnAddPolygon' , {
641+ variant : 'tertiary' ,
642+ label : 'Add shape' ,
643+ iconSvgContent : POLYGON_SVG ,
644+ onClick : ( ) => {
645+ resetActiveFeature ( )
646+ toggleActionButtons ( true )
647+ renderList ( true )
648+ drawPlugin . newPolygon ( generateID ( ) , polygonFeatureProperties )
649+ } ,
650+ mobile : { slot : 'actions' } ,
651+ tablet : { slot : 'actions' } ,
652+ desktop : { slot : 'actions' }
653+ } )
654+ }
655+
656+ if ( allowLine ) {
657+ map . addButton ( 'btnAddLine' , {
658+ variant : 'tertiary' ,
659+ label : 'Add line' ,
660+ iconSvgContent : LINE_SVG ,
661+ onClick : ( ) => {
662+ resetActiveFeature ( )
663+ toggleActionButtons ( true )
664+ renderList ( true )
665+ drawPlugin . newLine ( generateID ( ) , lineFeatureProperties )
666+ } ,
667+ mobile : { slot : 'actions' } ,
668+ tablet : { slot : 'actions' } ,
669+ desktop : { slot : 'actions' }
670+ } )
671+ }
672+ }
631673
632674 // Set the map provider on the context
633675 context . mapProvider = e . map
@@ -1055,6 +1097,12 @@ function onListElKeydownFactory() {
10551097 * @returns {void }
10561098 */
10571099
1100+ /**
1101+ * Returns the list of geometry types a user can create
1102+ * @callback GetAllowableGeometryTypes
1103+ * @returns {string }
1104+ */
1105+
10581106/**
10591107 * Set focus to the last description input
10601108 * @callback FocusDescriptionInput
@@ -1084,6 +1132,7 @@ function onListElKeydownFactory() {
10841132 * @property {HTMLDivElement } listEl - the summary list of features
10851133 * @property {ToggleActionButtons } toggleActionButtons - function that toggles the action buttons
10861134 * @property {FocusDescriptionInput } focusDescriptionInput - function that sets focus to a description input element
1135+ * @property {GetAllowableGeometryTypes } getAllowableGeometryTypes - function that returns the list of geometry types a user can create
10871136 */
10881137
10891138/**
@@ -1098,5 +1147,5 @@ function onListElKeydownFactory() {
10981147 */
10991148
11001149/**
1101- * @import { MapLibreMap } from '~/src/client/javascripts/map.js'
1150+ * @import { MapLibreMap, UIManagerOptions } from '~/src/client/javascripts/map.js'
11021151 */
0 commit comments