Skip to content

Instantly share code, notes, and snippets.

@eduardo-matos
eduardo-matos / analytics.js
Last active June 13, 2016 14:48
Loading Google Analytics using Dojo Toolkit (1.8+)
require([
'dojo/request/script'
], function(
script
) {
'use strict';
var _gaq = window._gaq = window._gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
@raykendo
raykendo / example.js
Created March 30, 2016 17:17
Quick and Dirty show Date from feature
require(["esri/map", "esri/layers/FeatureLayer", "esri/tasks/query"], function (map, FeatureLayer, query) {
var features = [/* assume a list of feature graphics will be assigned here soon */];
// do stuff to assign maps, feature layers, etc.
// do stuff to assign features as a list of search results from a feature layer
var importantDates = features.map(function (feature) {
if (feature.attributes["ImportantDate"] !== null) {
return new Date(feature.attributes["ImportantDate"]);
}
});
@raykendo
raykendo / UTCToMyDateTime.js
Last active March 29, 2016 15:48
UTC to current time zone converter
/*
* Dojo AMD helper function to convert dates stored as UTC milliseconds from January 1, 1970 to a date/time format more fitting
* for current location.
* Reason: ArcGIS Server stores dates without times as midnight UTC. When those times are translated into real dates,
* the browser often corrects the date for time zone differences, moving the date back several hours in the U.S.
*/
/* globals define */
define(function () {
var oneDay = 24 * 60 * 60 * 1000;
/**
@raykendo
raykendo / LayerListModified.js
Last active March 24, 2016 14:48
ArcGIS JSAPI Hack: LayerList fixes
define([
"dojo/_base/declare",
"dojo/_base/array",
"dojo/query",
"put-selector/put",
"esri/dijit/LayerList"
], function (declare, arrayUtils, dojoQuery, put, LayerList) {
return declare([LayerList], {
@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
@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 / 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
@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 / 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) {
@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) {