startDrawShape.js 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {createDrawFeature} from "./drawFeature"
  2. let drawShapeMap = new Map();
  3. function drawPoint(color,map){
  4. let option = {
  5. type:'Point',
  6. pointColor:color
  7. }
  8. let shape = new createDrawFeature(option,map)
  9. drawShapeMap.set('drawShape', shape)
  10. shape.addInteraction()
  11. }
  12. function drawLine(color,map){
  13. let option = {
  14. type:'LineString',
  15. lineColor:color
  16. }
  17. // if (!drawShapeMap.get('drawShape')) {
  18. // let shape = new createDrawFeature(option,map)
  19. // drawShapeMap.set('drawShape', shape)
  20. // shape.addInteraction()
  21. // }
  22. let shape = new createDrawFeature(option,map)
  23. drawShapeMap.set('drawShape', shape)
  24. shape.addInteraction()
  25. }
  26. function closeDrawShape() {
  27. if (drawShapeMap.get('drawShape')) {
  28. let shape = drawShapeMap.get('drawShape')
  29. shape.closeInteraction()
  30. shape.clearShapes()
  31. return shape.getData()
  32. }
  33. }
  34. export default{drawPoint,drawLine,closeDrawShape}