Viewing 3 replies - 1 through 3 (of 3 total)
  • +1

    Plugin Author bozdoz

    (@bozdoz)

    Both are definitely possible. I like the color attribute idea (like geojson.io), but the click events seem too difficult to create. What did you have in mind for click handlers? Would that be an attribute also? Something like { onClick: ‘https://www.www.ads-software.com’ }

    Also, beyond the ability to make this work, I doubt it would be good for User Experience, unless it was obvious to the user that clicking a shape would take them to a new page.

    theode

    (@theode)

    I got that…
    added to the geosjon shortcode website and onEachFeature. Just add a website=”” to your shortcode.

     $geojson_script = "<script>
                    WPLeafletMapPlugin.add(function () {
                        var map_count = {$leaflet_map_count},
                            previous_map = WPLeafletMapPlugin.maps[ map_count - 1 ],
                            src = '{$src}',
                            color = '{$color}',
                            weight = '{$weight}',
                            website = '{$website}',
                            opacity = '{$opacity}',
                            layer = L.ajaxGeoJson( src, {
                                color : color,
                                weight : weight,
                                website: website,
                                opacity : opacity,
                                onEachFeature: onEachFeature,
                            }),
                            fitbounds = {$fitbounds};
                                
                        layer.addTo( previous_map );
    					
                        if (fitbounds) {
                            layer.on('ready', function () {
                                this.map.fitBounds( this.getBounds() );
                            });
                        }
                        
    					function onEachFeature(feature, layer) {
    						layer.on('click', function (e) {
    							website = e.target.options.website;
    						  	window.location.href = website;
      							 abort;
    						});
    
    					}
    
    					
                    });</script>";
    • This reply was modified 8 years ago by theode.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Click event with geojson data’ is closed to new replies.