daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var vectorLayer = new OpenLayers.Layer.Vector('geoJSON', {
  2.     strategies: [new OpenLayers.Strategy.Fixed()],
  3.     protocol: new OpenLayers.Protocol.HTTP({
  4.         url: '<%= Url.Action("Vectors", "Maps") %>',
  5.         format: new OpenLayers.Format.GeoJSON()
  6.     }),
  7.     styleMap: new OpenLayers.StyleMap(style)
  8. });
  9.    
  10. OpenLayers.Request.GET({
  11.     url: '<%= Url.Action("Vectors", "Maps") %>',
  12.     async: true,
  13.     success: function(e) {
  14.         var features = new OpenLayers.Format.GeoJSON().read(e.responseText);
  15.         vectorLayer.addFeatures(features);
  16.     }
  17. });
  18.    
  19. var map, layer;
  20. map = new OpenLayers.Map(element.id);
  21. baseLayer = new OpenLayers.Layer.OSM('Simple OSM Map');
  22.  
  23.  
  24. var context = {
  25.     getColor: function(feature) {
  26.         return feature.attributes['Colour'];
  27.     },
  28.     getImageURL: function(feature) {
  29.         return feature.attributes['ImageURL'];
  30.     },
  31.     getLabel: function(feature) {
  32.         return feature.attributes['Label'];
  33.     }
  34. };
  35.  
  36. var template = {
  37.     externalGraphic: '${getImageURL}',
  38.     pointRadius: 5,
  39.     strokeWidth: 3,
  40.     strokeColor: "${getColor}"
  41. };
  42.  
  43.  
  44.  
  45. var style = new OpenLayers.Style(template, { context: context });
  46.  
  47. /*var vectorLayer = new OpenLayers.Layer.Vector('geoJSON', {
  48. strategies: [new OpenLayers.Strategy.Fixed()],
  49. protocol: new OpenLayers.Protocol.HTTP({
  50. url: '<%= Url.Action("Vectors", "Maps") %>',
  51. format: new OpenLayers.Format.GeoJSON()
  52. }),
  53. styleMap: new OpenLayers.StyleMap(style)
  54. });*/
  55.  
  56. var vectorLayer = new OpenLayers.Layer.Vector('geoJSON');
  57. vectorLayer.styleMap = new OpenLayers.StyleMap(style);
  58.  
  59. OpenLayers.Request.GET({
  60.     url: '<%= Url.Action("Vectors", "Maps") %>',
  61.     async: true,
  62.     success: function(e) {
  63.         var features = new OpenLayers.Format.GeoJSON().read(e.responseText);
  64.         vectorLayer.addFeatures(features);
  65.     }
  66. });
  67.  
  68. map.addLayers([baseLayer, vectorLayer]);
  69. map.setCenter(
  70.     new OpenLayers.LonLat(-4, 55).transform(
  71.         new OpenLayers.Projection("EPSG:4326"),
  72.         map.getProjectionObject()
  73.     ), 6
  74. );
  75.    
  76. { "features" : [ { "geometry" : { "coordinates" : [ -0.72766602400000002,
  77.                 51.273638529999999
  78.               ],
  79.             "type" : "Point"
  80.           },
  81.         "properties" : { "Colour" : "#ffffff",
  82.             "ImageURL" : "/360Scheduling/Content/Images/ByBox.png"
  83.           },
  84.         "type" : "Feature"
  85.       },
  86.       { "geometry" : { "coordinates" : [ [ -0.82559629999999995,
  87.                   51.296390000000002
  88.                 ],
  89.                 [ -0.72766602400000002,
  90.                   51.273638529999999
  91.                 ],
  92.                 [ -0.82559629999999995,
  93.                   51.296390000000002
  94.                 ]
  95.               ],
  96.             "type" : "LineString"
  97.           },
  98.         "properties" : { "Colour" : "#{72:x2}{241:x2}{152:x2}",
  99.             "ImageURL" : null
  100.           },
  101.         "type" : "Feature"
  102.       },
  103.       { "geometry" : { "coordinates" : [ -0.82559629999999995,
  104.                 51.296390000000002
  105.               ],
  106.             "type" : "Point"
  107.           },
  108.         "properties" : { "Colour" : "#ffffff",
  109.             "ImageURL" : "/360Scheduling/Content/Images/Home.png"
  110.           },
  111.         "type" : "Feature"
  112.       },
  113.       { "geometry" : { "coordinates" : [ -0.41132172900000002,
  114.                 50.821081319999998
  115.               ],
  116.             "type" : "Point"
  117.           },
  118.         "properties" : { "Colour" : "#ffffff",
  119.             "ImageURL" : "/360Scheduling/Content/Images/ByBox.png"
  120.           },
  121.         "type" : "Feature"
  122.       },
  123.       { "geometry" : { "coordinates" : [ [ -0.47245280000000001,
  124.                   50.817610000000002
  125.                 ],
  126.                 [ -0.41132172900000002,
  127.                   50.821081319999998
  128.                 ],
  129.                 [ -0.47245280000000001,
  130.                   50.817610000000002
  131.                 ]
  132.               ],
  133.             "type" : "LineString"
  134.           },
  135.         "properties" : { "Colour" : "#{206:x2}{155:x2}{66:x2}",
  136.             "ImageURL" : null
  137.           },
  138.         "type" : "Feature"
  139.       },
  140.       { "geometry" : { "coordinates" : [ -0.47245280000000001,
  141.                 50.817610000000002
  142.               ],
  143.             "type" : "Point"
  144.           },
  145.         "properties" : { "Colour" : "#ffffff",
  146.             "ImageURL" : "/360Scheduling/Content/Images/Home.png"
  147.           },
  148.         "type" : "Feature"
  149.       },
  150.       { "geometry" : { "coordinates" : [ 0.074993041999999996,
  151.                 51.270947649999997
  152.               ],
  153.             "type" : "Point"
  154.           },
  155.         "properties" : { "Colour" : "#ffffff",
  156.             "ImageURL" : "/360Scheduling/Content/Images/ByBox.png"
  157.           },
  158.         "type" : "Feature"
  159.       },
  160.       { "geometry" : { "coordinates" : [ [ 0.075924359999999996,
  161.                   51.268300000000004
  162.                 ],
  163.                 [ 0.074993041999999996,
  164.                   51.270947649999997
  165.                 ],
  166.                 [ 0.075924359999999996,
  167.                   51.268300000000004
  168.                 ]
  169.               ],
  170.             "type" : "LineString"
  171.           },
  172.         "properties" : { "Colour" : "#{99:x2}{146:x2}{254:x2}",
  173.             "ImageURL" : null
  174.           },
  175.         "type" : "Feature"
  176.       },
  177.       { "geometry" : { "coordinates" : [ 0.075924359999999996,
  178.                 51.268300000000004
  179.               ],
  180.             "type" : "Point"
  181.           },
  182.         "properties" : { "Colour" : "#ffffff",
  183.             "ImageURL" : "/360Scheduling/Content/Images/Home.png"
  184.           },
  185.         "type" : "Feature"
  186.       },
  187.       { "geometry" : { "coordinates" : [ -0.24428876999999999,
  188.                 51.583668719999999
  189.               ],
  190.             "type" : "Point"
  191.           },
  192.         "properties" : { "Colour" : "#ffffff",
  193.             "ImageURL" : "/360Scheduling/Content/Images/ByBox.png"
  194.           },
  195.         "type" : "Feature"
  196.       },
  197.       { "geometry" : { "coordinates" : [ [ -0.251608,
  198.                   51.580390000000001
  199.                 ],
  200.                 [ -0.24428876999999999,
  201.                   51.583668719999999
  202.                 ],
  203.                 [ -0.251608,
  204.                   51.580390000000001
  205.                 ]
  206.               ],
  207.             "type" : "LineString"
  208.           },
  209.         "properties" : { "Colour" : "#{188:x2}{122:x2}{221:x2}",
  210.             "ImageURL" : null
  211.           },
  212.         "type" : "Feature"
  213.       },
  214.       { "geometry" : { "coordinates" : [ -0.251608,
  215.                 51.580390000000001
  216.               ],
  217.             "type" : "Point"
  218.           },
  219.         "properties" : { "Colour" : "#ffffff",
  220.             "ImageURL" : "/360Scheduling/Content/Images/Home.png"
  221.           },
  222.         "type" : "Feature"
  223.       },
  224.       { "geometry" : { "coordinates" : [ -1.4948717600000001,
  225.                 53.68926664
  226.               ],
  227.             "type" : "Point"
  228.           },
  229.         "properties" : { "Colour" : "#ffffff",
  230.             "ImageURL" : "/360Scheduling/Content/Images/ByBox.png"
  231.           },
  232.         "type" : "Feature"
  233.       }
  234.     ],
  235.   "type" : "FeatureCollection"
  236. }
  237.    
  238. var features = new OpenLayers.Format.GeoJSON().read(e.responseText);
  239. var transformedFeatures = [];
  240. for(var i= 0; i < features.length; i++){
  241.   transformedFeatures.push(features[i].geometry.transform(
  242.      new OpenLayers.Projection("EPSG:4326"),
  243.      new OpenLayers.Projection("EPSG:900913")
  244.   ));
  245. }
  246. vectorLayer.addFeatures(transformedFeatures);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top