Skip to content

Instantly share code, notes, and snippets.

@js1568
js1568 / L.TopoJSON.js
Last active August 29, 2015 13:57 — forked from rclark/L.TopoJSON.js
/*
You'll need something like this in your HTML:
<script src="http://d3js.org/topojson.v1.min.js"></script>
*/
L.TopoJSON = L.GeoJSON.extend({
addData: function(jsonData) {
if (jsonData.type === "Topology") {
for (key in jsonData.objects) {
geojson = topojson.feature(jsonData, jsonData.objects[key]);
@js1568
js1568 / leaflet-geojson-setoptions.js
Last active December 31, 2015 12:49
Extend L.GeoJson to allow changes to the Feature Group after creation. Useful for dynamic filtering and map layer event processing.
L.GeoJSON.include({
setOptions: function(opts) {
//save original json data
this._data = this._data || this.toGeoJSON();
//destory layer group
this.clearLayers();
L.setOptions(this, opts);
//recreate layer group
@js1568
js1568 / leaflet-geojson-identify.js
Last active December 20, 2015 11:39
Leaflet Identify function (similar to ESRI ArcGIS Javascript API function) for finding polygons based on a given latlng from in a L.GeoJson feature layer group.Requires Leaflet and geojson-js-utils: https://github.com/maxogden/geojson-js-utils
L.GeoJSON.include({
identify: function(latlng) {
var features = new L.FeatureGroup(),
geopoint = {
type: 'Point',
coordinates: [latlng.lng, latlng.lat]
};
this.eachLayer(function (layer) {
if (gju.pointInPolygon(geopoint, layer.feature.geometry)) {
features.addLayer(layer);