graphxks VIP
Total posts: 68
06 Jul 2014 18:02

I am mapping Assets by using a parent/child relationship between the Asset (child) and the Asset's Collection (parent).

This works great for showing all the Assets in a Collection.

See: http://new.michiganwatertrails.org/index.php?option=com_cobalt& ;view=record&id=15:lake-michigan-water-trail-northwest&Itemid=161

Now, I need to sort the Assets displayed in this Collection map view, turning them on and off by their Attraction type (each Asset can belong to one (only one) of 47 total Attraction types).

See: http://www.michiganwatertrails.org/trail.asp?ait=cv& ;cid=126

This allows the end user to sort which type of Attraction they are interested in and turn off the others.

How do I do this in Cobalt?

Thanks!

Last Modified: 24 Jul 2014


Sergey
Total posts: 13,748
07 Jul 2014 09:36

To do this you will need to edit map template. otherwhise it will be filter with page reload only. You either filter by cheld or parent or you can create custom solution using Google map api in map template.


graphxks VIP
Total posts: 68
07 Jul 2014 10:24

hi Sergey,

Any idea how to go about this? I'm afraid I'm out of my depth on this one.

Thanks!


Sergey
Total posts: 13,748
07 Jul 2014 23:39

graphxks I'm afraid I'm out of my depth on this one.

To write totorial on whole subject with examples is even more time than add it to template. In generald when you create markers you add something there like tag. Then with Google MAP api you simply show/hide parkers with special tag.

Unfortunately I cannot tell you the whole story but if you start and you have spesific question, I may try to answer.


graphxks VIP
Total posts: 68
08 Jul 2014 00:54

Hi Sergey!

Maybe that's the issue. I am displaying a number of children (Assets) as part of a parent group (Collection). The children (Assets) are also part of an Attraction group. The Asset's Icon needs to pertain to that Attraction (i.e. - Asset is a beach, park, water access, etc.)

Now all the Assets are getting an icon (via a form field in Cobalt) that indicates the type it is (i.e. -beach, park, water access) since we can't assign the Asset icon by the Attraction group it is part of.

Can we sort by this icon? Showing a map key where users can show beaches, parks, etc?


Sergey
Total posts: 13,748
08 Jul 2014 02:29

graphxks Can we sort by this icon?

You cannot sort one section by value of field of related section. not technicaly possible.

Now I think that your attraction and assets should be a select field. With all things you want to do it is most appropriate one. With your current setup you cannot even hack CObalt because there is no even way to hack. You can still use articles for attractions and asets but connect not through parent/child field but through select field and SQL source. You wil get link to article and eesy custom code to add icon. You will save some recorses and make website quicker. You will be also easy hack to change marker acording to attraction or asset.

I added some text how to do that to SQL source documentation article.


graphxks VIP
Total posts: 68
08 Jul 2014 10:55

Sergey,

That is how I originally had it set up. The switch to parent/child was your idea initially.

I can see doing the Attractions as a select field on the Asset creation form. Should the Collection also be a select field on the Asset creation form or remain a Parent/Child relationship?

Thank you.


Sergey
Total posts: 13,748
09 Jul 2014 03:07

graphxks That is how I originally had it set up. The switch to parent/child was your idea initially.

I remember that. But now I had to change my mind because what you want is too complicated with parent/child fields setup.

graphxks Should the Collection also be a select field on the Asset creation form or remain a Parent/Child relationship?

If you are happy how it works now, you can live it as it is.


graphxks VIP
Total posts: 68
09 Jul 2014 22:36

Thanks Sergey,

Getting closer. I can now display a sort by Attractions area on the Collection page (I actually want this to the right, but I can style that later). See below:

Screen Shot 2014-07-09 at 6.27.30 PM

Clicking on one of these sorts then takes you to a list page. I want to be able to use clicks of these Attraction types to turn on and off these types on the map, not navigate away from the page.

Any ideas?


Sergey
Total posts: 13,748
09 Jul 2014 23:56

I understand. I'll try to think something out for this for the next release.


Sergey
Total posts: 13,748
10 Jul 2014 00:19

OK. Here is what I added into new 8.183 field with I updated.

There is parameter Marker list processor. This is the file you select from fields/geo/tmpl/markers_list/

So create copy and select it in parameters. Now you have to change it a little and return array with marker category with you can tace vrom select field. Just adds it's value into query.

Now in tha map template in JS find line where drawMarker(ll, k, v.marker); it is 166 here. And pass there your new parameter drawMarker(ll, k, v.marker, v.category);.

