Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request geometry from API #1282

Merged
merged 20 commits into from
Jun 6, 2024
Merged

Conversation

dbauszus-glx
Copy link
Member

@dbauszus-glx dbauszus-glx commented May 23, 2024

The aim of this PR is to allow the geometry entry to be extended by API calls.

Instead of copy and pasting most of the geometry entry script to create custom entry types for geometries which are requested from an API it should be possible to provide an entry.api method which will be called within the geometry entry show method if no value is available in the entry.show() method.

The entry.show() method must be async to allow for blocking api calls. The default is non-blocking.

It should be possible to provide edit controls to request geometries but also to use default and/or custom draw methods.

{
  "label": "GLX Catchment",
  "field": "isoline_h3",
  "fieldfx": "ST_asGeoJson(isoline_h3)",
  "type": "isoline_glx",
  "edit": {
    "draw": {
      "polygon": true
    }
  },
  "params": {
    "url": "XXXX",
    "api_key": "XXXXX"
  },
  "zIndex": 99,
  "style": {
    "strokeColor": "#0064B2",
    "strokeWidth": 2
  }
}

It should also be possible to modify geometries received from an API.

Any styling must only be applied by the geometry entry method.

For now geometries will always be stored as 'geojson' which will be turned to the native postgis geometry format in the location_update template.

However it should be possible to request and display other Openlayers supported formats. The new mapview.geometry() method supports any OL format. The mapview.geoJSON() method will set the geojson format before calling the geometry method.

The geometry created by the mapview.geometry() method should not be stored on the params object to prevent having to delete this object if the value updates.

The location_get method would not return a response if all fields are null. This has been resolved by concatenating the _.layer.qID with the fields array.

The geojson.js query template was bugged. Where IS NOT NULL is provided with the geom if now viewport is set.

The vector_layer entry method has been extended to apply theme styles and support API methods as well. However this work is incomplete and would too far extend of this PR. I have created a ticket to eventually merge the vector_layer and mvt_clone layer to support API calls, allow for the modification of geometries, and allow to draw new geometries. #1268

A render event was added to the location view element.

This allows for rendering the location view again without update.

location.view.addEventListener('render', ()=>renderLocationView(location))

location.view.addEventListener('updateInfo', () => {

    // Hides the upload icon.
    location.view.querySelector('.btn-save').style.display = 'none'

    // Location has toggle editing.
    if (location.editToggle) {

      location.editToggle.classList.remove('on')

      // Remove edits from infoj entries.
      location.removeEdits()
    }

    // Refresh dataviews
    if (location.layer?.dataviews) {
      Object.values(location.layer.dataviews).forEach(dv => {
        if (dv.display === true) {
          dv.update();
        }
      });
    }

    location.renderLocationView()
  })

function renderLocationView(location = this) {

  // Remove location.viewEntries.
  location.viewEntries.remove()

  // Enables the location view node and child elements.
  location.view.classList.remove('disabled')
  
  // Recreate location.viewEntries.
  location.viewEntries = location.view.appendChild(mapp.ui.locations.infoj(location))
}

@dbauszus-glx dbauszus-glx added Feature New feature requests or changes to the behaviour or look of existing application features. Code Issues related to the code structure and performance. Bug A genuine bug. There must be some form of error exception to work with. labels May 29, 2024
@dbauszus-glx dbauszus-glx marked this pull request as ready for review May 29, 2024 17:07
@dbauszus-glx dbauszus-glx linked an issue May 29, 2024 that may be closed by this pull request
@dbauszus-glx dbauszus-glx self-assigned this May 31, 2024
Copy link
Contributor

@RobAndrewHurst RobAndrewHurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Menu is shown for point geometry before the geometry is returned from the response.

Menu needs to appear only when the geometry from the request is returned!

@dbauszus-glx
Copy link
Member Author

The geometry edit method will no longer append the delete button if the field is the current layer geometry.

d2fc198

@dbauszus-glx
Copy link
Member Author

Menu is shown for point geometry before the geometry is returned from the response.

Menu needs to appear only when the geometry from the request is returned!

This issue is caused by starting the draw interaction without setting drawend: null.

@RobAndrewHurst
Copy link
Contributor

Nice thanks! @dbauszus-glx. Is there anything else that is outstanding on this?

@dbauszus-glx
Copy link
Member Author

Nice thanks! @dbauszus-glx. Is there anything else that is outstanding on this?

I am not aware of issues.

Copy link

sonarcloud bot commented Jun 6, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@dbauszus-glx dbauszus-glx merged commit cb4e2bd into GEOLYTIX:main Jun 6, 2024
4 checks passed
@dbauszus-glx dbauszus-glx deleted the api-geometry branch September 9, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A genuine bug. There must be some form of error exception to work with. Code Issues related to the code structure and performance. Feature New feature requests or changes to the behaviour or look of existing application features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

geometry entry from API
2 participants