GEOLYTIX / xyz

An open source javascript framework for spatial data and application interfaces.
MIT License
87 stars 25 forks source link

Request geometry from API #1282

Closed dbauszus-glx closed 3 months ago

dbauszus-glx commented 4 months ago

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 locationget 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. https://github.com/GEOLYTIX/xyz/issues/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 commented 3 months ago

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

https://github.com/GEOLYTIX/xyz/pull/1282/commits/d2fc198c3ac3f96ccf20227835eb7ff80c684b85

dbauszus-glx commented 3 months ago

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 commented 3 months ago

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

dbauszus-glx commented 3 months ago

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

I am not aware of issues.

sonarcloud[bot] commented 3 months ago

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