{"version":3,"file":"../../javascript/destination_map.js","names":["DestinationMap","mapId","popout","options","defaults","mapTypeId","google","maps","MapTypeId","ROADMAP","scrollwheel","mapTypeControl","streetViewControl","$","extend","this","map","Map","get","markers","bounds","LatLngBounds","activeFilter","activeMarker","activeMarkerId","current","on","e","preventDefault","closeDetails","removeClass","openDetails","data","addClass","window","resize","event","trigger","fitBounds","offsetX","getDiv","width","offsetCenter","marker","getPosition","prototype","addMarkers","makeClickable","propIcon","url","size","Size","origin","Point","anchor","partnerIcon","each","key","value","label","idx","text","color","fontSize","fontWeight","Marker","position","LatLng","lat","lng","icon","isReciprocal","clickable","zIndex","type","active","addListener","id","html","destination","filterDestinations","filterFn","gmap","m","setMap","zoomToDestination","Geocoder","geocode","address","results","status","GeocoderStatus","OK","geometry","viewport","setOpacity","setIcon","setZoom","latlng","offsetx","offsety","scale","Math","pow","getZoom","worldCoordinateCenter","getProjection","fromLatLngToPoint","pixelOffset","worldCoordinateNewCenter","x","y","newCenter","fromPointToLatLng","panTo"],"sources":["destination_map.js"],"mappings":"AAWA,IAAIA,eAAiB,SAAUC,EAAOC,EAAQC,GAC1C,IAAIC,EAAW,CACXC,UAAWC,OAAOC,KAAKC,UAAUC,QACjCC,aAAa,EACbC,gBAAgB,EAChBC,mBAAmB,GAGvBC,EAAEC,OAAOV,EAAUD,GACnBY,KAAKb,OAASW,EAAEX,GAChBa,KAAKC,IAAM,IAAIV,OAAOC,KAAKU,IAAIJ,EAAEZ,GAAOiB,IAAI,GAAId,GAChDW,KAAKI,QAAU,CAAC,EAChBJ,KAAKK,OAAS,IAAId,OAAOC,KAAKc,aAC9BN,KAAKO,cAAe,EAEpBP,KAAKQ,cAAe,EACpBR,KAAKS,gBAAiB,EAEtB,IAAIC,EAAUV,KAEdF,EAAE,4BAA6BX,GAAQwB,GAAG,SAAS,SAASC,GACxDA,EAAEC,iBACFH,EAAQI,eACRhB,EAAE,6BAA6BiB,YAAY,SAC/C,IAEAjB,EAAE,6BAA6Ba,GAA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Root":"../../../../resources/javascript","sourcesContent":["/**\n * Basic map object takes jquery selector to find the map element\n * and a list of options to get passed directly into the map constructor\n * there are some default options set which can be overriden\n *\n * @param  selector   id\n * @param  selector   popout\n * @param  object   options\n * @author Stuart Hallewell <stuart.hallewell@d3r.com>\n * Based off the map.js by Neil\n */\nvar DestinationMap = function (mapId, popout, options) {\n    var defaults = {\n        mapTypeId: google.maps.MapTypeId.ROADMAP,\n        scrollwheel: true,\n        mapTypeControl: false,\n        streetViewControl: false\n    };\n\n    $.extend(defaults, options);\n    this.popout = $(popout);\n    this.map = new google.maps.Map($(mapId).get(0), defaults);\n    this.markers = {};\n    this.bounds = new google.maps.LatLngBounds();\n    this.activeFilter = false;\n\n    this.activeMarker = false;\n    this.activeMarkerId = false;\n\n    var current = this;\n\n    $('.guide-map__popout__close', popout).on('click', function(e) {\n        e.preventDefault();\n        current.closeDetails();\n        $('.guide-map__places__place').removeClass('active');\n    });\n\n    $('.guide-map__places__place').on('click', function(e) {\n        e.preventDefault();\n        current.openDetails($(this).data('id'));\n        $('.guide-map__places__place').removeClass('active');\n        $(this).addClass('active');\n    });\n\n    $(window).resize(function() {\n        google.maps.event.trigger(current.map, 'resize');\n\n        current.map.fitBounds(current.bounds);\n\n        if (current.activeMarker) {\n            var offsetX = $(current.map.getDiv()).width() / 4;\n            current.offsetCenter(current.activeMarker.marker.getPosition(), offsetX, 0);\n        } else {\n\n        }\n\n    }).resize();\n\n};\n\nDestinationMap.prototype.addMarkers = function(data, makeClickable) {\n    makeClickable = typeof makeClickable != 'undefined' ? makeClickable : true;\n\n    var propIcon = {\n        url: \"/images/map/property-pin.png\",\n        size: new google.maps.Size(56, 68),\n        origin: new google.maps.Point(0,0),\n        anchor: new google.maps.Point(28, 68)\n    };\n\n    var partnerIcon = {\n        url: \"/images/map/partner-pin.png\",\n        size: new google.maps.Size(56, 68),\n        origin: new google.maps.Point(0,0),\n        anchor: new google.maps.Point(28, 68)\n    };\n\n    var current = this;\n\n    $.each(data, function(key, value) {\n        var label;\n        if (value.idx !== 'undefined' && value.idx > 0) {\n            label =  {\n                text: value.idx,\n                color:'#676767',\n                fontSize: '12px',\n                fontWeight: 'bold'\n            }\n        } else {\n            label = '';\n        }\n\n        var marker = new google.maps.Marker({\n            position: new google.maps.LatLng(value.lat, value.lng),\n            map: current.map,\n            icon: value.isReciprocal ? partnerIcon : propIcon,\n            clickable: true,\n            label: label,\n            zIndex: 5,\n            type: 'property',\n            active: false\n        });\n\n        if (makeClickable) {\n            marker.addListener(\"click\", function() {\n                current.openDetails(value.id);\n            });\n        }\n\n        current.bounds.extend(marker.getPosition());\n\n        current.markers[value.id] = {\n            marker: marker,\n            html: value.html,\n            type: 'property',\n            destination: value.destination,\n            isReciprocal: value.isReciprocal\n        };\n    });\n};\n\n/**\n * Filter the experience markers displayed on the map.\n *\n * @author James Atkin <james.atkin@d3r.com>\n */\nDestinationMap.prototype.filterDestinations = function(filterFn) {\n    var gmap = this;\n\n    $.each(this.markers, function (id, m) {\n        if (filterFn(id, m.destination)) {\n            m.marker.setMap(gmap.map);\n            gmap.activeFilter = m.destination;\n        } else {\n            m.marker.setMap(null);\n            if (gmap.activeMarkerId && gmap.activeMarkerId == id) {\n                gmap.closeDetails();\n            }\n        }\n    });\n};\n\n/**\n * Recenter the map and zoom to location\n *\n * @author Stuart Hallewell <stuart.hallewell@d3r.com>\n */\nDestinationMap.prototype.zoomToDestination = function(destination) {\n    var gmap = this;\n    var geocoder = new google.maps.Geocoder();\n\n    geocoder.geocode( {'address' : destination}, function(results, status) {\n        if (status == google.maps.GeocoderStatus.OK) {\n            gmap.map.fitBounds(results[0].geometry.viewport);\n        }\n    });\n}\n\n/**\n * Open the details popout\n *\n * @param  int id\n * @author Neil Brayfield <neil@d3r.com>\n */\nDestinationMap.prototype.openDetails = function(id) {\n    this.popout.addClass('guide-map__popout--active');\n\n    this.popout.trigger('open');\n\n    // Swap the current active marker back to non-active\n\n    $.each(this.markers, function(key, value) {\n        var icon = value.isReciprocal ? 'partner-pin.png' : 'property-pin.png';\n        if (key != id) {\n            value.marker.setOpacity(0.7);\n            if (value.marker.active == true) {\n                value.marker.setIcon(\"/images/map/\" + icon);\n                value.marker.active = false;\n            }\n        } else {\n            value.marker.setIcon(\"/images/map/property-pin-active.png\");\n            value.marker.setOpacity(1);\n            value.marker.active = true;\n        }\n    });\n\n    $('.guide-map__popout__content', this.popout).html(this.markers[id].html);\n\n    this.activeMarker = this.markers[id];\n    this.activeMarkerId = id;\n\n    var offsetX = $(this.map.getDiv()).width() / 4;\n\n    this.map.setZoom(15);\n\n    this.offsetCenter(this.markers[id].marker.getPosition(), offsetX, 0);\n};\n\n/**\n * Close the popout\n *\n * @author Neil Brayfield <neil@d3r.com>\n */\nDestinationMap.prototype.closeDetails = function() {\n    this.popout.removeClass('guide-map__popout--active');\n\n    this.popout.trigger('close');\n\n    $.each(this.markers, function(key, value) {\n        var icon = value.isReciprocal ? 'partner-pin.png' : 'property-pin.png';\n        value.marker.setOpacity(1);\n        if (value.marker.active == true) {\n            value.marker.setIcon(\"/images/map/\" + icon);\n            value.marker.active = false;\n            }\n    });\n\n   this.zoomToDestination(this.activeFilter);\n};\n\n/**\n * Move the map to a specific marker and center it\n * on the right hand side\n *\n * @param  google.maps.LatLng latlng\n * @param  int offsetx\n * @param  int offsety\n * @author Neil Brayfield <neil@d3r.com>\n */\nDestinationMap.prototype.offsetCenter = function(latlng, offsetx, offsety) {\n    var scale = Math.pow(2, this.map.getZoom());\n\n    var worldCoordinateCenter = this.map.getProjection().fromLatLngToPoint(latlng);\n    var pixelOffset = new google.maps.Point((offsetx/scale) || 0,(offsety/scale) ||0);\n\n    var worldCoordinateNewCenter = new google.maps.Point(\n        worldCoordinateCenter.x - pixelOffset.x,\n        worldCoordinateCenter.y + pixelOffset.y\n    );\n\n    var newCenter = this.map.getProjection().fromPointToLatLng(worldCoordinateNewCenter);\n\n    this.map.panTo(newCenter);\n\n};\n"]}