geosolutions-it / MapStore2

The solution to create and share maps, dashboards, geostories with 3D support on the web. And it is open-source too!
https://mapstore.geosolutionsgroup.com/
Other
517 stars 405 forks source link

Identify tool result should show urls as hyperlink #7096

Closed MaelREBOUX closed 3 years ago

MaelREBOUX commented 3 years ago

Description

Some datas has url in specific attributes. A user should be able to click on it to go to the resource : web page, document... It will be so much easier for non specialist users.

image

My proposition : if value of an attribute begins with "http" then transform the whole string in an hyperlink.

What kind of improvement you want to add? (check one with "x", remove the others)

Other useful information

landryb commented 3 years ago

and in the attribute table too ? in the feature popup ?

MaelREBOUX commented 3 years ago

Good question. I think yes ?

MV88 commented 3 years ago

@MaelREBOUX Hi, i guess this depends on the info_format chosen, which i can see is TEXT i.e. text/plain Have you tried using HTML if it is any better?

My 2 cents: I think this is the correct behaviour for this format

For the attribute table i think is possible to develop a custom cell renderer, based on the value of the attribute @offtherailz what do you think?

landryb commented 3 years ago

not sure what geoserver does for HTML output templating, but i'm pretty sure by default it doesnt render urls as proper HTML links.

offtherailz commented 3 years ago

You can do it on GeoServer using FTL template, then setting HTML format, or using the MapStore template format, putting the variables in the URL of a link like this image

MaelREBOUX commented 3 years ago

Yes : we know that we can do customizations (such FTL templates) but it has to be done for specific needs / projets.

Here I talk of a default behaviour. For any layers added through the catalogs services.

@MV88 The HTML default format is not suitable because it is all horizontal.

BUT, if the default HTML template would be vertical and url rendered as hyperlinks and the HTML output set as default output for the GFI...

... maybe it could be a good idea ?

tdipisa commented 3 years ago

@MaelREBOUX

BUT, if the default HTML template would be vertical

I think the only way you have is to provide a custom FTL template for this.

and url rendered as hyperlinks

GeoServer doesn't renders URLs as links in the default HTML template for GFI requests. Also in this case, if you don't want to use the MS templating system for GFI, I think the only way you have is to provide a custom FTL template.

and the HTML output set as default output for the GFI...

The default in GeoServer is text/plain but in MapStore you can choose a different default format for your maps.

For all three points above, if you want to change something GeoServer side, this is not the right repository anyway :-)

offtherailz commented 3 years ago

I think the default HTML template for GeoServer is made to satisfy the generic use case. A table with one row for each feature (feature info can return many features as once), with the attributes as columns. If you prefer to create many tables, one for each feature, you can customize even the default FTL template for all the layers on your own GeoServer (see documentation), Recognizing URLs, if you want to create links, is up to you When you configure these custom templates, you can create links for strings that have to be interpreted as URLs (or using regex to automatically transform them in links, if you prefer).

landryb commented 3 years ago

after thinking a bit, i'm a bit uncomfortable with this issue.

On one hand i fully agree with @tdipisa & @offtherailz that 'the way to go' is to use HTML format for the layer and modify the default geoserver ftl in https://github.com/geoserver/geoserver/blob/main/src/wms/src/main/resources/org/geoserver/wms/featureinfo/content.ftl#L28 (maybe even something to contribute upstream ? or local modification to georchestra's geoserver (yuck!) ?) so that it detects URLs/links in attributes, and renders them as html links by default.

But on the second hand, my understanding is what @MaelREBOUX wants is that mapstore should 'parse' the default text/plain returned content, detect URLs/links in attributes, and renders them as html links too. That makes me feel uncomfortable (as it would imo be a hack), but that would be a middle ground...

and as @mv88 said, rendering links in the attribute table could definitely be a mapstore-specific improvement (that would be welcome !).

MaelREBOUX commented 3 years ago

One other point : GeoServer rocks but impov it is the server data. If we give him too much things to do it is not good. What we talk here is data vizualisation which is, for me, the role of MapStore2.

store the data ==> treat / expose the data ==> vizualize the data

and for the plain/text uase case, I believe it could only be done by MapStore.

catmorales commented 3 years ago

For information, In portail-test i tried to generalize the fact that hyperlinks are clickable:

1- Ms templating Hyperlink is OK but this functionnality is usable only in an application context with layers pre-loaded and configured by administrators .

image

2- FTL I put *. ftl (header, footer and content) in the /geoserver-datadir/template/ directory to manage links to urls for all the layers published by geoserver. Specific parameters (content.ftl in the good directory) can be applied on a specific layer and will be prioritary.

It works but i didn't see how to force the html setting by default in the localConfig.json to complete the test.

@tdipisa , @offtherailz Could you give me the solution ?

