I have been attempting to develop some methodology or approach in order to monitor or track where users of our web map services are looking. Ideally the coordinates of the window.
Mapbox has created a very powerful approach to monitor statistics and locate areas that users are viewing.
I am looking to implement something similar on my ArcGIS Server in order to see where users are viewing the most. This way I can better densify the data in areas that are of the most interest.
So far I have utilized the Map Index Toolbox (I have lost the original link to the toolbox - but the python code for it is below)
"""
Script Name: Map_Index.py
https://bitbucket.org/npeihl/mapindextool
Description: ArcGIS Tool written in Python. The Map Index Tool creates a geographic index of all ArcMap documents (MXDs) in a folder supplied by the user. For each MXD, the tool finds the largest dataframe on the Layout view and sends the extent of that dataframe to a shapefile in the folder (map_index.shp). Tested on ArcGIS Desktop version 10. Not tested and likely not working on ArcGIS Desktop versions 9.3.1 and below.
WARNING: This tool will destroy and overwrite any shapefile named map_index within the supplied folder. Please use with caution.
Author: Nicholas Peihl
Email: [email protected]
Last Modified: 04/20/2011
"""
import arcpy
import os, sys
from datetime import datetime
from time import strftime
wp = arcpy.GetParameterAsText(0)
spatialRef = arcpy.GetParameterAsText(1)
fcName = "map_index.shp"
scriptPath = sys.path[0]
arcpy.AddMessage("Script path is %s" % scriptPath)
toolDataPath = os.path.join(scriptPath, "ToolData")
fcTemplate = os.path.join(toolDataPath, "map_index_template.shp")
arcpy.env.workspace = wp
files = arcpy.ListFiles("*.mxd")
if len(files) == 0:
arcpy.AddError("No ArcMap Documents were found in this folder. Please try another folder.")
else:
if arcpy.Exists(os.path.join(wp, fcName)):
arcpy.AddWarning("Existing Map Index shapefile found. Deleting the old index file.")
arcpy.Delete_management(fcName)
arcpy.AddMessage("Creating the new Map Index shapefile")
index = arcpy.CreateFeatureclass_management(wp, fcName, "POLYGON", fcTemplate,"","", spatialRef)
for mxd in files:
mxd = wp + "\\" + mxd
arcpy.AddMessage("Opening map document %s" % mxd)
mapDoc = arcpy.mapping.MapDocument(mxd)
dataframes = arcpy.mapping.ListDataFrames(mapDoc)
if len(dataframes) == 1:
pFrame = dataframes[0]
else:
max = 0
for frame in dataframes:
size = frame.elementWidth * frame.elementHeight
if size > max:
pFrame = frame
max = size
xmin = pFrame.extent.XMin
ymin = pFrame.extent.YMin
xmax = pFrame.extent.XMax
ymax = pFrame.extent.YMax
framespatialRef = pFrame.spatialReference
coords = [xmin,ymin],[xmax,ymin],[xmax,ymax],[xmin, ymax]
point = arcpy.Point()
array = arcpy.Array()
for coord in coords:
point.X = coord[0]
point.Y = coord[1]
array.append(point)
polygon = arcpy.Polygon(array, framespatialRef)
arcpy.AddMessage("Adding the extent of %s to the index." % mxd)
rows = arcpy.InsertCursor(index, spatialRef)
row = rows.newRow()
row.PATH = mapDoc.filePath
row.TITLE = mapDoc.title
row.AUTHOR = mapDoc.author
row.LASTSAVED = mapDoc.dateSaved
row.LASTUPDATE = datetime.strftime(datetime.now(),"%Y-%m-%d")
row.SHAPE = polygon
rows.insertRow(row)
del row
del rows
The result is a max/min window of all mxd projects created for the year. This result is excellent for all map driven requests. However, it does not deal with online mapping or demand.
What I am looking for: any toolset or methodology that will be able to monitor my Map Services for both Raster Types and Feature Types.
MY CURRENT STACK:
Back-end
- ArcGIS For Server 10.3.1
- ArcGIS Desktop 10.3.1
Front-end
- WebAppBuilder
- Developer WebAppBuilder
- ESRI Leaflet API (if needed)
UPDATE I have begun to tweak some basic ESRI JS code to add to WebAppBuilder
I have a fiddle that I am working with as of right now that simply builds out the extent of the viewing window. I am wondering if anyone knows a way to capture the XMin,YMin,XMax,YMax and write that data to some database (preferably a shapefile or SQL Database)
The code to capture the XMin,YMin,XMax,YMax is below:
dojo.require("esri.map");
function init() {
var initialExtent = new esri.geometry.Extent({"xmin":244598,"ymin":6241389,"xmax":278995,"ymax":6264320,"spatialReference":{"wkid":102100}});
var map = new esri.Map("map", {
basemap: "streets",
extent: initialExtent
});
dojo.connect(map, "onExtentChange", showExtent);
}
function showExtent(extent) {
var s = "";
s = "XMin: "+ extent.xmin.toFixed(2) + " "
+"YMin: " + extent.ymin.toFixed(2) + " "
+"XMax: " + extent.xmax.toFixed(2) + " "
+"YMax: " + extent.ymax.toFixed(2);
dojo.byId("info").innerHTML = s;
}
dojo.ready(init);