Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. const geojsonObject = {
  2. type: 'FeatureCollection',
  3. features: [
  4. {
  5. type: 'Feature',
  6. properties: {},
  7. geometry: {
  8. type: 'Polygon',
  9. coordinates: [
  10. [ [10.0, 40.0], [15.0, 40.0], [15.0, 50.0], [10.0, 50.0], [10.0, 40.0] ]
  11. ]
  12. }
  13. },
  14. {
  15. type: 'Feature',
  16. properties: {},
  17. geometry: {
  18. type: 'Polygon',
  19. coordinates: [
  20. [ [16.0, 40.0], [20.0, 40.0], [20.0, 50.0], [16.0, 50.0], [16.0, 40.0] ]
  21. ]
  22. }
  23. }
  24. ]
  25. };
  26.  
  27. const greenStyle = new Style({
  28. stroke: new Stroke({color: 'green', width: 3}),
  29. fill: new Fill({color: 'rgba(0, 255, 0, 0.1)'})
  30. });
  31.  
  32. const redStyle = new Style({
  33. stroke: new Stroke({color: 'red',width: 3}),
  34. fill: new Fill({color: 'rgba(255, 0, 0, 0.1)'})
  35. });
  36.  
  37. const blueStyle = new Style({
  38. stroke: new Stroke({color: 'blue', width: 3}),
  39. fill: new Fill({color: 'rgba(0, 0, 255, 0.1)'})
  40. });
  41.  
  42. const vector = new VectorLayer({
  43. source: new VectorSource({
  44. features: (new GeoJSON()).readFeatures(geojsonObject, {featureProjection: 'EPSG:3857'})
  45. }),
  46. style: greenStyle
  47. });
  48.  
  49. const select = new Select({
  50. condition: function(mapBrowserEvent) {
  51. return click(mapBrowserEvent) && altKeyOnly(mapBrowserEvent);
  52. },
  53. style: redStyle
  54. });
  55.  
  56. map.addInteraction(select);
  57. select.on('select', (e) => {
  58. console.log('selected:', e);
  59. });
  60.  
  61. const firstFeature = vector.getSource().getFeatures()[0];
  62. firstFeature.setStyle(blueStyle);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement