WordPress.org

Ready to get started?Download WordPress

Forums

Basic Google Maps Placemarks
[resolved] Icon Categories (8 posts)

  1. erinhamalainen
    Member
    Posted 1 year ago #

    Hi Ian

    Firstly, great plugin!

    Secondly, I like to make a different icon for each placemark on the map. I saw you have a coding on the FAQs for this, but Im not sure where to put it in the edit part of your plugin, and what bits of code to change (Im doing my website for a uni assignment and still learning code).

    Ive bolded what i think i need to change depending on the category - do I need to do the below code for each category or can i just build within this? (I assume the png image below is the icon wanted to be displayed on the map?)

    Help is much appreciated!
    http://erinh.phpfogapp.com/plan/map/

    function setBGMPDefaultIconByCategory( $iconURL, $placemarkID )
    {
        $placemarkCategories = wp_get_object_terms( $placemarkID, 'bgmp-category' );
    
        foreach( $placemarkCategories as $pc )
            if( $pc->slug == '<strong>restaurants</strong>' )
                $iconURL = get_bloginfo( 'stylesheet_directory' ) . '/<strong>images/bgmp-default-icon.png'</strong>;
    
        return $iconURL;
    }
    add_filter( 'bgmp_default-icon', 'setBGMPDefaultIcon', 10, 2 );

    http://wordpress.org/extend/plugins/basic-google-maps-placemarks/

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser.]

  2. Ian Dunn
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Erin, it's not a good idea to modify the plugin directly, because then your changes will be overwritten any time you upgrade. Instead, you can put your changes inside a functionality plugin.

    If you want to assign icons to multiple categories, you can do within a single function using a series of if/else statements or a switch().

  3. erinhamalainen
    Member
    Posted 1 year ago #

    Hi Ian, thanks so much for your reply they were great instructions - however the category icons still seem not to be working?

    I have added the [bgmp-map categories="restaurant,winery,accommodation,golf,hot-air-balloon"] as your installation instructions said.

    When i zipped my php file I also included folders to map the icons
    i.e. '/images/marker-icons/food-icon.png'; = (plugin)/images/market-icons/(icon.png file) - is this correct?

    Do the icons need to be a particular size? I've tried both with the size i have and the size of the existing icon but to no change

    http://erinh.phpfogapp.com/plan/map/

  4. erinhamalainen
    Member
    Posted 1 year ago #

    I found the workaround by using the featured image, but if you have time would like to know where I was going wrong above? thanks!

  5. Ian Dunn
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Erin, the size doesn't matter at all. I can't tell what's going wrong since you changed back to using the featured image, but my first guess would be that the URLs were wrong. You can install Firebug and check the Console tab for 404 errors.

    Instead of using relative paths, it's better to use one of the API functions to generate an absolute one. If the images are stored in the content directory, you'd use wp_uploads_dir(); if they're in a theme you'd use get_stylesheet_directory_uri(); and if they're in a plugin you'd use plugin_dir(). You can check the Codex for details on how to use those functions.

  6. erinhamalainen
    Member
    Posted 1 year ago #

    Thanks so much for your help Ian, I think I'm just not understanding the PHP coding... I will try and look into it if I have time, for what I need it for the featured image will work ok for now :)

  7. dhobeika
    Member
    Posted 1 year ago #

    I am also having some problems with this. I added this following code to my functions.php file -- we have 5 different categories of events, for most I just set the featured image, but I did a test one for Chicago without setting the featured image and just checking off the category name and it didn't work.

    Any suggestions?

    http://www.americanhistorybowl.com/regionals/

  8. Ian Dunn
    Member
    Plugin Author

    Posted 1 year ago #

    dhobeika, if you use Firebug or Chrome Dev Tools you'll see these errors in the console log:

    bgmp_createMarker(): OK - Tulsa  icon wasn't passed in. functions.js:141
    bgmp_createMarker(): IL - Chicago  icon wasn't passed in.

    If you view the page source and look at the bgmpData.markers array, you'll see that the icon values for both are "null"

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags