WME GIS

Displays the locality of the current location and provides links to open GIS if available

当前为 2017-01-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WME GIS
  3. // @author @Philistine11
  4. // @namespace https://greasyfork.org/en/users/53803
  5. // @description Displays the locality of the current location and provides links to open GIS if available
  6. // @include https://www.waze.com/editor/*
  7. // @version 1.3.2
  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 class="btn-group btn-group-sm" style="float:left; margin-left:1rem;"><a id="locality_gis" class="btn btn-default disabled hidden" style="border:1px solid" target="_blank" href="#">Locality</a><a id="county_gis" class="btn btn-default disabled hidden" style="border:1px solid" target="_blank" href="#">County</a><a id="state_gis" class="btn btn-default disabled hidden" style="border:1px solid" target="_blank" href="#">State</a></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 locality = "", county = "", state = "";
  35. $('#locality_gis').addClass('hidden');
  36. $('#county_gis').addClass('hidden');
  37. $('#state_gis').addClass('hidden');
  38.  
  39. for (var loc = 0; loc < locs.length; loc++) {
  40. if (locs[loc].types.indexOf("administrative_area_level_1") != -1) {
  41. state = locs[loc].long_name;
  42. $('#state_gis').removeClass('hidden').text(state);
  43. } else if (locs[loc].types.indexOf("administrative_area_level_2") != -1) {
  44. county = locs[loc].long_name;
  45. $('#county_gis').removeClass('hidden').text(county);
  46. } else if (locs[loc].types.indexOf("locality") != -1) {
  47. locality = locs[loc].long_name;
  48. $('#locality_gis').removeClass('hidden').text(locality);
  49. }
  50. }
  51.  
  52. $('#locality_gis').prop('href', '#').addClass('disabled');
  53. $('#county_gis').prop('href', '#').addClass('disabled');
  54. $('#state_gis').prop('href', '#').addClass('disabled');
  55.  
  56. if (states.hasOwnProperty(state)) {
  57. $.getJSON('https://script.google.com/macros/s/AKfycbx2bytvT5Un0TWcaU7BpVkauqeE8zqt8Mek7Zq-OF-bznGYDyZw/exec?v=1.3&link='+states[state], function(rows) {
  58. for (var row in rows)
  59. if (rows[row][2] !== "")
  60. if (rows[row][1] == "State") {
  61. $('#state_gis').prop('href', rows[row][2].replace('<lat>',center.lat).replace('<lon>',center.lon).replace('<zoom>',W.map.getZoom()+12)).removeClass('disabled');
  62. } else if (rows[row][1] == "County") {
  63. if (county.indexOf(rows[row][0]) != -1)
  64. $('#county_gis').prop('href', rows[row][2].replace('<lat>',center.lat).replace('<lon>',center.lon).replace('<zoom>',W.map.getZoom()+12)).removeClass('disabled');
  65. } else if (rows[row][0] == locality)
  66. $('#locality_gis').prop('href', rows[row][2].replace('<lat>',center.lat).replace('<lon>',center.lon).replace('<zoom>',W.map.getZoom()+12)).removeClass('disabled');
  67. });
  68. }
  69. }
  70. });
  71. });
  72. }
  73.  
  74. gis_init();