Coder Social home page Coder Social logo

notum-cz / strapi-plugin-location Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 10.0 1.19 MB

This plugin allows users to create location inputs and store latitude and longitude values as geometry types in a PostGIS database. It also provides functionality to filter items based on their location.

License: MIT License

TypeScript 99.35% JavaScript 0.65%
location plugin strapi

strapi-plugin-location's People

Contributors

ballonek avatar dependabot[bot] avatar jannikzed avatar omikulcik avatar tiaxter avatar tilman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

strapi-plugin-location's Issues

GeoJSON format support

It would be rad if the location data would be stored in the database following GeoJSON specifications.

So for example in the JSONB data field, instead of the actual:
{ "lat": 45.512861, "lng": 9.209278 }

recording:
[ 9.209278, 45.512861 ]

would permit right away to have a proper GeoJSON Feature that could be leveraged by other plugins or applications and used to build GeoJSON Feature Collections for various frontends.

Location not working if data came from populated (need a help)

Bug report

Describe the bug

A clear and concise description of what the bug is.

Steps to reproduce the behavior

Nothing happened when requesting on :
http://localhost:1337/api/parkings?populate[address][fields][0]=coords&$location[address][coords]=23,14,3

{
   "data": [{
         ...,
       {
            "id": 3,
            ...,
            "address": {
                "id": 13,
                "coords": {
                    "lat": 48.947545,
                    "lng": 2.1423899
                }
            }
        },
  }]
}

Expected behavior

I configured everything correctly, it took me a while to migrate my MySQL database to Postgres using the PostGis Docker image but I have no proof that this mechanism works, I always get a 200 response whatever the coordinates I use. enter I don't have the impression that the data is correct but the data from relation address not working

Screenshots

If applicable, add screenshots to help explain your problem.

Code snippets

If applicable, add code samples to help explain your problem.

System

  • Node.js version: v16.20.2
  • NPM version: 9.8.1
  • Strapi version: 4.14.5
  • Database: PostGis
  • Operating system: MacOS, Linux, Docker

Additional context

plugin-version: "@notum-cz/strapi-plugin-location": "^1.1.4",
Add any other context about the problem here.

Error: Undefined attribute level operator 0

Issue Description

When making a request to the Strapi plugin with the $location[coords] parameter, I've observed an issue where if I set the radius to a value greater than 406, it results in an error: Error: Undefined attribute level operator 0. Upon further investigation, it seems that this error is related to a change in the data type of the variable when the array of IDs contains a large number of elements.

Steps to Reproduce

  1. Make a request with the following parameters: ?$location[coords]=40.848557,14.255131,406.
  2. Observe the error: Error: Undefined attribute level operator 0.

Expected Behavior

The plugin should handle requests with a radius greater than 406 without producing an error.

Additional Information

I noticed that when the array of IDs becomes large, the data type of the variable appears to change from an array of numbers to an array of objects. This transition in data types may be the root cause of the issue.

Environment

  • Node.js version: 18.16.1
  • Strapi version: 4.9.1
  • Plugin version: 1.1.4
  • Operating system: Ubuntu

Please let me know if you need any more information or if there are specific steps to reproduce the issue.

Screenshots

image

Crash on startup when not using postgres

Bug report

Describe the bug

When strapi is not using postgres, the server crashes on startup

Steps to reproduce the behavior

  1. Start a strapi instance without using postgres
  2. The info message is logged, but the server crashes

Expected behavior

The plugin should be disabled and the server should start without it

Additional context

I noticed you already have a check in there for plugin disabled, I believe it just needs to be added to a few more places.

invalid input syntax for type double precision: ""13.537340924817212""

Bug report

Describe the bug

After testing out your v1.2.0 I receive now the following error when trying to start:

error: 
          UPDATE cities
          SET ch_koordinate_geom = ST_SetSRID(ST_MakePoint(
              CAST((ch_koordinate::json->'lng')::text AS DOUBLE PRECISION),
              CAST((ch_koordinate::json->'lat')::text AS DOUBLE PRECISION)

          ), 4326)
          WHERE (ch_koordinate::json->'lng')::text != 'null' AND
                (ch_koordinate::json->'lat')::text != 'null'
           - invalid input syntax for type double precision: ""13.537340924817212""

