3

I've got a directory channel, and each entry has been manually geocoded onto a map with the Google Maps for ExpressionEngine fieldtype. I now want to plot these 1,000 entries onto a single map in the most efficient way, and each category of entry has a different marker (6 categories in total).

Here's the code I'm using with Google Maps for EE:

{exp:gmap:init id="map1" class="gmap" scrollwheel="false" style="width:940px;height:500px" latitude="35.0000" longitude="25.0000"}

{exp:channel:entries channel="directory" status="open" disable="category_fields|member_data|pagination" limit="1000" dynamic="no" sort="asc" search:cf_directory_map_latitude="not IS_EMPTY"}

  {categories show_group="2" limit="1"}

    {cf_directory_map_location id="map1" show_one_window="true" icon="{category_image}" infobox="true" offsetY="-35" offsetX="15" closeBoxMargin="5px" class="ui-infobox-dark" closeBoxURL="/themes/third_party/gmap/css/images/white-close-button.png" style="width: '300px'" alignBottom="false" clearanceX="10" show_one_window="true" extend_bounds="false"}

      <h3>{title}</h3>
      <p><strong>City: </strong>{cf_directory_city}<br />
        <strong>Type: </strong>{category_name}</p>
      <p><a href="{cf_directory_website}" target="_blank">Visit Website &raquo;</a></p>

    {/cf_directory_map_location}

  {/categories}

{/exp:channel:entries}

The above works, but I feel that the code it's outputting is bloated when outputting so many entries. Every marker on the map is outputting its own script tag that is 45 lines long. So multiply this by 1,000 entries, and you end up with 1,000 sets of script tags, and 45,000 lines of code, which means that the page can be a few megabytes in size and slow to load, even when using caching.

Is there a more efficient way of plotting entries onto a map with this add-on? Or if not, is there an easy alternative that I can use which makes use of the data I already have for each entry (the Google Maps for EE field, or else the standard latitude/longitude fields)? Thanks for any advice.

2
  • I'll need to check but I think you can simply use the fieldtype and it will output all the markers. You don't need to loop through every entry and output its marker. But as I write that I can't think how it would work so maybe I'm mis-remembering!
    – foamcow
    Commented Dec 19, 2013 at 9:36
  • I thought I was already using the fieldtype above (cf_directory_map_location}), but thought I needed to use this within a channel entries loop. Correct me if I'm wrong though. Also, I suspect that the code that is outputted (either way) would still be as bloated.
    – Stephen
    Commented Dec 19, 2013 at 14:21

3 Answers 3

2

The basic concept behind what you need to do is generate a JSON response of your markers, and loop through them with JS and add them to the map manually. That's really the only want around the procedural JS that is injected into your page. You could load the JSON feed asynchronously too.

2
  • Thanks for the tip, Justin. Don't you find this issue coming up all the time with your customers (even to those showing a few hundred markers on the map)? To the point that this could be a feature request so they can still use the add-on for outputting the map, rather than having to go a custom route?
    – Stephen
    Commented Dec 24, 2013 at 12:35
  • 1
    Honestly, it's not really a big issue. Most people use some sort of pagination and only limit the markers to < 100 at most. I do have a new solution finished and ready to be released. I just didn't have time to release it this year. It handles the JSON for you, and I will likely build a new JS library to make plotting markers easier. The JS library is still in concept, but the EE portion is finished. Be on the lookout for it first part of 2014. Commented Dec 25, 2013 at 20:00
1

You might want to consider a custom query. I don't know much about exp:gmap:init but the channel entries tag can be a bit of an overkill sometimes when it comes to simple output.

1
  • 1
    I agree that a custom query would be best, as the channel entries tag and the categories tag have a lot of overhead. But I'm caching this with CE Cache, so I'm not worried about that at the moment. I just want the raw output in the template to be as streamlined as possible in the first instance (i.e. the 45,000 lines of code and page weight).
    – Stephen
    Commented Dec 19, 2013 at 23:08
-2

use clustering .make group of markers as cluster.one cluster will present many markers inside.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.