Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Last active June 7, 2016 19:44
Show Gist options
  • Save netsi1964/327d9714bdb451d4dc6dc425fcfb74c7 to your computer and use it in GitHub Desktop.
Save netsi1964/327d9714bdb451d4dc6dc425fcfb74c7 to your computer and use it in GitHub Desktop.
Peeking around the Apple MapKit javascript object

Get a JSON version of any browser object

Version 0.82

I am a curious sole, and when I saw that Apple had a map I wanted to see the API of it (at the time of writing it is not official). I wrote this litle script which should be executed in the developer toolbar. It allows you to get json object of the properties, functions, methodes an structur of any javascript object.

Please do use it and please put GISTs of the objects you convert to JSON. May I suggest that you name them the name that is autogenerated from the script.

mapkit becomes mapkitAsJSON.json

Share your JSON objects with #asjson

Wouldnt it be a great idea to share the gists you make on twitter using the hashtag asjson:-)

You may tweet to me with comments: @netsi1964

To-dos

  • Make conversion recurisive
  • Better function parameters detection
  • Perhaps better output, as markdown?
  • Perhaps option to push output to node.js service on heroku - perhaps even make a "canIUse" lookup of javascript objects so that we have a general repository of known javascript browser objects :-) (help needed!)

Started: 7. jun. 2016 Updateded: 7. jun. 2016, 21.44

