maptalks.plot/dist/maptalks.plot.min.js
2017-12-12 22:42:17 +08:00

6 lines
9.0 KiB
JavaScript

/*!
* maptalks.plot v0.0.0
* LICENSE : MIT
* (c) 2017-2017 https://sakitam-fdd.github.io/maptalks.plot
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("maptalks")):"function"==typeof define&&define.amd?define(["exports","maptalks"],e):e(t.MaptalksPlot={},t.maptalks)}(this,function(t,e){"use strict";var o="Polyline",r="FreeLine",n=Object.freeze({TextArea:"TextArea",ARC:"Arc",CURVE:"Curve",GATHERING_PLACE:"GatheringPlace",POLYLINE:o,FREE_LINE:r,POINT:"Point",PENNANT:"Pennant",RECTANGLE:"RectAngle",CIRCLE:"Circle",ELLIPSE:"Ellipse",LUNE:"Lune",SECTOR:"Sector",CLOSED_CURVE:"ClosedCurve",POLYGON:"Polygon",FREE_POLYGON:"FreePolygon",ATTACK_ARROW:"AttackArrow",DOUBLE_ARROW:"DoubleArrow",STRAIGHT_ARROW:"StraightArrow",FINE_ARROW:"FineArrow",ASSAULT_DIRECTION:"AssaultDirection",TAILED_SQUAD_COMBAT:"TailedSquadCombat",TAILED_ATTACK_ARROW:"TailedAttackArrow",SQUAD_COMBAT:"SquadCombat",RECTFLAG:"RectFlag",TRIANGLEFLAG:"TriangleFlag",CURVEFLAG:"CurveFlag"}),i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s=(function(){function t(t){this.value=t}function e(e){function o(n,i){try{var s=e[n](i),a=s.value;a instanceof t?Promise.resolve(a.value).then(function(t){o("next",t)},function(t){o("throw",t)}):r(s.done?"return":"normal",s.value)}catch(t){r("throw",t)}}function r(t,e){switch(t){case"return":n.resolve({value:e,done:!0});break;case"throw":n.reject(e);break;default:n.resolve({value:e,done:!1})}(n=n.next)?o(n.key,n.arg):i=null}var n,i;this._invoke=function(t,e){return new Promise(function(r,s){var a={key:t,arg:e,resolve:r,reject:s,next:null};i?i=i.next=a:(n=i=a,o(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),a=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},u=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},c=e.Canvas,l=function(t){function e(){return s(this,e),u(this,t.apply(this,arguments))}return a(e,t),e.prototype._arc=function(t,e,o){for(var r=this.options.arcDegree*Math.PI/180,n=1,i=e.length;n<i;n++)c._arcBetween(t,e[n-1],e[n],r),c._stroke(t,o)},e.prototype._quadraticCurve=function(t,e){e.length<=2?c._path(t,e):c.quadraticCurve(t,e)},e.prototype._bezierCurve=function(t,e){if(e.length<=3)c._path(t,e);else{var o=void 0,r=void 0;for(o=1,r=e.length;o+2<r;o+=3)t.bezierCurveTo(e[o].x,e[o].y,e[o+1].x,e[o+1].y,e[o+2].x,e[o+2].y);if(o<r)for(;o<r;o++)t.lineTo(e[o].x,e[o].y)}},e.prototype._toJSON=function(t){return{feature:this.toGeoJSON(t),subType:"Curve"}},e.prototype._paintOn=function(t,e,o){t.beginPath(),this._arc(t,e,o),c._stroke(t,o),this._paintArrow(t,e,o)},e.fromJSON=function(t){var o=t.feature,r=new e(o.geometry.coordinates,t.options);return r.setProperties(o.properties),r},e}(e.LineString);l.registerJSONType("Curve"),l.mergeOptions({arcDegree:90});var h=e.Coordinate,f=function(t){function e(o){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,e);var n=u(this,t.call(this,r));return n.type="Polyline",o&&n.setCoordinates(o),n}return a(e,t),e.prototype._exportGeoJSONGeometry=function(){var t=this.getCoordinates();return{type:"LineString",coordinates:h.toNumberArrays(t)}},e.prototype._toJSON=function(t){return{feature:this.toGeoJSON(t)}},e}(e.LineString);f.mergeOptions({arrowStyle:null,arrowPlacement:"vertex-last",clipToPaint:!0}),f.registerJSONType("Polyline");var p=e.Coordinate,y=function(t){function e(o){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,e);var n=u(this,t.call(this,r));return n.type="FreeLine",o&&n.setCoordinates(o),n}return a(e,t),e.prototype._exportGeoJSONGeometry=function(){var t=this.getCoordinates();return{type:"LineString",coordinates:p.toNumberArrays(t)}},e.prototype._toJSON=function(t){return{feature:this.toGeoJSON(t)}},e}(e.LineString);y.mergeOptions({arrowStyle:null,arrowPlacement:"vertex-last",clipToPaint:!0}),y.registerJSONType("FreeLine");var d={};d.Curve={action:"clickDblclick",create:function(t){return new l(t)},update:function(t,e){e.setCoordinates(t)},generate:function(t){return t}},d[o]={action:"clickDblclick",create:function(t){return new f(t)},update:function(t,e){e.setCoordinates(t)},generate:function(t){return t}},d[r]={action:"mouseup",create:function(t){return new y(t)},update:function(t,e){e.setCoordinates(t)},generate:function(t){return t}};var g=function(t){var e=void 0===t?"undefined":i(t);return null!==t&&("object"===e||"function"===e)},_=function t(e,o){for(var r in o)g(o[r])&&g(e[r])?t(e[r],o[r]):e[r]=o[r];return e},v=e.Polygon,m={symbol:{lineColor:"#000",lineWidth:2,lineOpacity:1,polygonFill:"#fff",polygonOpacity:.3},doubleClickZoom:!1,mode:null,once:!1,ignoreMouseleave:!0},C={},b=function(t){function e(){var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s(this,e);var r=_(m,o),n=u(this,t.call(this,r));return n.options=r,n._checkMode(),n}return a(e,t),e.prototype._getRegisterMode=function(){var t=this.getMode(),o=e.getRegisterMode(t);if(!o)throw new Error(t+" is not a valid mode of DrawTool.");return o},e.prototype.setSymbol=function(t){return t?(this.options.symbol=t,this._geometry&&this._geometry.setSymbol(t),this):this},e.prototype._clickForPath=function(t){var e=this._getRegisterMode(),o=t.coordinate,r=this.getSymbol();this._geometry?(null!==this._historyPointer&&(this._clickCoords=this._clickCoords.slice(0,this._historyPointer)),this._clickCoords.push(o),this._historyPointer=this._clickCoords.length,e.update(this._clickCoords,this._geometry,t),this._fireEvent("drawvertex",t)):(this._clickCoords=[o],this._geometry=e.create(this._clickCoords,t),r&&this._geometry.setSymbol(r),this._addGeometryToStage(this._geometry),this._fireEvent("drawstart",t))},e.prototype._mousemoveForPath=function(t){var e=this.getMap();if(this._geometry&&e&&!e.isInteracting()){var o=this._getMouseContainerPoint(t);if(this._isValidContainerPoint(o)){var r=t.coordinate,n=this._getRegisterMode(),i=this._clickCoords.slice(0,this._historyPointer);i&&i.length>0&&r.equals(i[i.length-1])||(n.update(i.concat([r]),this._geometry,t),this._fireEvent("mousemove",t))}}},e.prototype._dblclickForPath=function(t){if(this._geometry){var e=this._getMouseContainerPoint(t);if(this._isValidContainerPoint(e)){var o=this._getRegisterMode(),r=t.coordinate,n=this._clickCoords;if(n.push(r),!(n.length<2)){for(var i=[],s=1,a=n.length;s<a;s++)n[s].x===n[s-1].x&&n[s].y===n[s-1].y&&i.push(s);for(var u=i.length-1;u>=0;u--)n.splice(i[u],1);n.length<2||this._geometry&&this._geometry instanceof v&&n.length<3||(o.update(n,this._geometry,t),this.endDraw(t))}}}},e.prototype._mousedownToDraw=function(t){function e(t){var e=n.getSymbol(),o=n._geometry;o?r.update(t.coordinate,o,t):((o=r.create(t.coordinate,t)).setSymbol(e),n._addGeometryToStage(o),n._geometry=o)}var o=this._map,r=this._getRegisterMode(),n=this,i=this._getMouseContainerPoint(t);if(!this._isValidContainerPoint(i))return!1;var s=function(o){if(!this._geometry)return!1;var r=this._getMouseContainerPoint(o);return!!this._isValidContainerPoint(r)&&(e(o),this._fireEvent("mousemove",t),!1)},a=function r(n){if(o.off("mousemove",s,this),o.off("mouseup",r,this),this.options.ignoreMouseleave||o.off("mouseleave",r,this),!this._geometry)return!1;var i=this._getMouseContainerPoint(n);return this._isValidContainerPoint(i)&&e(n),this.endDraw(t),!1};return this._fireEvent("drawstart",t),e(t),o.on("mousemove",s,this),o.on("mouseup",a,this),this.options.ignoreMouseleave||o.on("mouseleave",a,this),!1},e.prototype.getEvents=function(){var t=this._getRegisterMode().action;return"clickDblclick"===t?{click:this._clickForPath,mousemove:this._mousemoveForPath,dblclick:this._dblclickForPath}:"click"===t?{click:this._clickForPoint}:"drag"===t?{mousedown:this._mousedownToDraw}:"mouseup"===t?{mousedown:this._mousedownToDraw}:null},e.registerMode=function(t,e){C[t.toLowerCase()]=e},e.getRegisterMode=function(t){return C[t.toLowerCase()]},e.registeredModes=function(t){if(t){var e=Reflect.ownKeys(t),o=Array.isArray(e),r=0;for(e=o?e:e[Symbol.iterator]();;){var n;if(o){if(r>=e.length)break;n=e[r++]}else{if((r=e.next()).done)break;n=r.value}var i=n;if(!i.match(/^(?:constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/)){var s=Object.getOwnPropertyDescriptor(t,i),a=i.toLowerCase();Object.defineProperty(C,a,s),console.log(C)}}}},e}(e.DrawTool);b.registeredModes(d),t.PlotDraw=b,t.PlotTypes=n,Object.defineProperty(t,"__esModule",{value:!0})});