Plesk / Docker / farmOS

Hi.
My Co. is managing a website for a client. He has installed farmOS via Docker using a Plesk dashboard.
We’re not particularly familiar with any of these tools, but we need to achieve two things in the very near future:

  1. connect to our own Mapbox content (we need to override the satellite imagery with the client’s AutoCAD drawings).
  2. Add custom module(s) to simplify data entry of Log info (simple, land/function, eg. Spray Vineyard, default everything else, is where we need to get to)

We have created our Mapbox image, and installed the API key, but nothing changes. So, I’m wondering if there are other settings somewhere we have to enable.

All instructions re. modules eventually (after long rabbit holes ) involve CLI instructions. With Plesk we do not have access to a CLI interpreter (at least not that I’ve found) so I need another solution.

I’m willing to pay for a solution - or instructions on how to get from point A. (vanilla farmOS) to B. achieving a custom module, which we can then add code to a redeploy.

Thanks.

1 Like

Hi @nzsnowman

connect to our own Mapbox content (we need to override the satellite imagery with the client’s AutoCAD drawings).

farmOS comes with a very basic Mapbox module that adds two of Mapbox’s default layers to the map:

  • Mapbox Satellite
  • Mapbox Outdoors

It is very simple, and does not have any support for other Mapbox layers or features at this time.

This is pretty much the extent of the code: https://github.com/farmOS/farmOS/blob/2.x/modules/core/map/modules/mapbox/js/farmOS.map.behaviors.mapbox.js

If you are interested in expanding the Mapbox capabilities in farmOS, I would recommend starting a custom module to experiment in. And if you reach a point where your code might be generally useful to others, we can explore merging it into the upstream farmOS core Mapbox module!

we need to override the satellite imagery with the client’s AutoCAD drawings

Or, if your needs are just simply adding a custom layer, you may be able to just add a very simple map behavior (like the one linked above) that simply hard-codes the custom Mapbox layer URL. We use a custom library called farmOS-map (based on OpenLayers) for adding features to maps. Here is the README section on adding layers: GitHub - farmOS/farmOS-map: farmOS-map is an OpenLayers wrapper library designed for agricultural mapping needs. It can be used in any project that has similar requirements.

Add custom module(s) to simplify data entry of Log info (simple, land/function, eg. Spray Vineyard, default everything else, is where we need to get to)

I would recommend using “Quick forms” for this.

We have some basic information for getting started in the farmOS.org docs:

Quick forms are largely just Drupal’s core Form API, though, so you can find a lot more information and tutorials on the internet.

The Drupal Examples module is always a good reference when you are getting starting with module development: https://www.drupal.org/project/examples/

All instructions re. modules eventually (after long rabbit holes ) involve CLI instructions. With Plesk we do not have access to a CLI interpreter (at least not that I’ve found) so I need another solution.

If you plan to do any custom development you will want to set up a local development environment SEPARATE from your “live” deployment. The farmOS development environment is based on a Docker image that includes all the CLI tools you need. I can’t recommend it strongly enough.

Instructions here: Getting started | farmOS

Never mess around with your live database, or you can end up breaking things. On this note, be sure to familiarize yourself with the upgrade procedure as well so you are comfortable upgrading when new versions of farmOS are released: Updating farmOS | farmOS

I’m willing to pay for a solution - or instructions on how to get from point A. (vanilla farmOS) to B. achieving a custom module, which we can then add code to a redeploy.

That’s great! Consider posting a dedicated thread over on the brand new Jobs Board, and describe which bits you’re specifically interested in paying for, information for contacting you, etc. :slight_smile:

Mike, thanks - once again - for your rapid and helpful reply.
I really appreciate it.

But let me get this straight… there is no actual backend code to take our Mapbox API key and use it to drag our mapping data in from mapbox.com ? So… saving our API key in the settings doesn’t actually do anything ? Little bit disappointing… we inferred from that page that we could use ours.
Judging by the hardcoded tile data in the js you referred to, unless we have a ‘outdoors-v11’ or ‘satellite-v9’ style configured we’d never pick anything up anyway.
But… it seems we could potentially add a third (in our case, fourth, as it happens) MapboxLayer option, which uses our API key. I believe (from what my dev says) we need to provide a style URL as well… can we then also extend that form to cater for that ?

1 Like

The Mapbox module included with farmOS has no concept of custom “mapping data” that is hosted by Mapbox. It could certainly be expanded to do that with development. But right now it only serves to add two Mapbox base layers as options to the map.

So… saving our API key in the settings doesn’t actually do anything ?

It does. It adds the “Mapbox Satellite” and “Mapbox Outdoors” layers to the farmOS map.

Mapbox requires an API key to include its satellite layers in other software. When you enter your API key in the farmOS /farm/settings/map/mapbox it adds/enables those layers as “base layer” options in farmOS maps.

Are you seeing those two layers? If so, then that is what the API key is allowing. If you don’t see those (with a valid API key), then maybe something else is going wrong (happy to help debug that).

We include the Mapbox module in farmOS simply to provide a satellite map layer option. Without that, there is only Open Street Map, which isn’t very useful for most agricultural mapping needs.

