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

Basic Map Integration Example #22

Closed
p-a-s-c-a-l opened this issue Sep 14, 2018 · 4 comments
Closed

Basic Map Integration Example #22

p-a-s-c-a-l opened this issue Sep 14, 2018 · 4 comments
Assignees
Labels
BB: Map Component Map Component Building Block BB: Scenario Transferability Scenario Transferability Building Block enhancement New feature or request

Comments

@p-a-s-c-a-l
Copy link
Member

Create a basic entity with country and study_area fields. Note: This basic entity will later be replaced by / integrated with the Study Group Type.

  • country field:
    • used to center the map shown in Mockup 0130 on a country selected by the user in in Mockup 0120
    • a reference to an entry in a countries vocabulary. Properties of the Country Taxonomy Type: name, country code, geom (type: Geofield), etc.
  • study_area field:
    • used for storing the spatial study area selected in Mockup 0130
    • a Geofield) attached to the Study Group Type) instance

Populate Countries Vocabulary (Taxonomy) with Couintry Data + Polygons, e.g. from #7 (comment)
Integrate React Map (e.g. Leaflet) via Module or iFrame (depending on the result of the evaluation).

Connect React Web App via Drupal REST API and / or JavaScript to Drupal Backend and implement the features for

  • setting and showing the polygon of the selected country on the react map
  • selecting the study area (bbox, polygon, etc.) in the react map and storing the geometry in the study_area field.

0120 cca _ study _ definition context end-user guide

0130 cca _ study _ area end-user guide

@p-a-s-c-a-l p-a-s-c-a-l added the enhancement New feature or request label Sep 14, 2018
@p-a-s-c-a-l p-a-s-c-a-l added this to the CSIS Bootstrapping milestone Sep 14, 2018
@therter
Copy link
Contributor

therter commented Oct 4, 2018

Add taxonomy terms via SQL:

As example, the taxonomy country with the two fields country and study_area was created.
When a shape file with the country data exists (e.g. from https://gadm.org/download_world.html), a import script can be created by the shp2pgsql command.

Example:

shp2pgsql -d -W UTF-8 shapefile table-name > ~/import-script.sql

This script can be executed with the psql command. After this, the data from the shape file is available in the specified database table. This data can be added to the drupal system with a pgsql script like the following script:

CREATE OR REPLACE FUNCTION public.import_countries()
    RETURNS boolean LANGUAGE 'plpgsql' COST 100 VOLATILE 
AS $BODY$
declare
        ref RECORD;
	tid integer;
begin
	--the imported data is contained within the table raw.countries
        for ref in select name, st_asText(the_geom) as the_geom from raw.countries  LOOP
		insert into taxonomy_term_data (vid, uuid, langcode)
		       values ('country', uuid_generate_v4(), 'en');
			
		select currval('taxonomy_term_data_tid_seq') into tid;

		insert into taxonomy_term_field_data (tid, vid, langcode, name, description__value, description__format, weight, changed, default_langcode)
		       values (tid, 'country', 'en', ref.name, null, null, 0, EXTRACT(EPOCH FROM now())::int, 1);

		insert into taxonomy_term__field_country (bundle, deleted, entity_id, revision_id, langcode, delta, field_country_value)
		       values ('country', 0, tid, tid, 'en', 0, ref.name);
                -- the following code also converts the postgis geometry to GeoJSON
		insert into taxonomy_term__field_study_area (bundle, deleted, entity_id, revision_id, langcode, delta, field_study_area_value)
		       values ('country', 0, tid, tid, 'en', 0, ST_AsGeoJSON(ref.the_geom));
        END LOOP;
		
	return true;
end
$BODY$;

@therter
Copy link
Contributor

therter commented Oct 22, 2018

A first gif of a map component that interacts with the drupal system:

anim

@clarity-h2020 clarity-h2020 deleted a comment from therter Oct 22, 2018
@clarity-h2020 clarity-h2020 deleted a comment from therter Oct 22, 2018
@therter
Copy link
Contributor

therter commented Oct 22, 2018

To allow the communication with the REST API, the RESTful Web Services module has to be activated (/admin/modules permission) and the permissions for the required resources should be set via the page /admin/config/services/rest.

restapi

Example to access the RestAPI from javascript code

    fetch('http://localhost:8080/taxonomy/term/93?_format=json')
    // see https://developer.mozilla.org/en-US/docs/Web/API/Body/json
    .then((resp) => resp.json())
    .then(function(data) {
        //do something
        //window.mapCom.setGeom(data.field_study_area[0].value);
    })
    .catch(function(error) {
      console.log(JSON.stringify(error));
    });         

This was referenced Oct 25, 2018
@p-a-s-c-a-l
Copy link
Member Author

done

@p-a-s-c-a-l p-a-s-c-a-l added the BB: Scenario Transferability Scenario Transferability Building Block label Jan 15, 2019
@p-a-s-c-a-l p-a-s-c-a-l added the BB: Map Component Map Component Building Block label Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BB: Map Component Map Component Building Block BB: Scenario Transferability Scenario Transferability Building Block enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants