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 / gist:31fb197a3f1a1ba52a6f
Created May 25, 2015 05:48
ArcGIS JSAPI: Query Distinct, the old fashion way.
require([..., "esri/tasks/query", "esri/tasks/QueryTask", "dojo/_base/array",...],
function (..., Query, QueryTask, arrayUtils,...) {
...
// urls faked to protect the innocent kitties
var qTask = new QueryTask("http://www.cat-hurders.com:6080/arcgis/rest/services/CatSightings/MapServer/"),
query = new Query();
// set up the parameters to query for the breeds
query.where = "1=1";
query.outFields = ["breed"];
query.returnGeometry = false;
@raykendo
raykendo / gist:507839766456f90e76d6
Created May 25, 2015 05:52
ArcGIS JSAPI: Query Return Distinct - Quick and Dirty (V. < 3.11)
require(["esri/tasks/QueryTask"], function (QueryTask) {
var url = "http://www.cat-hurders.com:6080/arcgis/rest/services/CatSightings/MapServer/",
qTask = new QueryTask(url + "?returnDistinctValues=true");
//...
});
@raykendo
raykendo / gist:a107b9417d62839a02c5
Last active August 29, 2015 14:21
ArcGIS JSAPI: Query Return Distinct - Precallback Request (V < 3.11)
require(["esri/request"], function (esriRequest) {
esriRequest.setRequestPreCallback(function(ioArgs){
// test if we're sending the request to a mapservice query
if(/query\/?$/.test(ioArgs.url)){
// if not requesting ObjectIds, count, or querying with a list of ObjectIDs, return distinct values.
if (ioArgs.content && !ioArgs.content.returnIdsOnly && !ioArgs.content.returnCountOnly && !ioArgs.content.objectIds) {
ioArgs.content.returnDistinctValues = true;
}
}
return ioArgs;
@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 / conf.xml
Created June 4, 2015 19:35
ArcGIS Server Tiled Map Service conf.xml for ESRI/Google/Bing Map Scales + 1:500 and 1:250-ish scales
<?xml version="1.0" encoding="utf-8" ?>
<CacheInfo xsi:type='typens:CacheInfo' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/10.1'>
<TileCacheInfo xsi:type='typens:TileCacheInfo'>
<SpatialReference xsi:type='typens:ProjectedCoordinateSystem'>
<WKT>PROJCS[&quot;WGS_1984_Web_Mercator_Auxiliary_Sphere&quot;,GEOGCS[&quot;GCS_WGS_1984&quot;,DATUM[&quot;D_WGS_1984&quot;,SPHEROID[&quot;WGS_1984&quot;,6378137.0,298.257223563]],PRIMEM[&quot;Greenwich&quot;,0.0],UNIT[&quot;Degree&quot;,0.0174532925199433]],PROJECTION[&quot;Mercator_Auxiliary_Sphere&quot;],PARAMETER[&quot;False_Easting&quot;,0.0],PARAMETER[&quot;False_Northing&quot;,0.0],PARAMETER[&quot;Central_Meridian&quot;,0.0],PARAMETER[&quot;Standard_Parallel_1&quot;,0.0],PARAMETER[&quot;Auxiliary_Sphere_Type&quot;,0.0],UNIT[&quot;Meter&quot;,1.0],AUTHORITY[&quot;EPSG&quot;,3857]]</WKT>
<XOrigin>-20037700</XOrigin>
<YOrigin>-30241100</YOrigin>
<XYScal
@raykendo
raykendo / arcgis-jsapi-webmap-extra-zoom-levels.js
Created June 9, 2015 05:32
ArcGIS JSAPI: AGOL Webmap with extra zoom levels
require(["esri/arcgis/utils"], function (arcgisUtils) {
// borrowed webmap id from https://developers.arcgis.com/javascript/jsapi/esri.arcgis.utils-amd.html#createmap
arcgisUtils.createMap("c41d5f3b4e304806a047702fbfc2759e", "mapdiv", {
usePopupManager: true, // just tossed this in there to show other webmap options
mapOptions: {
basemap: "streets",
center: [-15.469, 36.428]
lods: [
//{
// level: 0,
@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 / pouchdb_and_jsapi.html
Created November 23, 2015 21:19
Quick and simple way to add Pouch DB to ArcGIS JavaScript API
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Simple Map</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;