houdini/client/js/components/maps/cc_map.js
Bradley M. Kuhn fc77ee76d6 Relicense Javascript code in accordance with project's new license
The primary license of the project is changing to:
  AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later

The Additional Permission is designed to permit publicly distributed
Javascript code to be relicensed under LGPL-3.0-or-later, but not server-side
Javascript code.  As such, we've relicensed here static Javscript files under
LGPL-3.0-or-later, and those that run as part of build and/or server side
under AGPL-3.0-or-later.

Note that in future, Javascript files may be updated to be stronger copyleft
license with the Additional Permission, particularly if they adapted to run
on server side and/or turned into templates.  Of course, we'd seek public
discussion with the contributor community about such changes.

This commit is one of the many steps to relicense the entire codebase.

Documentation granting permission for this relicensing (from all past
contributors who hold copyrights) is on file with Software Freedom
Conservancy, Inc.
2018-03-25 15:10:40 -04:00

106 lines
3.1 KiB
JavaScript

// License: LGPL-3.0-or-later
var request = require('../../common/client')
var map_options = require('./default_options')
var cc_map = {}
var info_window = false
var map_data
// the endpoint is the only required param
// see maps_controller for endpoint options
cc_map.init = function(endpoint, options_obj, query) {
endpoint = window.location.origin + '/maps/' + endpoint
request.get(endpoint)
.query(query)
.end(function(err, resp) {
map_data = resp.body.data
var has_map = document.getElementById('google_maps')
if (app.map_provider === 'google') {
if (!has_map) {
var script = document.createElement('script')
script.type = 'text/javascript'
script.id = 'google_maps'
script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&callback=draw_map'
document.body.appendChild(script)
set_extra_options(options_obj)
} else {
set_extra_options(options_obj)
draw_map()
}
}
else {
if (has_map)
{
has_map.innerText = "Sorry, no map provider is installed"
}
else
{
var map = document.getElementById('googleMap')
map.innerText = "Sorry, no map provider is installed"
}
}
})
}
function set_extra_options(obj){
if(!obj){
return
}
if(obj.center && obj.center.lat) {
map_options.lat = obj.center.lat
map_options.lng = obj.center.lng
}
map_options.disableDefaultUI = obj.disable_ui ? true : false
map_options.zoom = obj.zoom ? obj.zoom : map_options.zoom
map_options.fit_all = obj.fit_all ? true : false
}
window.draw_map = function () {
map_options.center = new google.maps.LatLng(map_options.lat, map_options.lng)
map_options.mapTypeId = google.maps.MapTypeId.NORMAL
var map = new google.maps.Map(document.getElementById('googleMap'), map_options)
add_markers(map)
}
function add_markers(map){
var markers = []
appl.def('map_data_count', map_data.length)
map_data.forEach(function(data){
if (!data.latitude) {
return
}
var coordinates = new google.maps.LatLng(data.latitude, data.longitude)
var marker = new google.maps.Marker({
position: coordinates,
map: map,
draggable: false,
icon: 'https://raw.githubusercontent.com/CommitChange/public-resources/master/images/cc-map-marker-pick-22.png',
data: data
})
google.maps.event.addListener(marker, 'click', function() {
if (info_window) {
info_window.close()
}
info_window = new google.maps.InfoWindow({ content: this.data.name })
info_window.open(map,this)
var map_data = this.data
if(map_data.total_raised) {
map_data.total_raised = utils.cents_to_dollars(map_data.total_raised)
}
appl.def('map_data', map_data)
})
markers.push(marker)
})
if(map_options.fit_all) {
var bounds = new google.maps.LatLngBounds();
for(var i = 0; i < markers.length; i++) {
bounds.extend(markers[i].getPosition());
}
map.fitBounds(bounds);
}
}
module.exports = cc_map