Created
June 7, 2015 18:19
-
-
Save chiquitinxx/1eb901bcf81a4e068681 to your computer and use it in GitHub Desktop.
Groov'ing google maps api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GoogleMap.init { | |
options.zoom = 6 | |
options.center = ltlg(40.4379543,-3.6795367 ) | |
putStyle([ | |
[stylers: [ [ visibility: 'simplified' ],[ gamma: 0.5 ],[ weight: 0.5 ] ] ], | |
[featureType: 'water', stylers: [ [color: '#b77fd7'] ] ] | |
]) | |
mark(position: ltlg(40.4379543,-3.6795367), | |
title: 'grooscript', | |
icon: "img/gs.png" | |
) | |
mark(position: ltlg(41.39479,2.1487679), | |
title: 'Champions!', | |
icon: "img/barcelona.png", | |
infoWindow: '<img class="campeon" src="img/campeon.jpg"/>' | |
) | |
}.start('map-canvas') | |
import org.grooscript.asts.GsNative | |
class GoogleMap { | |
Map options = [ | |
zoom: 8 | |
] | |
private List<Map> _style | |
private List<Map> _marks = [] | |
static GoogleMap init(@DelegatesTo(GoogleMap) Closure actions) { | |
def map = new GoogleMap() | |
actions.delegate = map | |
actions() | |
map | |
} | |
@GsNative | |
def ltlg(latitude, longitude) {/* | |
return new google.maps.LatLng(latitude, longitude); | |
*/} | |
void putStyle(List<Map> styles) { | |
_style = styles | |
} | |
void mark(Map options) { | |
_marks << options | |
} | |
@GsNative | |
void start(String selectorId) {/* | |
var style = this._style; | |
var options = this.options; | |
var marks = this._marks; | |
google.maps.event.addDomListener(window, 'load', function() { | |
var MY_MAPTYPE_ID = 'custom_style'; | |
if (style) { | |
options['mapTypeControlOptions'] = { | |
mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID] | |
} | |
options['mapTypeId'] = MY_MAPTYPE_ID; | |
} | |
var map = new google.maps.Map(document.getElementById(selectorId), gs.toJavascript(options)); | |
if (style) { | |
var styledMapOptions = {name: 'Custom Style'}; | |
var customMapType = new google.maps.StyledMapType(gs.toJavascript(style), styledMapOptions); | |
map.mapTypes.set(MY_MAPTYPE_ID, customMapType); | |
} | |
marks.each(function(mark) { | |
mark.map = map; | |
var googleMark = new google.maps.Marker(gs.toJavascript(mark)); | |
if (mark.infoWindow) { | |
var infowindow = new google.maps.InfoWindow({content: mark.infoWindow}); | |
google.maps.event.addListener(googleMark, 'click', function() { | |
infowindow.open(map, googleMark); | |
}); | |
} | |
}); | |
}); | |
*/} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment