Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. <script>
  2. $(document).ready(function () {
  3. $('.tap-target').tapTarget('open');
  4.  
  5. var typeSelect = 'None';
  6.  
  7. <!-- Creating Basic Map -->
  8. var styles = [
  9. 'Road',
  10. 'Aerial',
  11. 'AerialWithLabels',
  12. 'collinsBart',
  13. 'ordnanceSurvey'
  14. ];
  15. var layers = [];
  16. var i, ii;
  17. for (i = 0, ii = styles.length; i < ii; ++i) {
  18. layers.push(new ol.layer.Tile({
  19. visible: false,
  20. preload: Infinity,
  21. source: new ol.source.BingMaps({
  22. key: '#mykey',
  23. imagerySet: styles[i]
  24. // use maxZoom 19 to see stretched tiles instead of the BingMaps
  25. // "no photos at this zoom level" tiles
  26. // maxZoom: 19
  27. })
  28. }));
  29. }
  30.  
  31. var map = new ol.Map({
  32. interactions: ol.interaction.defaults().extend([new app.Drag()]),
  33. layers: layers,
  34. // Improve user experience by loading tiles while dragging/zooming. Will make
  35. // zooming choppy on mobile or slow devices.
  36. loadTilesWhileInteracting: true,
  37. target: 'map',
  38. view: new ol.View({
  39. projection: 'EPSG:4326',
  40. //center: [0, 0],
  41. //projection: 'EPSG:4326',
  42. center: [-48.669159, -26.904534],
  43.  
  44. zoom: {{ geo|length > 0 ? 17 : 13 }}
  45. })
  46. });
  47.  
  48. var select = document.getElementById('layer-select');
  49.  
  50. function onChange()
  51. {
  52. var style = select.value;
  53.  
  54. for (var i = 0, ii = layers.length; i < ii; ++i)
  55. {
  56. layers[i].setVisible(styles[i] === style);
  57. }
  58. }
  59.  
  60. select.addEventListener('change', onChange);
  61. onChange();
  62. <!-- Creating Basic Map -->
  63.  
  64. <!-- Draw Feature -->
  65. var source = new ol.source.Vector({
  66. wrapX: true
  67. });
  68.  
  69. var fill = new ol.style.Fill({
  70. color: 'rgba(255,255,255,0.4)'
  71. });
  72.  
  73. var stroke = new ol.style.Stroke({
  74. color: '#3399CC',
  75. width: 3
  76. });
  77.  
  78. var sourceStyle = new ol.style.Style({
  79. image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
  80. anchor: [0.5, 36],
  81. anchorXUnits: 'fraction',
  82. anchorYUnits: 'pixels',
  83. src: '{{ asset('/images/material-icons/maps/1x_web/ic_place_black_36dp.png') }}'
  84. })),
  85. stroke: stroke,
  86. fill: fill
  87. });
  88.  
  89. var vector = new ol.layer.Vector({
  90. //projection: 'EPSG:25830',
  91. style: sourceStyle,
  92. source: source
  93. });
  94.  
  95. map.addLayer(vector);
  96. vector.setVisible(true);
  97.  
  98. $.ajax({
  99. type: 'get',
  100. url: 'http://datosabiertos.malaga.eu/recursos/urbanismoEInfraestructura/sedesWifi/sedesWifi-25830.geojson',
  101. type: 'json',
  102. success: function (r) {
  103. // eval pode incomodar, verificar isso para evitar problemas, mas feito assim para testes
  104.  
  105. //EPSG::3857
  106.  
  107. //console.log(r);
  108.  
  109. //console.log(new ol.format.GeoJSON().readProjection(r));
  110.  
  111.  
  112. var feats = (new ol.format.GeoJSON()).readFeatures(r);
  113. //I've tried to use featureProjection and dataProjection with no luck
  114.  
  115. source.reportError = true;
  116. source.addFeatures(feats);
  117. }
  118. });
  119.  
  120. });
  121. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement