WME GIS

Displays the jurisdiction of the current location, and adds a button to open the GIS if available

当前为 2016-07-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WME GIS
  3. // @author @Philistine11
  4. // @namespace https://greasyfork.org/en/users/53803
  5. // @description Displays the jurisdiction of the current location, and adds a button to open the GIS if available
  6. // @include https://www.waze.com/editor/*
  7. // @version 1.2.0
  8. // ==/UserScript==
  9.  
  10. function gis_init(model, modeId) {
  11. if (modeId === 1)
  12. return;
  13.  
  14. var location = $('div.location-info-region');
  15. if (location.length === 0) {
  16. setTimeout(gis_init, 500);
  17. return;
  18. }
  19. location.after('<div style="float:left"><div class="location-info">&nbsp;-&nbsp;<span id="jurisdiction"></span>&nbsp;<a id="gis" class="btn btn-default disabled" style="vertical-align:top" target="_blank" href="#">GIS</a></div></div>');
  20.  
  21. var states = {};
  22. $.getJSON('https://script.google.com/macros/s/AKfycbx2bytvT5Un0TWcaU7BpVkauqeE8zqt8Mek7Zq-OF-bznGYDyZw/exec?link=10dR8z16eKPHeI-ywLcHh2UNS3enQ7gt36Hhzm9nOJbA', function(rows) {
  23. for (var row in rows)
  24. states[rows[row][0]] = rows[row][1];
  25. });
  26.  
  27. W.map.events.register('moveend', null, function() {
  28. var center = W.map.getCenter().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
  29. $.getJSON('https://maps.googleapis.com/maps/api/geocode/json?latlng='+center.lat+','+center.lon, function(data) {
  30. if(data.status === "OK"){
  31. var locs = data.results[0].address_components;
  32. var state, county, city = "";
  33. for (var loc = 0; loc < locs.length; loc++) {
  34. if (locs[loc].types.indexOf("administrative_area_level_1") != -1)
  35. state = locs[loc].long_name;
  36. else if (locs[loc].types.indexOf("administrative_area_level_2") != -1)
  37. county = locs[loc].long_name;
  38. else if (locs[loc].types.indexOf("locality") != -1)
  39. city = 'City of ' + locs[loc].long_name;
  40. }
  41.  
  42. $('#jurisdiction').text(county ? county : city);
  43. $('#gis').prop('href', '#').addClass('disabled');
  44.  
  45. if (states.hasOwnProperty(state)) {
  46. $('#gis').removeClass('hidden');
  47. $.get('https://script.google.com/macros/s/AKfycbx2bytvT5Un0TWcaU7BpVkauqeE8zqt8Mek7Zq-OF-bznGYDyZw/exec?link='+states[state], function(rows) {
  48. var links = {};
  49. for (var row in rows)
  50. if (rows[row][1] !== "")
  51. links[rows[row][0]] = rows[row][1];
  52.  
  53. var jurisdiction = "";
  54. if (links.hasOwnProperty(city))
  55. jurisdiction = links[city];
  56. else if (links.hasOwnProperty(county))
  57. jurisdiction = links[county];
  58. else if (links.hasOwnProperty(state))
  59. jurisdiction = links[state];
  60.  
  61. if (jurisdiction !== "")
  62. $('#gis').prop('href', jurisdiction.replace('<lat>',center.lat).replace('<lon>',center.lon).replace('<zoom>',W.map.getZoom()+12)).removeClass('disabled');
  63. });
  64. } else
  65. $('#gis').addClass('hidden');
  66. }
  67. });
  68. });
  69. }
  70.  
  71. Waze.app.modeController.model.bind('change:mode', gis_init);
  72.  
  73. gis_init();