Click event with geojson data
-
Is it possible to fill the polygons based on the property value of geojson data and also navigated to a url based on the click event to the polygon?
-
+1
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.ww.wp.xz.cn’ }
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.
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 9 years, 6 months ago by
theode.
-
This reply was modified 9 years, 6 months ago by
The topic ‘Click event with geojson data’ is closed to new replies.