Skip to content

Instantly share code, notes, and snippets.

View jgravois's full-sized avatar

john gravois jgravois

View GitHub Profile
@jgravois
jgravois / gist:6090713
Created July 26, 2013 17:36
reprojected dynamic map service layer.
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Map Services</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.3/leaflet.css" />
<link rel="stylesheet" href="demo.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="leaflet/leaflet.ie.css" /><![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.6.3/leaflet.js"></script>
<script src="http://gravois/leaflet/esri-leaflet.min.js"></script>
@jgravois
jgravois / gist:6802432
Last active December 24, 2015 13:09
anatomy of AMD module loading
require([
"esri/map", "esri/InfoTemplate", "esri/layers/FeatureLayer",
"dojo/parser", "dojo/domReady!"
], function( //Beginning of anonymous callback which fires when modules have been loaded.
Map, InfoTemplate, FeatureLayer,
parser //Variable names to refer to loaded modules
) {
parser.parse(); //first line of actual callback code
map = new Map("mapDiv", {
basemap: "national-geographic",
@jgravois
jgravois / gist:6802514
Last active December 24, 2015 13:09
load comparison
//legacy
dojo.require(“esri.layers.FeatureLayer”);
var featureLayer = new esri.layers.FeatureLayer("url");
//AMD
require([
"esri/map", … "esri/layers/FeatureLayer"
], function(
Map, …, FeatureLayer,
@jgravois
jgravois / gist:6802612
Last active December 24, 2015 13:09
dojo vs. dom
dojo.byId("messages").innerHTML = "howdy"; //legacy
//becomes
dom.byId("messages").innerHTML = "why, hello there"; //AMD
@jgravois
jgravois / gist:7685198
Created November 28, 2013 00:04
loop through response fields and find 'esriFieldTypeOID' instead of pulling information from response.objectIdFieldName (which is only present in a response from FeatureServer layer.
if(response.features.length && !response.error){
//loop through fields returned by service
for (var j = response.fields.length - 1; j >= 0, j--) {
//find field with type 'esriFieldTypeOID' and use its name as an attribute when converting to GeoJSON
if(response.fields[j].type == "esriFieldTypeOID")
var idKey = response.fields[j].name
}
for (var i = response.features.length - 1; i >= 0; i--) {
var feature = response.features[i];
var id = feature.attributes[idKey];
@jgravois
jgravois / gist:8404339
Last active January 13, 2016 18:59
this is a gist to remind john and matt how to query for the maximum value in a field manually (since the JS api doesnt have any tools to limit query results)
use outStatistics
http://services.arcgis.com/OfH668nDRN7tbJh0/arcgis/rest/services/My_Walks/FeatureServer/0/query?where=1%3D1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&geohash=&inSR=&spatialRel=esriSpatialRelIntersects&distance=&units=esriSRUnit_Meter&outFields=&returnGeometry=false&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnDistinctValues=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=%5B%7B%0D%0A++++%22statisticType%22%3A+%22max%22%2C%0D%0A++++%22onStatisticField%22%3A+%22WHEN%22%0D%0A%7D%5D&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&quantizationParameters=&f=pjson&token=
// not the old hack you used with driskull
FIELD=(SELECT MAX(FIELD) FROM TABLE)
http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3/query?where=POP2007=(SELECT MAX(POP2007) FROM states)&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIn
@jgravois
jgravois / solarTerminator.js
Created April 25, 2014 23:01
solarTerminator.js
var sun = new SolarTerminatorLayer({
map: map // (required) map object. default: null.
}, "SunButton"); //div for the widget
sun.startup();
@jgravois
jgravois / amd-loader-options.html
Last active August 29, 2015 14:03
a few different examples of providing dojo AMD loader configuration options
//sometimes we see..
<script>var dojoConfig = { async: true };</script>
<script src="http://js.arcgis.com/3.10/"></script>
//or maybe..
<script data-dojo-config="async:true" src="http://js.arcgis.com/3.10/">
</script>
<script src="http://js.arcgis.com/3.10/"></script>
<script>
var dojoConfig = {
async:true,
cacheBust:new Date(),
waitSeconds:5,
isDebug:true,
useDeferredInstrumentation:true
};
</script>