Skip to content

Instantly share code, notes, and snippets.

@raykendo
raykendo / ArcGIS-JSAPI-MapClickByQueryHack.md
Last active Jul 6, 2018
ArcGIS-JSAPI: Clicking on a webmap without clicking on a webmap
View ArcGIS-JSAPI-MapClickByQueryHack.md

Clicking on a map without clicking on a map

An ArcGIS JavaScript API hack

Purpose: I have a map application with a list of results from a query. When I click on one of the items in the result list, I wanted the map to zoom to the associated feature, and trigger a click that shows the result in a popup.

Library: ArcGIS JavaScript API

Version: tested on versions 3.9-3.13.

@raykendo
raykendo / arcgis-jsapi-ondrawbegin.js
Last active Aug 29, 2015
ArcGIS-JSAPI: DrawingToolbar hack for onDrawBegin
View arcgis-jsapi-ondrawbegin.js
/*
* 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
ArcGIS JSAPI: Query Distinct, the old fashion way.
View gist:31fb197a3f1a1ba52a6f
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
ArcGIS JSAPI: Query Return Distinct - Quick and Dirty (V. < 3.11)
View gist:507839766456f90e76d6
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 Aug 29, 2015
ArcGIS JSAPI: Query Return Distinct - Precallback Request (V < 3.11)
View gist:a107b9417d62839a02c5
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
ArcGIS JSAPI: Map with ESRI basemap zooming in closer than basemap allows.
View arcgis-jsapi-map-zoom-in-closer.js
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 Jun 4, 2015
ArcGIS Server Tiled Map Service conf.xml for ESRI/Google/Bing Map Scales + 1:500 and 1:250-ish scales
View conf.xml
<?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 Jun 9, 2015
ArcGIS JSAPI: AGOL Webmap with extra zoom levels
View arcgis-jsapi-webmap-extra-zoom-levels.js
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 Aug 29, 2015
ArcGIS JSAPI: Measurement + Popup Combo
View customMeasurementDijit.js
/*
* 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 / BigQueryTask.js
Last active Jul 4, 2018
ArcGIS JSAPI Hack - Getting around the 1000 results limit for queries
View BigQueryTask.js
/** globals define */
define([
"dojo/_base/declare",
"dojo/Deferred",
"esri/tasks/query",
"esri/tasks/QueryTask",
"esri/request"
], function (
declare, Deferred, Query, QueryTask, esriRequest
) {