Skip to content

Instantly share code, notes, and snippets.

View dbouwman's full-sized avatar
😎
Hubbin it up @ Esri

Dave Bouwman dbouwman

😎
Hubbin it up @ Esri
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="MapService Layer as Feature Layer w/ min/max scale hack" />
<title>Create a Map</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="http://js.arcgis.com/3.8/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
<style>
@dbouwman
dbouwman / FeatueLayerScaleHack.js
Last active January 2, 2016 18:59
Example of how to work around min/max scale on feature layers
require(["esri/map",
"esri/layers/FeatureLayer",
"dojo/domReady!"],
function(Map, FeatureLayer) {
map = new Map("mapDiv", {
center: [-111.8, 40.7],
zoom: 3,
basemap: "gray"
});
@dbouwman
dbouwman / Response.json
Created January 11, 2014 01:21
Request to http://localhost:3000/datasets.json?q=france&page=0&per_page=10&sort_by=relevance&sort_order=desc
{
"data": [
{
"id": "fc3c6495a3734e41b176562deae87319_0",
"item_id": "fc3c6495a3734e41b176562deae87319",
"name": "Agences_Sites",
"description": "Agences Esri France (secteurs g??ographiques et localisation des agences)",
"url": "http://services.arcgis.com/d3voDfTFbHOCRwVR/arcgis/rest/services/Agences_ESRI_France_WM/FeatureServer/0",
"fields": [
{
@dbouwman
dbouwman / parse-json.spec.js
Created January 12, 2014 14:32
Spec showing loading json from a fixture
describe('loads itself from json', function () {
var model, fisherJson, json;
beforeEach(function() {
json = getJSONFixture('entities/Dataset/dataset.json');
model = new Composer.Models.Dataset({id:'a0818dca49bf4d5badd7d2b0fcbb51c9_5'});
model.loadFromJson(json);
});
it('sets the version', function() {
expect(model.get('current_version')).toEqual(json.data.current_version);
@dbouwman
dbouwman / ajax-mock.spec.js
Created January 12, 2014 14:34
Using a mock to test the full fetch method, without a server
describe('loads itself from the service', function () {
beforeEach(function() {
json = getJSONFixture('entities/Dataset/dataset.json');
var response = {
status: 200,
responseText: JSON.stringify(json)
};
jasmine.Ajax.useMock();
model = new Composer.Models.Dataset({id:json.data.id});
model.fetch();
@dbouwman
dbouwman / constructor.spec.js
Created January 12, 2014 14:49
Testing a constructor
describe('constructor', function () {
it('throws without an id', function() {
//this is sligtly obtuse formatting, but expect() requires a function
//and new Something is not a function, so we wrap it.
expect(function(){var m = new Composer.Models.Dataset();}).toThrow();
});
it('does not throw with an id', function() {
var f = function(){
@dbouwman
dbouwman / App-Navigate.js
Created January 28, 2014 03:28
Application.navigate function with logging
//App.navigate should be called over direct calls to the Backbone.history object
navigate: function(route, options){
//log the pageview
this.logPageView(route);
var ops = options || {};
//store the previous route
this._previousRoute = this.getCurrentRoute();
//call the underlying backbone method
Backbone.history.navigate(route, ops);
},
@dbouwman
dbouwman / logPageView.js
Created January 28, 2014 03:30
logPageView method
/**
* Wrapper that allows us to log pageviews
* in our SPA
*/
logPageView: function(route){
//check if google analytics is loaded
if(window.ga){
//send the pageview details
ga('send','pageview', route);
}
@dbouwman
dbouwman / logUiEvent.js
Created January 28, 2014 03:33
logUiEvent method
/**
* Wrapper to send Events to Google Analytics
* @param {string} action Action we are logging. lower-case
* @param {string} category standardized event categories
* @param {string} label optional description
*/
logUiEvent: function(action, category, label){
var lb = label || '';
//check for google analytics
if(window.ga){
@dbouwman
dbouwman / map-control-view.js
Created February 7, 2014 03:57
Map Controls view with calls to log the event
Composer.module('MapBarModule.Controls', function (Controls, App, Backbone, Marionette, $, _) {
//Controls item view
Controls.View = Backbone.Marionette.ItemView.extend({
model: Controls.Model,
template: 'mapbar/controls/controls_view',
className: 'mapbar-controls',
events: {
"click .type": "_changeBasemap"
},