Hope that clarifies!

2 Likes

@nzsnowman If you or your dev are available on Thursday at noon Eastern time we have our weekly farmOS dev call. Happy to talk though ideas there if it’s easier!

Aha. gotcha.
So it seems we are connecting to Mapbox using our key, but not using our style URL. Which currently contains our CAD plan overlaid on the map…

So could we edit the JS and replace

url: ‘https://api.mapbox.com/styles/v1/’ + tileset + ‘/tiles/512/{z}/{x}/{y}?access_token=’ + key,

with a formal URL pointing to our Mapbox style data ?

If so, is this just a script that is loaded at run time, or are all website files packaged up into the Docker container somehow ? Like, is there a build/compile step before new code is live ?

Yes and no. If I understand your environment it would be a bit tricky to edit the built-in Mapbox behavior to load your tilesets.

A better strategy would be to create a custom farmOS module with JS similar to the core Mapbox module, but which uses your tilesets. Then you can install that module and enable it in farmOS.

Yes! Absolutely… a custom module will be a much better approach.
I know it’s crude, just editing a script on the fly, but we can replace it with out own module(s) later when we get over that learning curve.
I’m just running out of time to persuade my client that his client has picked the right software. And for some reason, the old satellite picture (which shows a crappy building site, instead of gardens and pathways) is a deal breaker for him.
We told him (after seeing the Mapbox API key) that we could easily replace it for him (he wants the AutoCAD plan); that, and QuickForms (of which there only seems to be one) gave us confidence we could achieve what he wants…
Now, it’s been over a month and we appear to have made little progress.
I need a quick gain for our next “show and tell” - before I send my next invoice. :grin:

1 Like

Quick forms require a custom module too.

There’s a good amount of documentation here:

… but it takes some learning to do what you’re talking about. No guarantees of quick solutions! Good luck and feel free to ask specific questions as you start experimenting!

1 Like

Hope this works… @Sm1tie

Mmmm…
I might be stating the obvious here, but by experimentation we proved (to ourselves, at least) that this js script (farmOS/farmOS.map.behaviors.mapbox.js) is not being executed by the page at run time.
Calling an additional addMapboxLayer did not add an extra layer.
Even changing the Title text, was not reflected on the page, either.

The logic must be more complex because somewhere there is logic that determines whether to present the satellite map, etc. based on whether there is a Mapbox key stored. But not in this script.
If we could find that script, we could then write a module to override/extend whatever methods are used. And then provide proper Mapbox overlays using a style URL.

Any ideas ?
(sorry couldn’t get up at 5am for the dev call :sleeping:)

Have you tried clearing the Drupal cache? This can be done through the UI at /admin/config/development/performance

I think that should happen automatically when you add a MapBox API key and click “Save” in the MapBox settings.

I’m assuming you did put in a MapBox API key and click save? I think you said you did earlier, but worth double checking. farmOS.map.behaviors.mapbox.js only gets added to the page if an API key is saved.

Oh maybe I’m wrong! Maybe it doesn’t do this currently… it should!

See if clearing your cache fixes it…

When you say, through the UI at /admin/config/development/performance` I’m not sure what that means. Where am I going ? Is that a directory ?

Also… I know this probably needs a new thread… I broke the QuickForm function. I followed the EggHarvest tutorial/example/thingy/ The code didn’t work, and gave an error, so I uninstalled it. Removed all files.
But I still get an error loading the QuickForm page:

The website encountered an unexpected error. Please try again later.

*Drupal\Component\Plugin\Exception\PluginException* : Plugin (egg) instance class "Drupal\farm_quick\Plugin\QuickForm\Egg" does not exist. in *Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass()* (line *97* of *core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php* ).

and a crash dump.

Where is the egg stuff registered ? I need to get rid of it, asap.

I think your issue is you don’t have the egg module installed.
But if you have removed it from Quickforms again it should be sorted once you clear the cache.

This is a path in your browser so something like,
https://YourFarmOSURL/admin/config/development/performance

can be done from the command line by running the command drush cr (inside the container if running in docker)

Do you have a development instance? probably advisable not to try new things on a production machine.

1 Like

Ahh, brilliant. Thank you so much. All sorted now.
The cache must persist for quite some time…

1 Like

I had a go at adapting the Mapbox module to add additional layers (OpenWeatherMap Layers)
May be useful for you to have another example.

The the root of the Mapbox module is here https://github.com/farmOS/farmOS/tree/616261498d87103eba3651254ac25f9f4cfd0f36/modules/core/map/modules/mapbox . The logic to present the satellite image based on whether or not the the API key is set is at the bottom of this file. https://github.com/farmOS/farmOS/blob/616261498d87103eba3651254ac25f9f4cfd0f36/modules/core/map/modules/mapbox/src/EventSubscriber/MapRenderEventSubscriber.php ,
I just copied the entire module and replaced mapbox with openwethermap in every file with no other changes except for the JS which needed a little more.

The new module was then just placed in the normal modules folder and installed like any other module.

1 Like