Reverse geocoding

Feature request - Reverse geocoding

The plugin needs to incorporate a functionality where users can input an address, and it will automatically convert it into corresponding coordinates. This can be achieved through the utilization of the Google Maps API, which requires an API key. Developers will be given the choice to input this key into the configuration settings. Importantly, the plugin should gracefully handle situations where the API key is not provided, avoiding errors or any appearance of malfunction. In such cases, this specific feature should be smoothly disabled to prevent any dependency on Google features.

Cannot use a custom database schema name

Bug report

Describe the bug

Using Postgres 15.3, with a schema different from the default one (public), location fields cannot be created.

This error doesn't seem to happen when using the default public schema.

Steps to reproduce the behavior

  1. On your Postgres instance, create a new schema ( CREATE SCHEMA IF NOT EXISTS strapi;)
  2. Setup Strapi to use that schema.
  3. Add the strapi-plugin-location plugin to Strapi
  4. In the Content-Type builder, create a type with a location field
  5. apply changes

Expected behavior

Strapi restarts and the database is updated

Actual behavior

Strapi restart fails with the following error :

error: 
              ALTER TABLE user_profiles
              ADD COLUMN address_geopoint_geom GEOMETRY(Point, 4326);
             - relation "user_profiles" does not exist

Search not working in hyphenated content types

Bug report

Describe the bug

Search within radius or exact search is not working when the content type has hyphen in the api url.

Works for below content type
http://localhost:1338/api/samples?$location[samloc]=18.516726,73.856255,5000

Does not work when content type has hyphen in URL
http://localhost:1338/api/sam-locs?$location[samloc]=18.516726,73.856255,5000

Steps to reproduce the behavior

  1. Create collection with display name as camel case or spaced, which will create hyphenated API ID.
  2. Add custom location field
  3. Create few entries in newly created collection with lat and long entries few hundreds km apart
  4. Try to search on location field within 50m or exact search, it will return all entries

Expected behavior

Location search should work independent of the collection name format.

System

  • Node.js version: v18.17.0
  • NPM version: 9.6.7
  • Strapi version: 4.11.7
  • Database: Postgres SQL 14
  • Operating system: Windows 11

Additional context

"@notum-cz/strapi-plugin-location": "^1.0.1",
"@strapi/plugin-graphql": "^4.11.7",
"@strapi/plugin-i18n": "4.11.7",
"@strapi/plugin-users-permissions": "4.11.7",
"@strapi/strapi": "4.11.7",
"better-sqlite3": "8.0.1",
"pg": "^8.11.2",
"strapi-plugin-config-sync": "^1.1.2"

Errors in Plugin Build

Description:

When attempting to build the Strapi plugin "strapi-plugin-location" using the command npm run build, I encounter TypeScript errors that indicate 'strapi.db' is possibly undefined.

Environment:

  • Node.js version: Tried 16 and 19.
  • npm version: 9.2.0
  • TypeScript version: 5.2.2

Steps to Reproduce:

  1. Clone the repository.
  2. Install dependencies using npm install.
  3. Run the build command using npm run build.
  4. Observe the TypeScript errors.

Error Messages:
server/bootstrap.ts:13:14 - error TS18048: 'strapi.db' is possibly 'undefined'. const db = strapi.db.connection;

Troubleshooting Steps Taken:

  • I tried many ways to solve it by changing the node version and deleting the node_modules folder + package-lock.json everytime and run npm install but still the same issue.

image

Please let me know if you need any further assistance or have any specific details to add to the issue description.

GraphQL support

Feature request - GraphQL support

A GraphQL interface will be developed to grant access to the filtering and searching API.

Crash on startup with PostGIS enabled PostgreSQL 14

Bug report

Describe the bug

When PostGIS is already enabled on server, Strapi crashes on startup in developing environment (not tested in production).
This happens after enabling the plugin and adding the custom field to a collection, Strapi could not start and logs show the following:

[2023-08-08 18:57:53.332] info: Error Enabling PostGIS, create extension postgis; - extension "postgis" already exists
[2023-08-08 18:57:53.351] error: Error accessing POSTGIS
Error: Could not find Custom Field: plugin::location-plugin.location

On the server side, the Postgres logs show:

