1/** 2 * @namespace WPGMZA 3 * @module OLFeature 4 * @requires WPGMZA 5 */ 6jQuery(function($) { 7 8 WPGMZA.OLFeature = function(options) 9 { 10 WPGMZA.assertInstangeOf(this, "OLFeature"); 11 12 WPGMZA.Feature.apply(this, arguments); 13 } 14 15 WPGMZA.extend(WPGMZA.OLFeature, WPGMZA.Feature); 16 17 WPGMZA.OLFeature.getOLStyle = function(options) 18 { 19 var translated = {}; 20 21 if(!options) 22 return new ol.style.Style(); 23 24 options = $.extend({}, options); 25 26 // NB: Legacy name support 27 var map = { 28 "fillcolor": "fillColor", 29 "opacity": "fillOpacity", 30 "linecolor": "strokeColor", 31 "lineopacity": "strokeOpacity", 32 "linethickness": "strokeWeight", 33 "lineDashArray": "lineDash", 34 }; 35 36 for(var name in options){ 37 if(name in map) 38 options[map[name]] = options[name]; 39 } 40 41 // Translate 42 if(options.strokeColor){ 43 var opacity = 1.0; 44 var weight = 1; 45 46 if("strokeOpacity" in options) 47 opacity = options.strokeOpacity; 48 49 if("strokeWeight" in options) 50 weight = options.strokeWeight; 51 52 let strokeConfig = { 53 color: WPGMZA.hexOpacityToString(options.strokeColor, opacity), 54 width: weight 55 }; 56 57 if("lineDash" in options){ 58 strokeConfig.lineDash = options.lineDash.split(" "); 59 } 60 61 translated.stroke = new ol.style.Stroke(strokeConfig); 62 } 63 64 if(options.fillColor){ 65 var opacity = 1.0; 66 67 if("fillOpacity" in options) 68 opacity = options.fillOpacity; 69 70 var color = WPGMZA.hexOpacityToString(options.fillColor, opacity); 71 72 translated.fill = new ol.style.Fill({ 73 color: color 74 }); 75 } 76 77 return new ol.style.Style(translated); 78 } 79 80 WPGMZA.OLFeature.setInteractionsOnFeature = function(feature, enable) 81 { 82 if(enable) 83 { 84 if(feature.modifyInteraction) 85 return; 86 87 feature.snapInteraction = new ol.interaction.Snap({ 88 source: feature.layer.getSource() 89 }); 90 91 feature.map.olMap.addInteraction(feature.snapInteraction); 92 93 feature.modifyInteraction = new ol.interaction.Modify({ 94 source: feature.layer.getSource() 95 }); 96 97 feature.map.olMap.addInteraction(feature.modifyInteraction); 98 99 feature.modifyInteraction.on("modifyend", function(event) { 100 feature.trigger("change"); 101 }); 102 103 // NB: I believe this was causing issues with an older version of OpenLayers when two interactions were simultaneiously on, worth trying again. 104 /*feature.translateInteraction = new ol.interaction.Translate({ 105 source: feature.layer.getSource() 106 }); 107 108 feature.map.olMap.addInteraction(feature.translateInteraction);*/ 109 } 110 else 111 { 112 if(!feature.modifyInteraction) 113 return; 114 115 if(feature.map) 116 { 117 feature.map.olMap.removeInteraction(feature.snapInteraction); 118 feature.map.olMap.removeInteraction(feature.modifyInteraction); 119 // feature.map.olMap.removeInteraction(feature.translateInteraction); 120 } 121 122 delete feature.snapInteraction; 123 delete feature.modifyInteraction; 124 // delete feature.translateInteraction; 125 } 126 } 127 128});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.