Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leevigraham/04f008377ea44aae4c670a086009013b to your computer and use it in GitHub Desktop.
Save leevigraham/04f008377ea44aae4c670a086009013b to your computer and use it in GitHub Desktop.
From 8921f5b7da6be46d7c1949c424a0d1210fac3d9e Mon Sep 17 00:00:00 2001
From: Iain Saxon <iain.saxon@newism.com.au>
Date: Thu, 26 May 2016 18:45:37 +1000
Subject: [PATCH] Fixed the gmapStringifyReplacer function to work with
pre-flattened JSON
---
.../gmap/javascript/gmap_field.js | 46 ++++++++++++++++++----
1 file changed, 38 insertions(+), 8 deletions(-)
diff --git a/templates/third_party_themes/gmap/javascript/gmap_field.js b/templates/third_party_themes/gmap/javascript/gmap_field.js
index 0631849..173af93 100755
--- a/templates/third_party_themes/gmap/javascript/gmap_field.js
+++ b/templates/third_party_themes/gmap/javascript/gmap_field.js
@@ -22,18 +22,48 @@ var Gmap = function($wrapper, options) {
var icons = options.icons;
var savedResponse = options.response;
+ // yes this looks terrible and yes it needs to do all this as i can't find a js version of php class checking
var gmapStringifyReplacer = function(key, value) {
// we need to override the geometry output thanks to circular references in the google maps JS
if ('geometry' === key) {
- return {
- bounds: value.bounds.toJSON(),
- location: {
- lat: value.location.lat,
- lng: value.location.lng
- },
- location_type: value.location_type,
- viewport: value.viewport.toJSON()
+
+ // now we need to determine what properties are used and how to fetch them
+ var newValue = {
+ location_type: value.location_type
};
+
+ // check that the bounds are present
+ if ('object' === typeof(value.bounds)) {
+ if ('function' === typeof(value.bounds.toJSON)) {
+ newValue.bounds = value.bounds.toJSON();
+ } else {
+ newValue.bounds = value.bounds;
+ }
+ }
+
+ // check that the location is present
+ if ('object' === typeof(value.location)) {
+ if ('function' === typeof(value.location.toJSON)) {
+ newValue.location = {
+ lat: value.location.lat,
+ lng: value.location.lng
+ };
+ } else {
+ newValue.location = value.location;
+ }
+ }
+
+ // check that the viewport is present
+ if ('object' === typeof(value.viewport)) {
+ if ('function' === typeof(value.viewport.toJSON)) {
+ newValue.viewport = value.viewport.toJSON();
+ } else {
+ newValue.viewport = value.viewport;
+ }
+ }
+
+ // return the new object
+ return newValue;
}
return value;
--
2.7.4 (Apple Git-66)+GitX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment