Skip to content

Instantly share code, notes, and snippets.

@geog4046instructor
geog4046instructor / arcgis-simple-map.js
Last active January 1, 2018 23:02
ArcGIS JavaScript API - Simple map
/* Create a simple map with the ArcGIS JavaScript API.
* example: http://developers.arcgis.com/javascript/samples/map_simple/
*/
require([
"esri/map", // modules need to be added to this list before dojo/domReady, separated by a comma and enclosed in quotation marks
"dojo/domReady!"
], function (
Map // the names of functions corresponding to the modules need to be added to this list, separated by a comma
) {
let map = new Map("map", {
@geog4046instructor
geog4046instructor / arcgis-add-layer.js
Last active January 1, 2018 22:59
ArcGIS JavaScript API - add a layer
/* Add layer(s) from an ArcGIS web service
*
* function name: ArcGISDynamicMapServiceLayer
* module name: "esri/layers/ArcGISDynamicMapServiceLayer"
* documentation: https://developers.arcgis.com/javascript/jssamples/map_dynamic.html
* example: http://developers.arcgis.com/javascript/samples/map_dynamic/
*/
// Create a layer object from an ArcGIS Server web service, with no options
let layer1 = new ArcGISDynamicMapServiceLayer( "http://example.com/arcgis/rest/services/Layer1/MapServer" );
@geog4046instructor
geog4046instructor / arcgis-basemap-toggle.js
Last active January 1, 2018 22:58
ArcGIS JavaScript API - Basemap toggle
/* Adds a map control to select a basemap. Requires a div with id="basemap-toggle" inside the map div.
*
* function name: BasemapToggle
* module name: "esri/dijit/BasemapToggle"
* documentation: https://developers.arcgis.com/javascript/jssamples/widget_toggle.html
* example: http://developers.arcgis.com/javascript/samples/widget_toggle/
*/
let toggle = new BasemapToggle({
map: map,
@geog4046instructor
geog4046instructor / google-simple-map.js
Last active April 17, 2017 02:51
Google Maps API - Simple map
/* Create a basic map with the Google Maps JavaScript API.
* documentation: https://developers.google.com/maps/documentation/javascript/examples/map-simple
*/
var map;
function initMap() {
map = new google.maps.Map( document.getElementById( 'map' ), {
center: { lat: 30, lng: -90 },
zoom: 4
});
@geog4046instructor
geog4046instructor / google-add-kml.js
Last active January 1, 2018 22:49
Googla Maps API - Add a KML layer
/* Add layer(s) from an online KML or KMZ file
*
* function: google.maps.KmlLayer
* documentation: https://developers.google.com/maps/documentation/javascript/examples/layer-kml
*/
let kml = new google.maps.KmlLayer({
url: 'http://example.com/layer1.kmz',
preserveViewport: true // setting to true will prevent the map from zooming to this layer
});
@geog4046instructor
geog4046instructor / leaflet-external-geojson.js
Last active April 18, 2017 12:48
Leaflet - Get external GeoJSON
/* Get GeoJSON data from an external website using jQuery's getJSON function.
*
* function: getJSON
* documentation: http://api.jquery.com/jquery.getjson/
*
* See the Leaflet documentation on using GeoJSON
* http://leafletjs.com/examples/geojson/
*/
jQuery.getJSON( "http://example.com/layer1.geojson", function( geojsonFeature ) {
@geog4046instructor
geog4046instructor / arcgis-css-basemap.css
Last active January 1, 2018 22:47
ArcGIS JavaScript API - CSS for a basemap toggle control
/* Resize and position the basemap control on an ArcGIS map. Requires a #basemap-toggle div inside of the #map div */
#basemap-toggle {
position: absolute;
top: 60px;
right: 20px;
z-index: 50;
}
@geog4046instructor
geog4046instructor / bootstrap-full-background.css
Last active January 1, 2018 22:46
Bootstrap 3 - Full-page background image
/* For Bootstrap 3. Create a full-page background image on the Bootstrap "Cover" template
* Cover template: https://getbootstrap.com/examples/cover
* CSS code credit: http://stackoverflow.com/questions/25556622/bootstrap-cover-template-where-to-place-image
*/
body {
background: url(../img/background.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
@geog4046instructor
geog4046instructor / google-geojson-popup.js
Last active June 16, 2022 16:01
Add a GeoJSON layer with a popup showing feature attributes with the Google Maps API
/* This example demonstrates how to create a popup, or an "infowindow", from
* GeoJSON data (USGS earthquake feed). "place" and "mag" are the names of properties in the GeoJSON file.
* This code can be placed before or after other code for adding layers.
*/
map.data.loadGeoJson('http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson');
// Create an infowindow object to use later
var infowindow = new google.maps.InfoWindow();
/* Create a "listener" that will wait for the user to click an earthquake point,
@geog4046instructor
geog4046instructor / javascript-insert-year.js
Last active March 30, 2017 00:20
Insert the current year into a page
/* Print the year in the format YYYY between any HTML tags with class="current-year"
*/
var currentYear = new Date().getFullYear()
jQuery( ".current-year" ).text( currentYear )