2023-08-08 17:22:32.530 UTC [476909] strapi@develop_strapi ERROR:  function postgis_version() does not exist at character 8
2023-08-08 17:22:32.530 UTC [476909] strapi@develop_strapi HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
2023-08-08 17:22:32.530 UTC [476909] strapi@develop_strapi STATEMENT:  SELECT PostGIS_version();
2023-08-08 17:22:32.547 UTC [476909] strapi@develop_strapi ERROR:  extension "postgis" already exists
2023-08-08 17:22:32.547 UTC [476909] strapi@develop_strapi STATEMENT:  create extension postgis;
2023-08-08 17:22:32.566 UTC [476909] strapi@develop_strapi ERROR:  function postgis_version() does not exist at character 8
2023-08-08 17:22:32.566 UTC [476909] strapi@develop_strapir HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
2023-08-08 17:22:32.566 UTC [476909] strapi@develop_strapir STATEMENT:  SELECT PostGIS_version();
2023-08-08 17:22:32.748 UTC [476909] strapi@develop_strapi LOG:  could not receive data from client: Connection reset by peer

Steps to reproduce the behavior

  1. Install the strapi-plugin-location following documentation
  2. Execute npm install && npm run build && npm run develop
  3. Access the Strapi dashboard and add the custom field provided by the plugin to a collection, Strapi restarts
  4. See error

Expected behavior

Strapi should restart properly.

System

  • Node.js version: v18.17.0
  • NPM version: v9.6.7
  • Strapi version: v4.12.1
  • Database: PostgreSQL 14.8 (Ubuntu 14.8-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu
  • PostGIS version: v3.2.0
  • Operating system: Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-78-generic x86_64)

Additional context

PostGIS has its own 'postgis' scheme enabled on the db, Strapi uses the 'public' scheme. The 'search_path' on the database is configured with 'public, postgis' values.

Running the command 'SELECT postgis_full_version();' on the database properly returns PostGIS version:
POSTGIS="3.2.0 c3e3cc0" [EXTENSION] PGSQL="140" GEOS="3.10.2-CAPI-1.16.0" PROJ="8.2.1" LIBXML="2.9.12" LIBJSON="0.15" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)"

column "XXX_geom" of relation "XXX" does not exist

Bug report

Describe the bug

We are having some issues using your plugin. When trying to start for a large database, that has already several 100k entries, I'm running into this issue and I don't know, how to solve it - I can't see the column "XXX_geom" anywhere, so I was wondering, how exactly the plugin works.

error: 
          UPDATE pois
          SET ch_geo_points_geom = ST_SetSRID(ST_MakePoint(
              CAST((ch_geo_points::json->'lng')::text AS DOUBLE PRECISION),
              CAST((ch_geo_points::json->'lat')::text AS DOUBLE PRECISION)

          ), 4326)
          WHERE (ch_geo_points::json->'lng')::text != 'null' AND
                (ch_geo_points::json->'lat')::text != 'null'
           - column "ch_geo_points_geom" of relation "pois" does not exist
           - 

A clear and concise description of what the bug is.

Steps to reproduce the behavior

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Code snippets

If applicable, add code samples to help explain your problem.

System

  • Node.js version:
  • NPM version:
  • Strapi version:
  • Database:
  • Operating system:

Additional context

Add any other context about the problem here.

Search not working in components

Although the geo fields are getting created in the tables for components with location custom field, none of the below approaches are able to search if the location field is inside the component. Below is the sample that I tried to pass as parameter. address is the component name and loc is location custom field.

$location[address][loc]
$location[address.loc]

'All changes made will be lost' warning upon exiting unedited collection item

Bug report

Describe the bug

When exiting an item that features the plugin custom fields, the user is warned about data loss and forced to click 'Save', even if nothing was updated.

Steps to reproduce the behavior

  1. In the Content Manager go to a collection where you use the lat/lon custom field
  2. Click on a collection item an open it
  3. Do not edit anything
  4. Click the Back link at the top of the page
  5. See error

Expected behavior

Normally going back to the items list of the collection as no content was updated.

Bug: Does not work with fields containing capital letters

Bug report

Describe the bug

Strapi crashes when a custom location fields name is containing capital letters.

How to fix:

  1. Go to src/api/content-types/[your content type]/schema.json
  2. Change the field name to all lower case
  3. The app should now start without any problems

