OpenGIS / Waymark

Waymark adds powerful mapping features to WordPress that are easy to use. Create beautiful, interactive Maps that you can customise to suit your needs.
https://www.waymark.dev
GNU General Public License v2.0
21 stars 6 forks source link

Custom Properties #45

Open dariospace opened 3 months ago

dariospace commented 3 months ago

Hey @morehawes, awesome work with Waymark Jow! It deserves more stars ⭐️. Quick questions:

Cheers mate!

morehawes commented 3 months ago

Hi @dariospace,

Thanks for reaching out and for your kind words 🙏

Can this feature make a comeback and disabled with a filter instead? You removed it on 1.1.0. Removed Settings for importing custom GeoJSON properties.

I have to apologise for removing this feature without warning! This was one of a number of smaller settings and features that I removed in order to try and simplify the plugin codebase. This was much needed for future plans!

we need custom properties besides the default ones

This feature stored expected custom properties by simply appending them to the Overlay Description as a HTML <table>, which isn't very helpful if you are looking to do something else with the values. It also only did this once - on import of the original GeoJSON, so this was a pretty crude implementation.

Could you provide more specifics, ideally with an example of what you are trying to achieve? Currently unexpected properties are removed, but I can see that it would be useful to provide a mechanism for storing and accessing expected properties.

How should we target the callback function to get a property from a marker into an input somewhere in the page? We want to get the properties for selected markers to add them somewhere else as a table.

Please check out this example, here the title property is accessed for each Overlay like so:

layer.feature.properties.title

I hope this helps.

Is is possible to show a property as the marker icon instead of text/html/icon? Say we want to show a property price, or square meters.

This sounds quite custom to your project, however if in the future properties are stored and available as outlined above then yes this kind of customisation would be possible.

Are you using this for a commercial project? Would you be willing to sponsor the development of such a feature?

Cheers,

Joe

dariospace commented 3 months ago
  1. Custom Properties: we are loading a GeoJSON dynamically after an API call, the issue is that it seems you've added a sanitazing? function that removes any property that doesn't match default properties. We would need a filter to disable that sanitazing function on the GeoJSON when it is stored as a custom meta in the Map Post Type.

We import them once and we will access them later on the front end programatically, say layer.property.id or layer.property.square_meter

  1. Yes, we've tried that layer.feature.properties.title, and it worked, thanks. What we are looking is callback function when a marker is clicked instead. Marker is clicked > We store the title/id/x property

  2. It aims to be a commercial project. It is an MVP right, I might be able to break the piggy bank 🐷.

We don't want to modify the code and we couldn't find many filters to get what we need!

morehawes commented 3 months ago

Thanks for the extra detail :)

We would need a filter to disable that sanitazing function on the GeoJSON when it is stored as a custom meta in the Map Post Type.

Instead of disabling, I think a mechanism for storing and accessing expected properties is a good idea.

I will definitely think more on this.

Cheers,

Joe

morehawes commented 3 months ago

We don't want to modify the code and we couldn't find many filters to get what we need!

Good point, looks of room for improvement here! This might be worth a new issue/discussion to gather ideas for actions/filters.

morehawes commented 3 months ago

Hi @dariospace,

I have just released v1.3.0 of the plugin:

Overlay Properties - Read GeoJSON feature properties when importing (Settings > Overlays > Properties). If Waymark finds data for the specified property keys they will stored upon import. These can be automatically appended to the Overlay Description, or accessed programatically via the layer.feature.properties Object.

Once the expected properties have been imported, they can now be accessed on the front-end like so:

//Our Callback Function
const waymark_properties = (Waymark) => {
  if (typeof Waymark !== "object" || typeof jQuery !== "function") {
    console.error("Waymark or jQuery not loaded");
  }

  // Iterate over each Overlay
  Waymark.map_data.eachLayer(function(layer) {
    // When the layer is clicked
    layer.on('click', function(e) {
      alert(JSON.stringify(e.target.feature.properties));
    });
  });
};

Please let me know if this works as expected for you.

Cheers,

Joe