Content.ftl:

<ul>
<#list features as feature>
  <li>
    <b>Couche : ${type.name}</b> - Entit&eacute; : (id: <em>${feature.fid}</em>):
    <br/>
    <ul class="puce">
        <#list feature.attributes as attribute>
             <#if !attribute.isGeometry>
                <#if attribute.value?has_content>
                    <#if attribute.value?contains ("https")>
                        <li><a href="${attribute.value}"target="_blank">Cliquer sur le lien</a><li/>
                    <#else> 
                            <li><b>${attribute.name}</b> : ${attribute.value}</li>
                    </#if>
                <#else>
                    <li><b>${attribute.name}</b>: Non renseign&eacute;</li>
                </#if>
                </#if>
        </#list>
    </ul>
  </li>
</#list>
</ul>

image

3- For attribute table we don't have any solution, now, to make links clickable but @MV88 suggested a solution.

tdipisa commented 3 years ago

@MaelREBOUX

One other point : GeoServer rocks but impov it is the server data. If we give him too much things to do it is not good.

As I said this is not a plus :-), this is a core feature of GeoServer and it is something that GeoServer can usually manage through Freemarker templates (that requires text/html as a format for GFI requests)

What we talk here is data vizualisation which is, for me, the role of MapStore2.

Of course, other ways are also available like using the MS templating system for GFI as I said before (that requires application/json as a format for GFI in order to be able to parse the response to apply the template client side)

store the data ==> treat / expose the data ==> vizualize the data and for the plain/text uase case, I believe it could only be done by MapStore.

as also mentioned by @landryb text/plain is not a format that can be parsed in a good and stable way, therefore that kind of format must be excluded in this case.

@catmorales

I put *. ftl (header, footer and content) in the /geoserver-datadir/template/ directory to manage links to urls for all the layers published by geoserver. Specific parameters (content.ftl in the good directory) can be applied on a specific layer and will be prioritary

Ok. I think anyway it is better use the starts_with function of freemarker instead using contains such as:

      <#if attribute.value?starts_with("http") || attribute.value?starts_with("https")>
        <li><a href="${attribute.value}"target="_blank">Cliquer sur le lien</a></li>
      <#else>
        <li>${attribute.name}: ${attribute.value}</li>
      </#if>

It works but i didn't see how to force the html setting by default in the localConfig.json to complete the test.

If you remember it is possible in localConfig by using defaultState.initialState.mapInfo.configuration.infoFormat set to text/html as documented here. Below is a sample.

    "initialState": {
      "defaultState": {
        "mapInfo": {
          "enabled": true, 
          "disabledAlwaysOn": false, 
          "configuration": {
            "showEmptyMessageGFI": false, 
            "infoFormat": "text/html"           
          }
        }
landryb commented 3 years ago

It works but i didn't see how to force the html setting by default in the localConfig.json to complete the test.

If you remember it is possible in localConfig by using defaultState.initialState.mapInfo.configuration.infoFormat set to text/html as documented here. Below is a sample.

    "initialState": {
      "defaultState": {
      "mapInfo": {
        "enabled": true, 
        "disabledAlwaysOn": false, 
        "configuration": {
          "showEmptyMessageGFI": false, 
          "infoFormat": "text/html"           
        }
      }

we've had a debugging session over irc with @catmorales last week and failed to find the right incantation/way to put that in localConfig.json, but i've tested this chunk here locally and yes, this works fine, all GFI queries now default to text/html.

How about having that by default, both in https://github.com/georchestra/mapstore2-georchestra/blob/master/localConfig.json#L107 and https://github.com/georchestra/datadir/blob/master/mapstore/localConfig.json#L107 ? the default text/plain is a bit ... not that user-friendly :)

tdipisa commented 3 years ago

@landryb

How about having that by default, both in https://github.com/georchestra/mapstore2-georchestra/blob/master/localConfig.json#L107 and https://github.com/georchestra/datadir/blob/master/mapstore/localConfig.json#L107 ? the default text/plain is a bit ... not that user-friendly

This is not a problem for us, of course.

catmorales commented 3 years ago

Ok. I think anyway it is better use the starts_with function

done, thank you.

If you remember it is possible in localConfig

I will try newly in localConfig.json but i I had already added it it in the config.json and new.son before the section dimensionData" and it works :

"mapInfoConfiguration": {
        "showEmptyMessageGFI": false,
            "infoFormat": "text/html",
        "maxItems": 1000
    },
    "dimensionData": {},
    "timelineData": {}
tdipisa commented 3 years ago

@catmorales thank you for the feedback Can we close then this issue and open a new one dedicated for links in attribute table?

catmorales commented 3 years ago

Yes i agree

tdipisa commented 3 years ago

@catmorales will you do it?

catmorales commented 3 years ago

done !