Steps to reproduce the behavior

  1. Go to Content-types-builder
  2. Create a content-type with the custom location field and use capital letters in its name.
  3. Click save and the app crashes

Expected behavior

The field should be created without crashing the application.

Screenshots

image

System

  • Node.js version: 17.9.1
  • NPM version: 8.11.0
  • Strapi version: 4.11.5.
  • Database: Postgres + Postgis
  • Operating system: MacOS 13.4

Geolocation shape field

Feature request - Geolocation shape field

The plugin's functionality should be expanded to enable users to utilize not only a field for specifying single location coordinates, but also a field for defining location shapes (areas) composed of multiple location points.

Support mysql

Hi, I'd like to use this plugin, but I can't because my project uses a MySQL database. I guess more people are in a similar situation,

Map tiles do not load due to Content Security Policy

Bug report

Describe the bug

When trying to view the map the OpenStreetMap tiles do not load due to being blocked by strapi's default Content Security Policy.

Steps to reproduce the behavior

  1. Click on "Map" button below coordinates
  2. The map shows only a grey background, no tiles

Expected behavior

Tiles are shown

Screenshots

N/A

Code snippets

The config/middlewares.ts needs to be adjusted to allow the browser to load the tiles from an external source. This configuration works for me:

export default [
  "strapi::errors",
  {
    name: "strapi::security",
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "connect-src": ["'self'", "https:"],
          "img-src": [
            "'self'",
            "data:",
            "blob:",
            "https://market-assets.strapi.io",
            "https://tile.openstreetmap.org",
            "https://a.tile.openstreetmap.org",
            "https://b.tile.openstreetmap.org",
            "https://c.tile.openstreetmap.org",
          ],
          "media-src": ["'self'", "data:", "blob:"],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  "strapi::cors",
  "strapi::poweredBy",
  "strapi::logger",
  "strapi::query",
  "strapi::body",
  "strapi::session",
  "strapi::favicon",
  "strapi::public",
];

System

  • Node.js version: 18.17.1
  • NPM version: 9.6.7
  • Strapi version: 4.13.7
  • Database: PostgreSQL 16 - PostGIS 3.4
  • Operating system: Fedora 38

Additional context

N/A

Cannot edit location field when embedded in a Component

Bug report

Describe the bug

When a component embeds a plugin::location-plugin.location field, its value cannot be set.

This is the logged error :

error: 
        UPDATE components_address_adresses
        SET geopoint_geom = ST_SetSRID(ST_MakePoint(-0.5870622786552258, 44.78683011143263), 4326)
        WHERE id = 1;
    - column "geopoint_geom" of relation "components_address_adresses" does not exist

Steps to reproduce the behavior

  1. In the content type builder, create a component (named address)
  2. Add a custom location field in the component
  3. In the content type builder, create a new collection type (named user-profile)
  4. Add an address component field to user-profile
  5. In the content editor, create a new user-profile, and fill its address field.
  6. Hit save button

Expected behavior

The user profile is created.

Actual behavior

Save fails with the following error

error: 
        UPDATE components_address_adresses
        SET geopoint_geom = ST_SetSRID(ST_MakePoint(-0.5870622786552258, 44.78683011143263), 4326)
        WHERE id = 1;
    - column "geopoint_geom" of relation "components_address_adresses" does not exist

No able to see the location custom type

Bug report

Hi,

Thanks for your work !

Describe the bug

After installing the plugin :
image

image

It seems to be well installed, but i can't see any location custom type in the content manager :

image

Steps to reproduce the behavior

  1. Generate new empty strapi project on PostgreSQL with PostGIS installed
  2. Add the plugin

image

  1. I'm not able to use the custom type
    image

Expected behavior

be able to use the custom type

System

  • Node.js version: v16.18.1
  • NPM version: 8.19.2
  • Strapi version: 4.12.4
  • Database: postgreSQL
  • Operating system: Windows 10
  • Location Plugin : 1.0.2

Additional context

I also try to modify the json directly by adding the custom type on a field named location but the create page was loading indefinitely
and i can't see the content manager which showed a blank page.

I'm ok to check the code, if you can tell me where i must take a look to eventually fix it (i already put a lot of console.log in the node_module)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.