Gmap3 - Forum

Gmap3 exchange platform

You are not logged in.

Ads
(server costs 27.50€ per month)

#1 2012-06-13 22:32:44

degt
Member
Registered: 2012-05-15
Posts: 33
Website

Injecting addKmlLayer objects to a gmap3

I am still a newbie at this but since most of the examples are based on static data (not questioning the quality of the examples though!) I need to dynamically inject data to GMAP3.

In particular I have my KML files, I want that on load the script retrieves an URL from my site that will return a list of KML URLs or something like that. Then after it receives it (which may as well be triggered by pressing a button), it would then dynamically inject "addKmlLayer" actions into the GMAP3 instance.

Is there  a way to achieve that rather than hardcoding all the addKmlLayer actions?

Offline

Ads
(server costs 27.50€ per month)

#2 2012-06-14 01:25:26

charlietfl
Moderator
Registered: 2011-11-24
Posts: 201

Re: Injecting addKmlLayer objects to a gmap3

Not really clear exactly what you are trying to , but you could do something like this:

var kmlOptions = {/* kml overlay options */};
var $map=$('#map');

$.getJSON(url, function(data) {
    /* assumes data is a simple array of url's in json format*/
    $.each(data, function(index, url) {
        $map.gmap3({
            action: {
                action: 'addKmlLayer',
                url: url,
                options: kmlOptions

            }
        });
    });
});

Offline

Board footer

Powered by FluxBB