//* comment *// Copyright (C) 2015 Yash Khandelwal This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . NOTE: Default local is downtown Boston. //* globals *// var gmapMashapeKey = 'JidA8phgY8mshJ8MiEUeHTdwFjjtp1wq209jsncYthfRDMQNW6'; var cityName = ''; var cityLatitude = 0; var cityLongitude = 0; //* block:cityToLat *// var cityToLatBlk = new ProtoBlock('cityToLat'); cityToLatBlk.palette = palettes.dict['GMAP']; blocks.protoBlockDict['cityToLat'] = cityToLatBlk; cityToLatBlk.staticLabels.push(_('city latitude')); cityToLatBlk.adjustWidthToLabel(); cityToLatBlk.oneArgMathBlock(); cityToLatBlk.dockTypes[1] = 'anyin'; cityToLatBlk.defaults.push("Boston"); //* block:cityToLong *// var cityToLongBlk = new ProtoBlock('cityToLong'); cityToLongBlk.palette = palettes.dict['GMAP']; blocks.protoBlockDict['cityToLong'] = cityToLongBlk; cityToLongBlk.staticLabels.push(_('city longitude')); cityToLongBlk.adjustWidthToLabel(); cityToLongBlk.oneArgMathBlock(); cityToLongBlk.dockTypes[1] = 'anyin'; cityToLongBlk.defaults.push("Boston"); //* arg:cityToLong *// var block = logo.blocks.blockList[blk]; var conns = block.connections; var city = logo.parseArg(logo, turtle, conns[1]); if (city == cityName) { block.value = cityLongitude; } else { var apiURL = 'https://devru-latitude-longitude-find-v1.p.mashape.com/latlon.php?location=' + city; var request = new XMLHttpRequest(); request.open('GET', apiURL, false); request.setRequestHeader('X-Mashape-Authorization', gmapMashapeKey); request.send(null); var response = request.responseText; var data = JSON.parse(response); var longitude = 0; if (data['Results'].length > 0) { data = data['Results'][0]['ll']; var parts = data.split(' '); try { cityLatitude = Number(parts[0]); cityLongitude = Number(parts[1]); var longitude = cityLongitude; cityName = city; } catch (e) { logo.errorMsg(_('Coordinate data not available.'), blk); } } else { logo.errorMsg(_('Coordinate data not available.'), blk); } block.value = longitude; } //* arg:cityToLat *// var block = logo.blocks.blockList[blk]; var conns = block.connections; var city = logo.parseArg(logo, turtle, conns[1]); if (city == cityName) { block.value = cityLatitude; } else { var apiURL = 'https://devru-latitude-longitude-find-v1.p.mashape.com/latlon.php?location=' + city; var request = new XMLHttpRequest(); request.open('GET', apiURL, false); request.setRequestHeader('X-Mashape-Authorization', gmapMashapeKey); request.send(null); var response = request.responseText; var data = JSON.parse(response); var latitude = 0; if(data['Results'].length > 0) { data = data['Results'][0]['ll']; var parts = data.split(' '); try { cityLatitude = Number(parts[0]); cityLongitude = Number(parts[1]); var latitude = cityLatitude; cityName = city; } catch (e) { logo.errorMsg(_('Coordinate data not available.'), blk); } } else { logo.errorMsg(_('Coordinate data not available.'), blk); } block.value = latitude; } //* block:gmap *// var gmapBlk = new ProtoBlock('gmap'); gmapBlk.palette = palettes.dict['GMAP']; blocks.protoBlockDict['gmap'] = gmapBlk; gmapBlk.staticLabels.push(_('Google map'),_('coordinates'),_('zoom factor')); gmapBlk.adjustWidthToLabel(); gmapBlk.twoArgMathBlock(); //* arg:gmap *// var block = logo.blocks.blockList[blk]; var conns = block.connections; var url = logo.parseArg(logo, turtle, conns[1]); var zoom_factor = logo.parseArg(logo, turtle, conns[2]); if(!url) { url = 'http://maps.googleapis.com/maps/api/staticmap?center=42.357279,-71.065740'; } if(!zoom_factor) { zoom_factor = 10; } if(zoom_factor == 0) { zoom_factor = 0; } gmapURL = url + '&size=800x800&zoom=' + zoom_factor +'&sensor=false'; block.value = gmapURL; //* block:zoom *// var zoomBlk = new ProtoBlock('zoom'); zoomBlk.palette = palettes.dict['GMAP']; blocks.protoBlockDict['zoom'] = zoomBlk; zoomBlk.staticLabels.push(_('zoom')); zoomBlk.adjustWidthToLabel(); zoomBlk.oneArgMathBlock(); zoomBlk.dockTypes[1] = 'anyin'; zoomBlk.defaults.push(10); //* arg:zoom *// var block = logo.blocks.blockList[blk]; var conns = block.connections; var zoomFactor = logo.parseArg(logo, turtle, conns[1]); block.value = zoomFactor; //* block:coord *// var coordBlk = new ProtoBlock('coord'); coordBlk.palette = palettes.dict['GMAP']; blocks.protoBlockDict['coord'] = coordBlk; coordBlk.staticLabels.push(_('coordinates'),_('latitude'),_('longitude')); coordBlk.adjustWidthToLabel(); coordBlk.twoArgMathBlock(); coordBlk.dockTypes[1] = 'anyin'; coordBlk.dockTypes[2] = 'anyin'; coordBlk.defaults.push(42.357279,-71.065740); //* arg:coord *// var block = logo.blocks.blockList[blk]; var conns = block.connections; var latitude = logo.parseArg(logo, turtle, conns[1]); var longitude = logo.parseArg(logo, turtle, conns[2]); latitude = eval(latitude); longitude = eval(longitude); if(!latitude || !longitude) { latitude = 42.357279; longitude = -71.065740; } gmapURL = 'http://maps.googleapis.com/maps/api/staticmap?center=' + latitude + ',' + longitude; block.value = gmapURL; //* palette-icon:GMAP *// //* palette-fill:GMAP *// #00abff //* palette-stroke:GMAP *// #005aaa //* palette-highlight:GMAP *// #00c5ff //* palette-stroke-highlight:GMAP *// #002659