Guest User

Untitled

a guest
May 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. function addInteractions() {
  2. draw = new ol.interaction.Draw({
  3. source: source,
  4. type: typeSelect.value
  5. });
  6. draw.on("drawend", function(e) {
  7. var f = e.feature;
  8. features.push(f);
  9. geoJson = format.writeFeatures(features);
  10. console.log(geoJson);
  11. document.getElementById('js-textarea').value = geoJson;
  12. });
  13. map.addInteraction(draw);
  14. snap = new ol.interaction.Snap({source: source});
  15. map.addInteraction(snap);
  16. }
  17.  
  18. var geoDataUrl = '/data/' + '{{percorso._id}}' + '.json';
  19. var vectorLayer = new ol.layer.Vector({
  20. source: new ol.source.Vector({
  21. url: geoDataUrl,
  22. format: new ol.format.GeoJSON()
  23. }),
  24. style: new ol.style.Style({
  25. fill: new ol.style.Fill({
  26. color: 'rgba(255, 255, 255, 0.2)'
  27. }),
  28. stroke: new ol.style.Stroke({
  29. color: '#ffcc33',
  30. width: 2
  31. }),
  32. image: new ol.style.Circle({
  33. radius: 7,
  34. fill: new ol.style.Fill({
  35. color: '#ffcc33'
  36. })
  37. })
  38. })
  39. });
  40. var raster = new ol.layer.Tile({
  41. source: new ol.source.OSM()
  42. });
  43. var map = new ol.Map({
  44. layers: [raster, vectorLayer],
  45. target: 'map',
  46. view: new ol.View({
  47. center: {{#if percorso.mapCenter}}[{{percorso.mapCenter}}] {{else}} ol.proj.transform([9.688053, 45.362760], 'EPSG:4326', 'EPSG:3857'){{/if}},
  48. zoom: {{#if percorso.zoomLevel}}{{percorso.zoomLevel}} {{else}} 13{{/if}}
  49. })
  50. });
  51.  
  52. var jsonMappa = JSON.stringify(eval("(" + oggetto_mappa + ")"));
  53. require("fs").writeFile("./public/data/" + id_perc + ".json", jsonMappa, 'utf8', function(f_err) {
  54. if(f_err)
  55. console.log(f_err);
  56. });
  57.  
  58. {
  59. "type":"FeatureCollection",
  60. "features":[
  61. {
  62. "type":"Feature",
  63. "id" : "aa",
  64. "geometry":
  65. {
  66. "type":"LineString",
  67. "coordinates":[
  68. [1073328.751180445,5680150.227413875],
  69. [1077857.6451063417,5682481.556776573],
  70. [1070385.9255914658,5679156.546046168],
  71. [1076825.7452244917,5680226.66444216],
  72. [1073328.751180445,5680169.336670946]
  73. ]
  74. },
  75. "properties":null
  76. },
  77. {
  78. "type":"Feature",
  79. "id" : "ab",
  80. "geometry":
  81. {
  82. "type":"LineString",
  83. "coordinates":[
  84. [1073328.751180445,5680169.336670946],
  85. [1071628.0273010998,5677130.96479661]
  86. ]
  87. },
  88. "properties":null}
  89. ]
  90. }
Add Comment
Please, Sign In to add comment