Guest User

Untitled

a guest
Oct 15th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. var defaultStyle_polygon_1 = new ol.style.Style({
  2. fill: new ol.style.Fill({
  3. color: 'rgba(251, 209, 88, 0.4)'
  4. }),
  5. stroke: new ol.style.Stroke({
  6. color: 'rgba(251, 209, 88, 1)',
  7. width: 2
  8. }),
  9. });
  10.  
  11. var openstreetmap = new ol.layer.Tile({
  12. source: new ol.source.OSM()
  13. });
  14.  
  15.  
  16. var polygon_source = new ol.source.Vector({
  17. format: new ol.format.GeoJSON(),
  18. url: function(extent, resolution, projection) {
  19. return 'https://fbinter.stadt-berlin.de/fb/wfs/geometry/senstadt/re_schutzgebiete?service=WFS&' +
  20. 'version=2.0.0&request=GetFeature&typeNames=re_schutzgebiete&' +
  21. 'outputFormat=application/json&crs=EPSG:25833&' + 'Filter=%3CFilter%3E%3CPropertyIsEqualTo%3E%3CPropertyName%3ESCHUTZSTATUS%3C/PropertyName%3E%3CLiteral%3EFFH-Gebiet%3C/Literal%3E%3C/PropertyIsEqualTo%3E%3C/Filter%3E';
  22. },
  23. strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
  24. minZoom: 10
  25. }))
  26. });
  27.  
  28. var polygons = new ol.layer.Vector({
  29. source: polygon_source,
  30. style: defaultStyle_polygon_1
  31. });
  32.  
  33. var map = new ol.Map({
  34. target: 'map',
  35. layers: [
  36. openstreetmap,
  37. polygons
  38. ],
  39. view: new ol.View({
  40. center: ol.proj.transform([13.3833, 52.5167], 'EPSG:4326', 'EPSG:3857', 'EPSG:25833'),
  41. zoom: 9,
  42. }),
  43. });
  44.  
  45. var select = new ol.interaction.Select({});
  46. map.addInteraction(select);
  47.  
  48.  
  49. var search = new ol.control.SearchFeature(
  50. {
  51. source: polygon_source,
  52. property: "GEBIETSNAME"
  53. });
  54. map.addControl (search);
  55.  
  56. var selectedFeatures = [];
  57. selectFeaturesGlobal = selectedFeatures;
  58.  
  59. search.on('select', function(e)
  60. { select.getFeatures().clear();
  61. select.getFeatures().push (e.search);
  62. var p = e.search.getGeometry().getFirstCoordinate();
  63. map.getView().animate({
  64. center: p,
  65. zoom: 13
  66. });
  67. });
  68.  
  69. search.on('select', function(event)
  70. {
  71. var selectedFeatures = [];
  72. selectFeaturesGlobal = selectedFeatures;
  73.  
  74. map.forEachFeatureAtPixel(event.pixel, function(feature, layer) {
  75. console.log(feature.get('GEBIETSNAME'));
  76. selectedFeatures.push(feature);
  77. });
  78. if (selectedFeatures.length > 0) {
  79. var info = [];
  80. for (var i=0; i<selectedFeatures.length; i++) {
  81. info.push(selectedFeatures[i].get('GEBIETSNAME'));
  82. }
  83. <!-- string aus der Liste erzeugen 'info.join'-->
  84. document.getElementById('infoDiv').innerHTML = info.join('<br />')
  85. } else {
  86. <!-- wenn kein Feature ausgewählt wird, wird nichts angezeigt -->
  87. document.getElementById('infoDiv').innerHTML = '';
  88. }
  89. });
Add Comment
Please, Sign In to add comment