WME GIS

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

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

  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.1
  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.app.modeController.model.bind('change:mode', gis_init);
  28.  
  29. W.map.events.register('moveend', null, function() {
  30. var center = W.map.getCenter().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
  31. $.getJSON('https://maps.googleapis.com/maps/api/geocode/json?latlng='+center.lat+','+center.lon, function(data) {
  32. if(data.status === "OK"){
  33. var locs = data.results[0].address_components;
  34. var state, county, city = "";
  35. for (var loc = 0; loc < locs.length; loc++) {
  36. if (locs[loc].types.indexOf("administrative_area_level_1") != -1)
  37. state = locs[loc].long_name;
  38. else if (locs[loc].types.indexOf("administrative_area_level_2") != -1)
  39. county = locs[loc].long_name;
  40. else if (locs[loc].types.indexOf("locality") != -1)
  41. city = 'City of ' + locs[loc].long_name;
  42. }
  43.  
  44. $('#jurisdiction').text(county ? county : city);
  45. $('#gis').prop('href', '#').addClass('disabled');
  46.  
  47. if (states.hasOwnProperty(state)) {
  48. $('#gis').removeClass('hidden');
  49. $.get('https://script.google.com/macros/s/AKfycbx2bytvT5Un0TWcaU7BpVkauqeE8zqt8Mek7Zq-OF-bznGYDyZw/exec?link='+states[state], function(rows) {
  50. var links = {};
  51. for (var row in rows)
  52. if (rows[row][1] !== "")
  53. links[rows[row][0]] = rows[row][1];
  54.  
  55. var jurisdiction = "";
  56. if (links.hasOwnProperty(city))
  57. jurisdiction = links[city];
  58. else if (links.hasOwnProperty(county))
  59. jurisdiction = links[county];
  60. else if (links.hasOwnProperty(state))
  61. jurisdiction = links[state];
  62.  
  63. if (jurisdiction !== "")
  64. $('#gis').prop('href', jurisdiction.replace('<lat>',center.lat).replace('<lon>',center.lon).replace('<zoom>',W.map.getZoom()+12)).removeClass('disabled');
  65. });
  66. } else
  67. $('#gis').addClass('hidden');
  68. }
  69. });
  70. });
  71. }
  72.  
  73. gis_init();