JMap Cloud
English
English
  • Welcome to JMap Cloud documentation
  • JMap Cloud Portal
    • JMap Cloud Portal User Guide
      • Introduction
        • Accessing JMap Cloud Portal
        • User Interface
        • Dashboard
      • Roles
      • Functions Reserved for Administrators
        • Managing the Organization
          • General
          • API Keys
          • Members
          • Invitations
      • Connecting Data: Data Sources
        • Creating Data Sources
          • Vector/Raster Data Files
          • Non-spatial tabular data files
          • WMS/WMTS Service
          • Vector Tile Service
          • Feature Service
        • Status of a Data Source
        • Managing Data Sources
          • Displaying and editing information
          • Updating data
          • Permissions
          • Removing a spatial data source
        • Uploading Files
      • Organizing Data into Projects
        • Creating a New Project
        • Managing a Project
          • Open the Project
          • Editing a project
          • Permissions
          • Getting the project's public link
          • MVT Cache
          • Deleting the project
      • Configuring Project Content
      • Jobs
  • JMap NG
    • JMap NG User Guide
      • Introduction
        • Connecting to JMap NG
        • User Interface
        • Navigating on the Map
        • Profile and user settings
      • The Data
        • The Layers Panel
        • Data Layers
          • Displaying layers
          • Thematics
          • Layer Information
          • Geographic Extent of the Layer
          • Making layer elements selectable
      • I Wish to...
        • Display Element Information
        • Select Elements on the Map
        • Measure Distances and Surfaces
        • Add Annotations to the Map
        • Export / Print a Map
    • JMap NG Developer Documentation
      • Startup Options
      • Extensions
      • Examples
        • Start the JMap NG Core library
        • Start the JMap NG App
        • Add a JMap NG App extension
        • Toggle a JMap layer visibility
        • Add a layer to display custom data from GeoJSON file
        • Locate and select features by attribute query
        • Add an event on move end
        • Add attributions on the map
        • Locate and select feature by id
        • Locate and select feature(s) by location
        • Custom mouseover on a layer
        • Create a custom form in a div
      • Changelog
  • JMap Cloud API
    • JMap Cloud API Documentation
  • JMap Cloud Plugin for QGIS
    • JMap Cloud Plugin User Guide
      • Installing the plugin
      • Connecting to JMap Cloud
      • Opening a project
      • Editing features
      • Exporting a project
Propulsé par GitBook

K2 Geospatial 2023

Sur cette page
Exporter en PDF
  1. JMap NG
  2. JMap NG Developer Documentation
  3. Examples

Create a custom form in a div

PrécédentCustom mouseover on a layerSuivantChangelog

Dernière mise à jour il y a 11 mois

This example shows how to create a custom form. It instantiates a JMap NG App extension that creates a custom form in a panel.

Form UI is only available in JMap NG App, and not in JMap NG Core.

Example

Try it out in

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <meta charset="UTF-8">
    <style>
      #my-custom-app {
        position: relative;
        overflow: hidden;
        width: 850px;
        height: 700px;
        border: 1px solid grey;
      }
    </style>
  </head>
  <body>
    <div id="my-custom-app" class="jmap_wrapper"></div>
    <script type="text/javascript">
      window.JMAP_OPTIONS = {
        projectId: 1,
        restBaseUrl: "https://jmapdoc.jmaponline.net/services/rest/v2.0",
        anonymous: true,
        map: {
          zoom: 9.573700695830425,
          center: {
            x: -73.7219880403544,
            y: 45.53690235213574
          }
        },
        application: {
          containerId: "my-custom-app",
          panel: "test-form-panel",
          extensions: [{
            id: "test-form",
            panelTitle: "Test of form component API",
            initFn: () => {/* nothing to do */},
            onPanelCreation: panelContainerId => {
              document.getElementById(panelContainerId).style.padding = "1rem"
              JMap.Application.Form.render(panelContainerId, {
                id: "search-form",
                schema: {
                  properties: {
                    name: {
                      title: "Office Name",
                      type: "string",
                      isRequired: true,
                      maxLength: 255
                    },
                    type: {
                      title: "Office type",
                      type: "number",
                      // default: 2,
                      enum: [1, 2, 3],
                      enumNames: ["Local", "External", "Mixte"]
                    }
                  }
                },
                uiSchema: [
                  {
                    type: "Tab",
                    controls: [
                      {
                        id: "name",
                        label: "Office name",
                        widget: "input",
                        scope: "#/properties/name"
                      },
                      {
                        id: "type",
                        label: "Office type",
                        widget: "select",
                        scope: "#/properties/type"
                      }
                    ]
                  }
                ],
                defaultValueById: { // defaultValueById is optional
                  name: "default value",
                  type: 2
                },
                validate: (values, formMetaData) => JMap.Form.validateData(formMetaData, JMap.Form.getPreparedData(formMetaData, values)),
                onSubmit: values => {
                  // Here you process/persist the data. This function can:
                  //  - returns nothing: means onSubmit success
                  //  - returns a string: the string is an error that will be displayed
                  //  - returns a promise: the form will display a loading button until the promise resolved
                  JMap.Application.Message.info(`Submitted values: ${JSON.stringify(values)}`)
                }
              })
            },
            onPanelDestroy: panelContainerId => {
              JMap.Application.Form.destroyByContainerId(panelContainerId)
            }
          }]
        }
      };
    </script>
    <script defer type="text/javascript" src="https://cdn.jsdelivr.net/npm/jmap-app-js@7_Kathmandu_HF3"></script>  
  </body>
</html>
Codepen.io