Skip to content

Instantly share code, notes, and snippets.

@raykendo
raykendo / arcgis-jsapi-ondrawbegin.js
Last active August 29, 2015 14:21
ArcGIS-JSAPI: DrawingToolbar hack for onDrawBegin
/*
* Making up for a missing "draw-begin" or "draw-start" event for the ArcGIS JavaScript API Drawing toolbar
*
* Problem: While the drawing toolbar in the ArcGIS JavaScript API has a "draw-end" and a "draw-complete"
* event, it doesn't have a "draw-start" or "draw-begin" event.
*
* Solution: Use a dojo/on pausable event that is only unpaused after the draw-end event.
*/
require(["esri/map", "dojo/on", "esri/toolbars/draw"], function (Map, dojoOn, Draw) {
var map = new Map("mapdiv", {});
@raykendo
raykendo / arcgis-jsapi-map-zoom-in-closer.js
Created May 29, 2015 21:08
ArcGIS JSAPI: Map with ESRI basemap zooming in closer than basemap allows.
require(["esri/Map"], function (Map) {
var map = new Map("mapdiv", {
basemap: "streets",
center: [-15.469, 36.428]
lods: [
//{
// level: 0,
// resolution: 156543.033928,
// scale: 591657527.591555
//},
@raykendo
raykendo / customMeasurementDijit.js
Last active August 29, 2015 14:23
ArcGIS JSAPI: Measurement + Popup Combo
/*
* Custom Measurement Widget extension that connects to Popup dijit (esri/dijit/Popup),
* retrieves the selected feature, then passes the geometry to be measured by the Measurement Dijit.
*/
define("custom.Measurement",
[
"dojo/_base/declare",
"dojo/_base/lang",
"esri/dijit/Measurement",
"dojo/query",
@raykendo
raykendo / georgeWashington.js
Last active November 17, 2015 16:16
George Washington - A user testing test
/**
* This script is a test to see whether the people who are supposed to be user testing your site are actually doing
* anything. It injects a piece of red text with content of George Washington somewhere in the document. It's designed
* to look for lowest hanging HTML dom nodes in the DOM tree (no children elements) that are visible (offsetParent is not null).
*/
(function () {
var nodes = Array.prototype.filter.call(document.querySelectorAll('div, p, span, blockquote, code, a, td'), function (node) {
return !(node.children && node.children.length) && node.offsetParent !== null;
});
if (nodes.length) {
@raykendo
raykendo / GetTimeStamp.js
Last active November 24, 2015 20:56
Dojo time stamp browser plugins
/**
* Gets a time stamp out of either localStorage, or a cookie session, if those are available.
* Use in conjunction with SetTimeStamp module.
* @module GetTimeStamp
* @param {string} id - string id you want to use to retrieve a time stamp from the browser
* @returns {Date} - Date of the last time stamp
*/
define(["dojo/cookie"], function (cookie) {
return {
load: function (id, require, callback) {
@raykendo
raykendo / UniqueComboBox.js
Last active December 8, 2015 23:17
David Walsh's Display Unique Combobox (https://davidwalsh.name/unique-combobox) updated for AMD
/**
* An update on David Walsh's Unique Combobox
* Updated for Dojo AMD (tested at v. 1.10)
* Originally posted: https://davidwalsh.name/unique-combobox
*/
define("davidwalsh.form._UniqueComboBoxMenu",
["dojo/_base/declare", "dojo/_base/array", "dijit/form/_ComboBoxMenu"],
function (declare, arrayUtils, _ComboBoxMenu) {
return declare([_ComboBoxMenu], {
createOptions: function (results, dataObject, labelFunc) {
@odoe
odoe / IndexedDBStore.js
Last active December 25, 2015 03:39
IndexedDBStore and PouchDBStorefor holding ArcGIS Features.
/*global define */
/*jshint browser:true, laxcomma:true, newcap:false*/
/** Heavily influenced by https://github.com/pjekel/indexedDB **/
define([
'dojo/Deferred',
'dojo/_base/declare',
'dojo/_base/array',
'dojo/store/util/QueryResults',
'dojo/store/util/SimpleQueryEngine'
], function (Deferred, declare, array, QueryResults, SimpleQueryEngine) {
@raykendo
raykendo / UrlSearchParameters.js
Created January 18, 2016 17:00
Dojo plugin to parse URL parameters and translate them to a where clause for an ArcGIS JavaScript API Query
/**
* A dojo plugin that extracts possible query parameters from the URL.
* @module search/UrlSearch
*/
define(["esri/urlUtils"], function (urlUtils) {
// regex for parameter names to ignore
var ignoreParameters = [
/^appid$/i, // ArcGIS Online uses appid parameter to define application id
/^folderid$/i, // ArcGIS Online uses folderid to define folder hash where webmap is stored
/^webmap$/i // ArcGIS Online uses webmap property to define the map to use in the application
@nickpeihl
nickpeihl / index.html
Last active January 27, 2016 23:24
San Juan County Aerials in Mapbox-GL.js
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.12.5/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.12.5/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
@raykendo
raykendo / PointWithin.js
Created February 1, 2016 16:29
Finding a point within a geometry for ArcGIS JavaScript API using client-side processing
define([
"dojo/_base/array",
"esri/geometry/Polygon",
"esri/geometry/Polyline",
"esri/geometry/Point",
"esri/geometry/geometryEngine"
], function (arrayUtils, Polygon, Polyline, Point, geometryEngine) {
/**
* Finds a point on a polyline