{
"OBJ2JSON": {
"version": 0.82,
"date": "2016-06-07T19:43:52.712Z",
"navigator": "5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36",
"info": "https://gist.github.com/netsi1964/327d9714bdb451d4dc6dc425fcfb74c7",
"url": "https://developer.apple.com/wwdc/attending/"
},
"init": "function(a,b)",
"version": "3.1.1",
"build": "16.18-5",
"language": "da",
"addEventListener": "function()",
"removeEventListener": "function()",
"toString": "function()",
"_tileProvider": "Apple",
"_countryCode": "DK",
"_restore": "function()",
"_environment": "MapsWebProd",
"debugInfoForMap": "function(a)",
"CoordinateRegion": {
"constructor": "function",
"copy": "property",
"toString": "function",
"toBoundingRegion": "property",
"toMapRect": "property"
},
"CoordinateSpan": {
"constructor": "function",
"copy": "property",
"toString": "function"
},
"Coordinate": {
"constructor": "function",
"copy": "property",
"toMapPoint": "property",
"toUnwrappedMapPoint": "property",
"toString": "function"
},
"BoundingRegion": {
"constructor": "function",
"copy": "property",
"toString": "function",
"toCoordinateRegion": "property"
},
"MapPoint": {
"constructor": "function",
"toString": "function",
"copy": "property",
"equals": "property",
"toCoordinate": "property"
},
"MapRect": {
"constructor": "function",
"toString": "function",
"copy": "property",
"equals": "property",
"minX": "property",
"minY": "property",
"midX": "property",
"midY": "property",
"maxX": "property",
"maxY": "property",
"scale": "property",
"toCoordinateRegion": "property"
},
"MapSize": {
"constructor": "function",
"toString": "function",
"copy": "property",
"equals": "property"
},
"Padding": {
"constructor": "function",
"toString": "function",
"copy": "property",
"equals": "property"
},
"Style": {
"constructor": "function",
"strokeColor": "property",
"strokeOpacity": "property",
"lineWidth": "property",
"lineCap": "property",
"lineJoin": "property",
"lineDash": "property",
"lineDashOffset": "property",
"fillColor": "property",
"fillOpacity": "property",
"fillRule": "property"
},
"CircleOverlay": {
"constructor": "function",
"coordinate": "property",
"radius": "property",
"style": "property",
"map": "property",
"data": "property",
"visible": "property",
"enabled": "property",
"selected": "property"
},
"PolylineOverlay": {
"constructor": "function",
"points": "property",
"style": "property",
"map": "property",
"data": "property",
"visible": "property",
"enabled": "property",
"selected": "property"
},
"PolygonOverlay": {
"constructor": "function",
"points": "property",
"style": "property",
"map": "property",
"data": "property",
"visible": "property",
"enabled": "property",
"selected": "property"
},
"_CustomOverlay": {
"constructor": "function",
"needsDisplay": "property",
"boundingRectAtScale": "property",
"drawInContext": "property",
"map": "property",
"data": "property",
"visible": "property",
"enabled": "property",
"selected": "property"
},
"Geocoder": {
"constructor": "function",
"lookup": "property",
"reverseLookup": "property",
"getsUserLocation": "property",
"language": "property",
"cancel": "property"
},
"Search": {
"constructor": "function",
"coordinate": "property",
"region": "property",
"search": "property",
"autocomplete": "property",
"getsUserLocation": "property",
"language": "property",
"cancel": "property"
},
"Directions": {
"constructor": "function",
"route": "property",
"getsUserLocation": "property",
"language": "property",
"cancel": "property"
},
"Map": {
"constructor": "function",
"padding": "property",
"scrollable": "property",
"zoomable": "property",
"showsZoomControl": "property",
"zoomControlPlacement": "property",
"mapType": "property",
"showsMapTypeControl": "property",
"showsUserLocationControl": "property",
"userLocationControlPlacement": "property",
"showsPointsOfInterest": "property",
"element": "property",
"visibleMapRect": "property",
"setVisibleMapRectAnimated": "property",
"region": "property",
"setRegionAnimated": "property",
"center": "property",
"setCenterAnimated": "property",
"overlays": "property",
"selectedOverlay": "property",
"addOverlay": "property",
"addOverlays": "property",
"removeOverlay": "property",
"removeOverlays": "property",
"annotations": "property",
"selectedAnnotation": "property",
"addAnnotation": "property",
"addAnnotations": "property",
"removeAnnotation": "property",
"removeAnnotations": "property",
"showAnnotations": "property",
"showItems": "property",
"annotationsInMapRect": "property",
"updateSize": "property",
"convertCoordinateToPointOnPage": "property",
"convertPointOnPageToCoordinate": "property",
"showsUserLocation": "property",
"userLocationAnnotation": "property",
"tracksUserLocation": "property",
"tintColor": "property",
"destroy": "property"
},
"Annotation": {
"constructor": "function",
"map": "property",
"coordinate": "property",
"title": "property",
"subtitle": "property",
"accessibilityLabel": "property",
"data": "property",
"enabled": "property",
"calloutEnabled": "property",
"selected": "property",
"animates": "property",
"calloutOffset": "property",
"callout": "property",
"draggable": "property",
"size": "property",
"node": "property",
"element": "property",
"anchorOffset": "property",
"visible": "property",
"appearanceAnimation": "property",
"addEventListener": "property",
"removeEventListener": "property"
},
"PinAnnotation": {
"constructor": "function",
"size": "property",
"color": "property",
"map": "property",
"coordinate": "property",
"title": "property",
"subtitle": "property",
"accessibilityLabel": "property",
"data": "property",
"enabled": "property",
"calloutEnabled": "property",
"selected": "property",
"animates": "property",
"calloutOffset": "property",
"callout": "property",
"draggable": "property",
"node": "property",
"element": "property",
"anchorOffset": "property",
"visible": "property",
"appearanceAnimation": "property",
"addEventListener": "property",
"removeEventListener": "property"
},
"ImageAnnotation": {
"constructor": "function",
"url": "property",
"map": "property",
"coordinate": "property",
"title": "property",
"subtitle": "property",
"accessibilityLabel": "property",
"data": "property",
"enabled": "property",
"calloutEnabled": "property",
"selected": "property",
"animates": "property",
"calloutOffset": "property",
"callout": "property",
"draggable": "property",
"size": "property",
"node": "property",
"element": "property",
"anchorOffset": "property",
"visible": "property",
"appearanceAnimation": "property",
"addEventListener": "property",
"removeEventListener": "property"
}
}
var info = {
OBJ2JSON: {
version: 0.82,
date: new Date(),
navigator: navigator.appVersion,
info: 'https://gist.github.com/netsi1964/327d9714bdb451d4dc6dc425fcfb74c7',
url: location.href
}
};
var object = prompt('Which object do you want to convert to JSON?', (mapkit) ? 'mapkit' : '');
var father = eval(object);
for (var c in father) {
info[c] = {};
var child = father[c];
if (typeof child !== 'function') {
info[c] = child;
} else {
var any = false;
for (var p in child.prototype) {
any = true;
var v = child[p];
var type = typeof v;
info[c][p] = (type === 'undefined') ? 'property' : type;
}
if (!any) {
info[c] = 'function(' + child.toString().split('function (')[1].split(')')[0] + ')';
}
}
}
var json = JSON.stringify(info);
var twitter = 'I have just generated ' + object + ' #asjson find it here: ';
try {
copy(json);
prompt('A JSON version of #javascript object "' + object + '" is on the clipboard. Make a gist and share using: ', twitter);
} catch (e) {
console.log(json);
prompt('A JSON version of #javascript object "' + object + '" is in the console. Make a gist and share using: ', twitter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment