• Resolved larus-argentatus

    (@ecce-homo)


    I’ve used the leaflet tools successfully before but never interrogated the geojson to get the popups to work. My geojson has a slightly more complex structure, with nested answers to questions. I can get certain elements out and display them, like the {elementid}.

    But I want to pickout and display the answers from this section, which has multiple answers which usefully extends the pop up information on each “near miss” incident:

    "properties":{"popup":[{"question":"Choose one option in position 1","response":"near miss when on a bike"},{"question":"How long ago was the incident ?","response":"Earlier this year"},{"question":"What happened?","response":null},{"question":"Reporting the incident","response":"I did not report the incident to the police"}

    The pop up ideally would display something like this as per the link I have created:

    Incident: near miss when on a bike;
    When: Earlier this year;
    Reporting the incident: I did not report the incident to the police

    The full geojson

    https://connectingdunbar.org.uk/files/2023/10/Drop-a-pin-where-you-had-a-near-miss.json

    Any pointers or worked examples would be great!

    Thanks in anticipation and thanks for extending the toolset for WordPress users

    ??

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author hupe13

    (@hupe13)

    There were any CORS errors regarding fonts on your test page. See the developer console.

    Incident: near miss when on a bike;
    When: Earlier this year;
    Reporting the incident: I did not report the incident to the police

    Like this?: Put in a shortcode block:

    [leaflet-map fitbounds]
    [leaflet-geojson src="/url/to/Drop-a-pin-where-you-had-a-near-miss.json"]
    <b>{popup[0]question}</b>: {popup[0]response}<br>
    <b>{popup[1]question}</b>: {popup[1]response}<br>
    <b>{popup[2]question}</b>: {popup[2]response}<br>
    <b>{popup[3]question}</b>: {popup[3]response}
    [/leaflet-geojson]
    Thread Starter larus-argentatus

    (@ecce-homo)

    That’s pretty much exactly what I wanted to do, and v useful to know how to get into the nested popup.

    Also thanks for the heads up about the CORS violations, I had not noticed them!

    Thanks

    Plugin Author hupe13

    (@hupe13)

    Thank you very much for the five stars. ??

    Thread Starter larus-argentatus

    (@ecce-homo)

    A supplementary question, which I tag on here as it relates to the use of nested variables.

    I would like to display coloured and grouped markers, as per the detailed examples decribed here: https://leafext.de/en/marker/geojsonmarker/

    I can get this to work nicely in another example, but the properties are simply structured: https://connectingdunbar.org.uk/map-based-consultation/crash-data/

    I cannot see how to get the variable for property

    property=popup[3]response

    obviously doesn’t work

    [leaflet-geojson src="https://connectingdunbar.org.uk/files/2023/10/Drop-a-pin-where-you-had-a-near-miss.json" circleMarker color=red]
    <b>What happened?</b>: {popup[0]response}<br>
    <b>When?</b>: {popup[1]response}<br>
    <b>In detail</b>: {popup[2]response}<br>
    <b>Report</b>: {popup[3]response}<br>
    {respondentId}[/leaflet-geojson][geojsonmarker property=popup[3]response icondefault=blue iconprops="purple,orange"  values="I did not report the incident to the police,I reported the incident to the police" groups="I did not report the incident to the police,I reported the incident to the police" disableClusteringAtZoom=16][cluster][fullscreen][zoomhomemap]

    I’ve tried some alternatives but run out of ideas …

    Plugin Author hupe13

    (@hupe13)

    The big problem are the brackets [] in popup[3]response. I didn’t consider anything that complicated.

    Thread Starter larus-argentatus

    (@ecce-homo)

    OK, I see. Thanks.

    This json was the output of a map based questionnaire via a third party service (Maptionnaire), so I have exported a json from QGIS instead as their shape files are less complicated. This should in theory resolve the issue. My shortcode now

    [leaflet-geojson src="https://connectingdunbar.org.uk/files/2023/10/Near-misses-with-sane-variable-name.json" circleMarker color=red]
    <b>What happened?</b>: {Whathappen}<br>
    <b>When?</b>: {When}<br>
    <b>Detail</b>: {Detail}<br>
    <b>Report</b>: {Reporting}<br>
    {responId}[/leaflet-geojson][geojsonmarker property="Detail" icondefault=blue iconprops="purple,orange"  values="I did not report the incident to the police,I reported the incident to the police" groups="I did not report the incident to the police,I reported the incident to the police" disableClusteringAtZoom=16][fullscreen][zoomhomemap]

    However, this is classifying everything as “other” … nearly there, hopefully an error on my part?

    Plugin Author hupe13

    (@hupe13)

    Can you please share the json file, or at least an entry?

    • This reply was modified 1 year, 5 months ago by hupe13.
    Thread Starter larus-argentatus

    (@ecce-homo)

    Plugin Author hupe13

    (@hupe13)

    [geojsonmarker property="Reporting" icondefault=blue icon=fa-solid prefix=fa-burst iconprops="purple,orange" values="I did not report the incident to the police,I reported the incident to the police" groups="I did not report the incident to the police,I reported the incident to the police" disableClusteringAtZoom=16]
    Thread Starter larus-argentatus

    (@ecce-homo)

    That obviously did the trick, my bad!

    ??

    I am assuming there is no easy way to remove the entries that are empty e.g. Report: {Reporting}. I can probably replace the blanks with a “Missing” before I export.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Geojson popup text’ is closed to new replies.