Guest User

Untitled

a guest
Jan 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. // marker layer
  2. Msource = new ol.source.Vector();
  3.  
  4. markLayer = new ol.layer.Vector({
  5. source: Msource,
  6. style: new ol.style.Style({
  7. image: new ol.style.Icon({
  8. opacity: 0.95,
  9. src: 'http://www..../images/mapplot.png',
  10. color: "red"
  11. })
  12. })
  13. });
  14.  
  15. var mark;
  16. var counter = "true";
  17.  
  18. function addMark(Type) {
  19.  
  20. counter = "true";
  21.  
  22. mark = new ol.interaction.Draw({
  23. source: Msource,
  24. type: Type
  25. });
  26.  
  27. // limit the marker to 4
  28. if (Msource.getFeatures().length < 4) {
  29.  
  30. map.addInteraction(mark);
  31.  
  32. // occurs when you finish to draw the current element
  33. mark.on("drawend", function(){
  34. counter = "true";
  35. drawingMarker();
  36. });
  37.  
  38. // occurs just after you finish to draw the current element
  39. markLayer.on("change", function(){
  40. map.removeInteraction(mark);
  41.  
  42. if (counter == "true") {
  43. counter = "false";
  44. var ind = Msource.getFeatures().length - 1;
  45. Msource.getFeatures()[ind].setId(MarkId - 1);
  46. }
  47.  
  48. });
  49.  
  50. } else {
  51.  
  52. map.removeInteraction(mark);
  53.  
  54. // show max marker message
  55. $(".maxmarkers").css("display", "inline");
  56.  
  57. }
  58.  
  59. } // end addDraw
  60.  
  61.  
  62. $("#Marker").click(function(e) {
  63. e.preventDefault();
  64. addMark("Point");
  65. });
Add Comment
Please, Sign In to add comment