Now edit function drawMarker(mPosition, record_id, icon) and change to function drawMarker(mPosition, record_id, icon, cat).

Now just ander marker defined in 188 add new line

var marker = new google.maps.Marker(mOptions);
marker.category = cat;

This is phase 1. You added category tag to every marker. So you can search through them and change visibility property acordingly on attraction icon clicked.


graphxks VIP
Total posts: 68
10 Jul 2014 00:39

Very cool solution! I will try it. Thank you Sergey!


graphxks VIP
Total posts: 68
10 Jul 2014 19:05

Sergey OK. Here is what I added into new 8.183 field with I updated.

There is parameter Marker list processor. This is the file you select from fields/geo/tmpl/markers_list/

Sergey, I downloaded and installed the new "field_cobalt.j3.geo.v.8.184.zip" and there is no markers_list folder in fields/geo/tmpl/

Please advise.


Sergey
Total posts: 13,748
11 Jul 2014 03:43

You are right. Somehow it is lost. I restoerd it and updated.


graphxks VIP
Total posts: 68
11 Jul 2014 03:44

Ok, I will try again in the morning. Almost midnight here. Thank you.


graphxks VIP
Total posts: 68
11 Jul 2014 12:37

Sergey So create copy and select it in parameters. Now you have to change it a little and return array with marker category with you can tace vrom select field. Just adds it's value into query.

Add this value into what query?

Sergey Now in tha map template in JS find line where drawMarker(ll, k, v.marker); it is 166 here. And pass there your new parameter drawMarker(ll, k, v.marker, v.category);.

Sorry where is this map template?

If you could expand on your explanations a bit it would help. Thank you.


Sergey
Total posts: 13,748
14 Jul 2014 00:54

graphxks Sorry where is this map template?

Please read article on Cobalt templates.

http://docs.mintjoomla.com/en/cobalt/custom-templates-general

This is article list template. Do not forget to make a copy first and assign new template to the section so you do not lose your changes on update.

graphxks Add this value into what query?

There is a query in that file.

$query = $db->getQuery(TRUE);
$query->select('value_index, field_value, record_id');
$query->from('#__js_res_record_values');
$query->where("value_index IN('lat', 'lng', 'marker')");
$query->where('section_id = ' . $this->request->getInt('section_id'));

You have to extend this so that field value from select is also included. You can add $query->where("field_id IN(2,12)"); instead of $query->where("value_index IN('lat', 'lng', 'marker')");. Where 2 and 12 are ids of goe and select fields.

Now in foreach($list as $position) convert this value to category property.


graphxks VIP
Total posts: 68
14 Jul 2014 02:08

Ok, I found the map template. Funny, I searched files for drawMarker(ll, k, v.marker); and it didn't find it but your instruction helped.

Thank you for your patience.


graphxks VIP
Total posts: 68
14 Jul 2014 02:24

Sergey You have to extend this so that field value from select is also included. You can add $query-&gt;where("field_id IN(2,12)"); instead of $query-&gt;where("value_index IN('lat', 'lng', 'marker')");. Where 2 and 12 are ids of goe and select fields.> <small

I'm going to sound dumb again. Remember I am a Cobalt newbie. Where do I get the ids of the geo and select fields?

Sergey Now in foreach($list as $position) convert this value to category property.

Can you expand on this please?

I'll pay you back by writing a wiki tutorial if we can make this work. There has to be others who need this function.

Thank you.


Sergey
Total posts: 13,748
14 Jul 2014 05:08

graphxks Where do I get the ids of the geo and select fields?

In backend in the list of fields last column.

graphxks Can you expand on this please?

Add field_id to select.

$query->select('value_index, field_value, record_id, field_id');

Replace whole foreach($list as $position){... with

foreach($list as $item)
{
    if($item->field_id == 1)
    {
        $out[$item->record_id]['category'] = $item->field_value;
    }

    if($item->field_id == 2)
    {
        if($position->$item === 0)
        {
            continue;
        }

        $val = $item->value_index == 'marker' ?
            JUri::root() . 'components/com_cobalt/fields/geo/markers/' . $this->params->get('params.map_icon_src.dir', 'custom') . '/' . $item->field_value :
            (float)$item->field_value;

        $out[$item->record_id][$item->value_index] = $val;

    }

}
  • 1 - ID of the select field
  • 2 - ID of the geo field

Now in map template in AJAX see what is retuned. you should have array of opbjects for each article with category propert which you can use later for JS based visibility.


graphxks VIP
Total posts: 68
14 Jul 2014 10:42

Thanks Sergey,

I'm traveling today but will try this tonight.

Powered by Cobalt