printOpenStreetMap (check if empty)

Roland Member

Hello ! Sorry to bother you peoples, with my PHP level 1 skills.
Thinking it was easy, but I already spend... hours trying to solve it ^^'

Here is the deal :
In picture view if I want to hide the bloc section of the OSM plugin, I wrote this :

if(function_exists('printOpenStreetMap') && (getImageData('EXIFGPSLatitude')!='')) {
echo '<section class="bloc-osm">';
echo '<h2>Maps</h2>';
@call_user_func('printOpenStreetMap');
echo '</section>';
}

And it's working :)

In Album view, I tried :
if (!empty(printOpenStreetMap())) { ... }
if (!empty(getAlbumGeodata($_zp_current_album))) { ... }
if (!empty(getGeoData())) { ... }
if (!empty(getGeoDataJS())) { ... }

None of them are working. Any clue ?

Thanks !

Comments

  • acrylian Administrator, Developer
    edited March 31

    if (!empty(printOpenStreetMap())) { ... }

    This function "prints" and does not return anything. You cannot check if or empty therefore. Most "get" functions return values. In any case read the docs first before using something.

    if (!empty(getAlbumGeodata($_zp_current_album))) { ... }
    if (!empty(getGeoData())) { ... }
    if (!empty(getGeoDataJS())) { ... }

    These all are class methods of the openStreetMap class and not standalone functions to use.
    https://docs.zenphoto.org/1.5.x/class-openStreetMap.html

    To do what you want to do you have to use the class object directly.
    https://docs.zenphoto.org/1.5.x/source-class-openStreetMap.html#388-502

    Off head this should work:

     $map_object = new openStreetMap(null, $_zp_current_image); // or $_zp_current_album 
     if (!empty( $map_object->geodataJS) && !empty( $map_object->center)) { // this check is used internally to decide if a map should be printed
      //print your html stuff here
       $map_object->printMap();
     }
    

    if you already use if(function_exists('printOpenStreetMap') as a check you don't need to @call_user_func('printOpenStreetMap'); which has the same reason. You need the wrapping check with my code as well. You could also use if(class_exists('openstreetmap')) { or the generalif(extensionEnabled('openstreetmap')) { instead.

  • Roland Member

    Hello acrylian, thanks for your support ! I'm gonna to try this.

Sign In or Register to comment.