Form element "Maps2PoiPosition" for the form framework
New in version 13.3.0
maps2 provides the form element Maps2Poi for forms based on
the TYPO3 form framework (EXT:form).
The form element Maps2Poi shows a map with a draggable marker in
a frontend form. Frontend users can correct a position, for example the
position, which was found by geocoding the address they have entered on a
previous page of the form. Dragging the marker or clicking into the map
moves the marker and updates the position.
This chapter describes, how integrators add the element to a form definition and configure it. The chapter Integrate the form element "Maps2PoiPosition" in code describes the value of the element and how an extension geocodes an address and stores the position.
When to use the form element "Maps2PoiPosition"
Use the element, if frontend users create or edit records with an address and the position on the map matters, for example companies, locations or events. A geocoded position is not always exact: new buildings, large premises or ambiguous addresses result in a marker at the wrong place. With the element the user moves the marker to the correct place before the form is submitted.
The element does not geocode an address and does not store anything. Your extension sets the initial position and stores the submitted position. See Integrate the form element "Maps2PoiPosition" step by step.
Requirements for the form element "Maps2PoiPosition"
- The system extension EXT:form (
typo3/) is installed.cms- form - The site set Maps2 - Google Maps (
jweiland/) or Maps2 - OpenStreetMap (maps2- googlemaps jweiland/) is included in the site. They provide the settings of the map, for example the API key and the map ID of Google Maps or the tile server of OpenStreetMap. Both depend on Maps2 - Default Set (maps2- openstreetmap jweiland/).maps2- default
The form element itself needs no registration. maps2 ships the form set
jweiland/ in EXT:. EXT:form
discovers it automatically, as soon as maps2 is installed. The form set has
the priority 50: it is loaded after the base configuration of EXT:form
(priority 10) and before form sets with the default priority 100, so
the form sets of your site package can override it.
To disable the form set, add its name to the disabled form sets of EXT:form:
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['form']['disabledSets'][] = 'jweiland/maps2';
If your extension ships a site set with a form, which uses the element, add one of the site sets of maps2 to the dependencies of your site set:
name: my-vendor/my-extension
label: 'My extension'
dependencies:
- typo3/form
- jweiland/maps2-openstreetmap
Add the form element "Maps2PoiPosition" to a form definition
Add an element of type Maps2Poi to the form definition (YAML
file). Add the validator Not, if the user has to place the marker:
renderables:
- type: Page
identifier: page-map
label: 'Position on the map'
renderables:
- type: Maps2PoiPosition
identifier: position
label: 'Position on the map'
properties:
markerTitle: 'Your company'
zoom: 15
height: 400
elementDescription: 'Move the marker, if the position is not correct.'
validators:
- identifier: NotEmpty
The element works without an initial position, too. Then the marker is
shown at the default position of the
extension settings (default and
default) and the user has to place it. As long as the marker was
not placed, the element has no value and Not fails.
maps2 adds its own validator Maps2Poi to each element
automatically. See Validation of the form element "Maps2PoiPosition".
Properties of the form element "Maps2PoiPosition"
Set these properties below properties of the element. Common properties
of form elements like element work as usual. maps2 ignores
properties it does not know, so your extension can add properties of its
own.
| Name | Type | Default |
|---|---|---|
| string | (empty) | |
| int | 15 | |
| int|string | 400 | |
| string | (empty) | |
| string | https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png | |
| string | © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors |
-
- Type
- string
- Default
- (empty)
The map provider of the map:
gm(Google Maps) orosm(OpenStreetMap).The property is respected only, if the extension setting
mapisProvider both. Else the map provider of the extension settings is used. An empty or invalid value uses the extension settingdefault. See Extension Settings.Map Provider
-
- Type
- int
- Default
- 15
The zoom level of the map, from
0to20. Other values use the default15. The TypoScript settingplugin.is not used for this element.tx_ maps2. settings. zoom
-
- Type
- int|string
- Default
- 400
The height of the map. Use a number (pixels) or a number with one of the units
px,em,rem,vhor%, for example300,25remor50vh. Invalid values use the default400.The width of the map is always
100%of the surrounding element.
-
- Type
- string
- Default
- (empty)
The title of the marker, which is shown as tooltip on mouse over.
-
- Type
- string
- Default
- https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
The tile server of OpenStreetMap, which is used, if the TypoScript setting
plugin.is empty, for example because the site set "Maps2 - OpenStreetMap" is not included.tx_ maps2. settings. map Tile
-
- Type
- string
- Default
- © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors
The attribution of defaultMapTile.
The default values of all properties are defined in the form set of
maps2 (EXT:, below
prototypes.).
Change them in a form set of your site package for all elements or in the
form definition for a single element.
Map settings of the form element "Maps2PoiPosition"
The element uses the following TypoScript settings of
plugin.. map, map,
google and google are set by the site
settings of the site sets of maps2:
mapandTile map: the tile server of OpenStreetMap and its attribution. Without a tile server, the propertiesTile Attribution defaultandMap Tile defaultof the element are used.Map Tile Attribution google: the API key for Google Maps. Without this setting, the API key of the extension settings is used.Maps Java Script Api Key google: the map ID of Google Maps, which the draggable advanced marker requires. Without this setting, the map ID of the extension settings is used.Maps Map Id map,Type Id zoom,Control map,Type Control scale,Control street,View Control full,Screen Control activateandScroll Wheel styles: the same settings as for the maps of the maps2 plugins.
See TypoScript.
Consent for requests to the map provider
If the extension setting explicit is enabled and
the user has not agreed to requests to the map provider yet, the element
shows the same information as the maps2 plugins and a button to show the
map instead of the map.
The button submits the form to the current page of the form again and adds
the parameter tx_ to the
URI. The form state and all entered values are kept and the user stays on
the same page of the form.
The button disables the validation of the browser only. EXT:form validates
the submitted page as usual. So the user may see error messages after the
consent, for example of the validator Not, if there is no initial
position yet, or of other required fields on the same page.
Tip
Put the element on a page of its own and set an initial position (see Integrate the form element "Maps2PoiPosition" step by step). Then the page is valid already, when it is shown for the first time.
The JavaScript and style sheets of the map provider are loaded only after the consent and only on pages of the form, which contain the element. See JavaScript and style sheets of the map.
JavaScript and style sheets of the map
The partial Maps2Poi of the form element loads the
JavaScript and the style sheets of the map provider with the ViewHelpers
f: and f:. It is rendered by the partial
Maps2Poi, if requests to the map provider are allowed. The
assets are added with csp="1", so TYPO3 adds them to the Content
Security Policy of the page.
The partial gets these arguments:
mapProvider - The map provider of the element:
gmorosm. googleMaps Java Script Api Key - The TypoScript setting
plugin.or, if empty, the extension settingtx_ maps2. settings. google Maps Java Script Api Key google.Maps Java Script Api Key
The asset identifiers are the same as in the partial Load of the
maps2 plugins (maps2-, maps2-, maps2-,
maps2-). So the assets are loaded only once, if a maps2
plugin is on the same page.
To load the assets from other locations, for example a Leaflet version of your own or a CDN, copy the partial to your site package:
EXT:my_sitepackage/Resources/Private/Form/Partials/Maps2PoiPosition/LoadAssets.fluid.html
Register the partial root path with a key higher than 15 in a form set of
your site package:
name: my-vendor/site-package
label: 'Site package'
prototypes:
standard:
formElementsDefinition:
Form:
renderingOptions:
partialRootPaths:
100: 'EXT:my_sitepackage/Resources/Private/Form/Partials/'
Or register it for a single form in its form definition:
renderingOptions:
partialRootPaths:
100: 'EXT:my_sitepackage/Resources/Private/Form/Partials/'
The same way you can override the partials Maps2Poi,
Maps2Poi and Maps2Poi.
Summary page and emails
maps2 overrides the partial Summary of EXT:form and shows the
position as text, for example:
Latitude: 48.663012, Longitude: 9.218945
The override is registered in the form set of maps2 with the
partial key 15. The site setting
form. of EXT:form uses the key 20 and wins.
The email templates of the email finishers of EXT:form are not overridden. They render the value like the value of other elements with multiple values: as list with the latitude and the longitude without labels.
Styling of the form element "Maps2PoiPosition"
The map and the consent information are wrapped in a div with the CSS
class maps2-. If the validation fails, the error class of the
form (field) is added to this div. The
surrounding container has the classes
form-.
Limitations of the form element "Maps2PoiPosition"
- The element is not available in the backend form editor
- The form editor does not offer the element. Add the element to form definitions, which your extension or site package ships as YAML files.
- An own SummaryPage partial with a higher key wins
-
If your site package overrides
Summarywith a higherPage. fluid. html partialkey than maps2 (for example with the site settingRoot Paths form.), the position is shown as list again. Add a branch for the element type to your partial:templates. partial Root Path EXT:my_sitepackage/Resources/Private/Form/Partials/SummaryPage.fluid.html<f:else if="{0: formValue.element.type} == {0: 'Maps2PoiPosition'}"> <f:render partial="Maps2PoiPosition/SummaryValue" arguments="{position: formValue.value}"/> </f:else>Copied!The partial
Maps2Poiis found as long as the partial root path of maps2 (keyPosition/ Summary Value 15) is registered. - No geocoding and no storage
- The element shows and returns a position only. Geocoding an address and storing the position in a record are the job of your extension. See Integrate the form element "Maps2PoiPosition" step by step.