开发者

Google maps filtering, jquery and KML

wondering if you could shed light for me please!

I'm using http://jquery-ui-map.googlecode.com/svn/trunk/demos/google-maps-jquery-filtering.html and I have the filter working locally when the markers are being created and tagged by the script.

However I'm bringing in my map pointers from a kml file rather than through the script.

So for that I'm using

var road = new google.maps.KmlLayer( 
                        'http://www.mylivesite.ie/temp/20110627.kml',
                        {preserveViewport:true}
                        );

                    road.setMap(map);

The points load fine but I need a way to filter points in it.

The original example uses tags to filter..

                var tag = "jQuery";
                    for ( i = 0; i < 40; i++ ) {
                        if ( i > 10 ) { tag = "Google maps"; }
                        if ( i > 20 ) { tag = "Plugin"; }
                        if ( i > 30 ) { tag = "SEO"; }
                        $('#map_canvas').gmap('addMarker', { 'tag':tag, 'title':tag, 'bound':false, 'position': new google.maps.LatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random()) } );
                    }


                    $("#tags").change(function() {
                        var bounds = new google.maps.LatLngBounds();
                        var tag = $(this).val();
                        if ( tag == 'all' ) {
                            $('#map_canvas').gmap('findMarker', 'tag', tag, function(found, marker) {
                                marker.setVisible(true); 
                                bounds.extend(marker.position);
                                marker.map.fitBounds(bounds);   
                            });
                        } else {
                            $('#map_canvas').gmap('findMarker', 'tag', tag, function(found, marker) {
        开发者_StackOverflow社区                        if (found) {
                                    marker.setVisible(true); 
                                    bounds.extend(marker.position);
                                    marker.map.fitBounds(bounds);
                                } else { 
                                    marker.setVisible(false); 
                                }
                            });
                        }
                        $('#map_canvas').gmap('option', 'center', bounds.getCenter());
                    });

But I couldn't figure out how to add these tags to the kml, so I decided I would try to use the tag thats already in there to filter.

Anyone know how to target items using a styleURL reference instead? I tried targetting an id instead of tag but that doesnt seem to work. e.g.

var tag = $(this).id(); 

Would be grateful for any help please! Either in referencing from styleURL or where to place tags in KML for them to act the same as putting em in through the code.

Thanks in advance

leapin


As far as I know there is no way to do this in the current Google Maps v3.6 API (using KMLLayer), to make it work you'd have to parse the KML yourself and then loop through it and add the markers with a tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