1/** 2 * @namespace WPGMZA 3 * @module OLPolygon 4 * @requires WPGMZA.Polygon 5 * @pro-requires WPGMZA.ProPolygon 6 */ 7jQuery(function($) { 8 9 var Parent; 10 11 WPGMZA.OLPolygon = function(options, olFeature) 12 { 13 var self = this; 14 15 Parent.call(this, options, olFeature); 16 17 if(olFeature) 18 { 19 this.olFeature = olFeature; 20 } 21 else 22 { 23 var coordinates = [[]]; 24 25 if(options && options.polydata) 26 { 27 var paths = this.parseGeometry(options.polydata); 28 29 // NB: We have to close the polygon in OpenLayers for the edit interaction to pick up on the last edge 30 for(var i = 0; i <= paths.length; i++) 31 coordinates[0].push(ol.proj.fromLonLat([ 32 parseFloat(paths[i % paths.length].lng), 33 parseFloat(paths[i % paths.length].lat) 34 ])); 35 } 36 37 this.olFeature = new ol.Feature({ 38 geometry: new ol.geom.Polygon(coordinates) 39 }); 40 } 41 42 this.layer = new ol.layer.Vector({ 43 source: new ol.source.Vector({ 44 features: [this.olFeature] 45 }) 46 }); 47 48 this.layer.getSource().getFeatures()[0].setProperties({ 49 wpgmzaPolygon: this, 50 wpgmzaFeature: this 51 }); 52 53 if(options) 54 this.setOptions(options); 55 } 56 57 if(WPGMZA.isProVersion()) 58 Parent = WPGMZA.ProPolygon; 59 else 60 Parent = WPGMZA.Polygon; 61 62 WPGMZA.OLPolygon.prototype = Object.create(Parent.prototype); 63 WPGMZA.OLPolygon.prototype.constructor = WPGMZA.OLPolygon; 64 65 WPGMZA.OLPolygon.prototype.getGeometry = function() 66 { 67 var coordinates = this.olFeature.getGeometry().getCoordinates()[0]; 68 var result = []; 69 70 for(var i = 0; i < coordinates.length; i++) 71 { 72 var lonLat = ol.proj.toLonLat(coordinates[i]); 73 var latLng = { 74 lat: lonLat[1], 75 lng: lonLat[0] 76 }; 77 result.push(latLng); 78 } 79 80 return result; 81 } 82 83 WPGMZA.OLPolygon.prototype.setVisible = function(visible) 84 { 85 this.layer.setVisible(visible ? true : false); 86 } 87 88 WPGMZA.OLPolygon.prototype.setOptions = function(options) 89 { 90 Parent.prototype.setOptions.apply(this, arguments); 91 92 if("editable" in options) 93 WPGMZA.OLFeature.setInteractionsOnFeature(this, options.editable); 94 } 95 96});
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.