Home > Software engineering >  How to display a picture using Fluid (ViewHelper) from a JavaScript-file in TYPO3
How to display a picture using Fluid (ViewHelper) from a JavaScript-file in TYPO3

Time:01-14

I created a own extension for an interactiv map using leaflet. But I can't display my picture for a map:

enter image description here

I've already uploaded a picture in backend: enter image description here

setup.typoscript:

tt_content {
   interaktivekarte_karteuser =< lib.contentElement
   interaktivekarte_karteuser {
      templateName = Map
      dataProcessing {
         40 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
         40 {
            references.fieldName = tx_interaktiveKarte_image
            as = image
         }
      }
   }
}

Map.html:

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:section name="content">
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin="" />
    <script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>
    
    <div >      
      <div id="map">
        
      </div>
    </div>
  
</f:section>
</html>

park.js:

var map = L.map('map', {crs: L.CRS.Simple});
var bounds = [[0,0], [750,1200]];
L.imageOverlay('../Parks/Park.png', bounds).addTo(map);
map.fitBounds(bounds); 

To check I wrote this fluid in Map.html:

<f:for each="{image}" as="fileReference">
  <f:image  image="{fileReference}"/>
</f:for>

If I wrote the fluid above in Map.html, a picture is displayed. But outside of leaflet! I want to display the picture in leaflet...

How can I write in HTML- and JavaScript-file to display a picture in leaflet?

(And do I have to use fluid in any case? A picture-data is in my extension. Can I just render it in javascript-file?)

Thank you for your help.

CodePudding user response:

What about?

HTML:

<div id="map" data-image="{image.0.publicUrl}">

</div>

JS:

var map = L.map('map', {crs: L.CRS.Simple});
var bounds = [[0,0], [750,1200]];
var imageUrl = $('#map').data('image');
L.imageOverlay(imageUrl, bounds).addTo(map);
map.fitBounds(bounds); 
  •  Tags:  
  • Related