Skip to content

Instantly share code, notes, and snippets.

@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
View leaflet-geojson-identify.js
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);
@iwek
iwek / find-in-json.js
Created October 20, 2012 21:43
Searching through JSON
View find-in-json.js
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i] == val || i == key && val == '') { //
@ralphcrisostomo
ralphcrisostomo / array_dupplicate_counter.js
Created July 19, 2012 07:43
Javascript: Count duplicates in an array
View array_dupplicate_counter.js
/**
Problem:
You have a javascript array that likely has some duplicate values and you would like a count of those values.
Solution:
Try this schnippet out.
*/