Skip to content

Instantly share code, notes, and snippets.

View pmacMaps's full-sized avatar

Patrick McKinney pmacMaps

View GitHub Profile
@pmacMaps
pmacMaps / style.css
Created June 18, 2018 18:28
Expanded Layer Widget with Legend for Esri Web AppBuilder
/* Introduction
CSS rules for the Layer widget is Esri's Web AppBuilder.
For layer widgets that are expanded on map load, legend items will show
with their symbols instead of a loading icon.
Place these style rules within the <style> tag of the index.html file.
Or, create a new style.css file and link to it in the index.html file
*/
/* Layer list expanded by default */
@pmacMaps
pmacMaps / index.html
Last active July 17, 2018 17:14
Add error message to Leaflet.js web map if an Esri service fails to load
<!-- error message modal -->
<div class="modal fade" id="layerErrorModal" tabindex="-1" role="dialog" aria-labelledby="layerErrorModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Error Adding Layers</h4>
</div>
<div id="erMsg" class="modal-body">
<h4 class="text-danger">Warning: One or more layers failed to load on the map!</h4>
@pmacMaps
pmacMaps / custom-tool.py
Last active July 17, 2018 14:58
Python module to use with ArcPy custom geoprocessing tools that provides an error message including system message, line number, and file of error
# this is the file where the logic for your custom tool goes
# import modules
# import errorLogger.py module
import arcpy, sys, errorLogger
# run your tool's code
try:
pass
# your code goes here
# If an error occurs running geoprocessing tool(s) capture error and write message
@pmacMaps
pmacMaps / ListBrokenDataSources.py
Created August 1, 2018 19:18
ArcPy Python script to list out broken data sources in an ArcMap document
#-------------------------------------------------------------------------------
# Name: Lesson 24 - Working With Multiple Maps In A Directory,
# Geospatial Programming
#
# Author: Patrick McKinney, Harrisburg Area Community College
#
# Created: 6/13/17
#
# Description: sample script for looping through a folder (directory)
# and listing broken data sources in each map document (.mxd)
@pmacMaps
pmacMaps / stop_start_services.py
Last active January 17, 2023 22:10
Start or Stop an ArcGIS Server Service (ArcPy Script)
# Sample script to start/stop ArcGIS Server service
# import modules
import arcpy, os, sys, time, datetime, urllib, urllib2, json
# generate token for server
def gentoken(server, port, adminUser, adminPass, expiration=60):
# Re-usable function to get a token required for Admin changes
query_dict = {'username': adminUser,
'password': adminPass,
@pmacMaps
pmacMaps / featured-image--jekyll-post-snippets.html
Last active April 19, 2020 12:49
Sample code for Jekyll Featured Image Template Blog Post
<!-- 1. Post File [2018-09-30-Sample-Post.md] -->
---
layout: post
title: A Sample Post
date: 2018-09-30
author: Mike the Blogger
description: This is the one blog post to rule them all
featured-image: my-awesome-photo.jpg
featured-image-alt: Mike the Blogger speaking at Times Square, New York City, New York
categories: Side Hustle
@pmacMaps
pmacMaps / esri-leaflet-map-service-load-test.js
Created February 1, 2019 17:05
Esri Leaflet Map Service Loaded to Map Function
// function to handle load event for map services
// See API reference at https://esri.github.io/esri-leaflet/api-reference/services/service.html#events
function processLoadEvent(service) {
// service request success event
service.on('requestsuccess', function(e) {
// set isLoaded property to true
service.options.isLoaded = true;
});
// request error event
# ---------------------------------------------------------------------------
# Name: Loop Through Layer "A" and Clip Features from Layer "B"
#
# Author: Patrick McKinney, Cumberland County GIS (pmckinney@ccpa.net or pnmcartography@gmail.com)
#
# Created on: 6/21/2019
#
# Description: This sample script provides a template for how to loop through a layer (A) and clip features
# from another layer (B) based upon each record in layer A.
#
@pmacMaps
pmacMaps / esri-storymap-map-tour-alt-text.js
Last active October 22, 2019 15:41
Add Alt Attribute to Images in Esri Map Tour StoryMap (Classic Series)
require(["dojo/topic"], function(topic) {
// default alt text to apply to images
const defaultAltText = 'a view along the Yellow Breeches Creek';
// function to set alt attribute for images
function setAltText(title,img) {
// use grouped text if slide title text exists
if (title) {
// grouped text
const groupedAltText = `${defaultAltText}; map tour stop: ${title}`;
@pmacMaps
pmacMaps / esri-storymap-map-tour-alt-text-ie11.js
Created October 22, 2019 15:38
Add Alt Attribute to Images in Esri Map Tour StoryMap (Classic Series). Code is supported in IE11
require(["dojo/topic"], function(topic) {
// default alt text to apply to images
const defaultAltText = 'a view along the Yellow Breeches Creek';
// function to set alt attribute for images
function setAltText(title,img) {
// use grouped text if slide title text exists
if (title) {
// grouped text
const groupedAltText = "".concat(defaultAltText, "; map tour stop: ").concat(title);