@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 6.68 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import t from"../../core/Logger.js";import{animationDebugFlags as e}from"./animationDebugFlags.js";import{defaultCIMValues as r}from"./defaultCIMValues.js";import{AnimatedSymbolRepeatType as o,AnimatedSymbolEasingType as n}from"./enums.js";import{getExtent as i}from"./SDFHelper.js";import{getProcessParam as a,getValue as s,getSize as c}from"./utils.js";import{TimeOrigin as m}from"../../views/2d/engine/webgl/animations/instructions.js";function l(t,e,r){return{transform:g(t,e,r.transform),fromColor:b(t,e,r.fromColor),toColor:I(t,e,r.toColor),colorMix:T(t,e,r.colorMix),toOpacity:h(t,e,r.toOpacity),opacityMix:k(t,e,r.opacityMix),hasAnimations:r.hasAnimations||!!e.animations&&e.animations.length>0}}function p(t){return!e.forceStaticPath&&(e.forceAnimatedPath||t.hasAnimations)}function f(e,r,o){if("CIMCharacterMarker"===r.type)return t.getLogger("animationUtils").error("#handleMarker()","CIM character markers do not support animations"),o;const n=a(e,r,"OffsetX"),i=a(e,r,"OffsetY");if("CIMPictureMarker"===r.type)return{...o,transform:{type:"AnimatedTransform",relativeTranslation:!1,absoluteScale:!0,translation:R([n,i]),rotation:R(0),scale:R(a(e,r,"Size")),parent:o.transform}};const s=r.frame,c=s.ymax-s.ymin;return{...o,transform:{type:"AnimatedTransform",relativeTranslation:!1,absoluteScale:!1,translation:R([n,i]),rotation:R(0),scale:R({type:"Process",op:"Divide",left:a(e,r,"Size"),right:c}),parent:o.transform}}}function u(t,e){let r=0,o=0;const n="Absolute"!==t.anchorPointUnits;return t.anchorPoint&&(r=-t.anchorPoint.x,o=-t.anchorPoint.y),{...e,transform:{type:"AnimatedTransform",relativeTranslation:n,absoluteScale:!1,translation:R([r,o]),rotation:R(0),scale:R(1),parent:e.transform}}}function y(t,e){return"Absolute"===t.anchorPointUnits?e:u(t,e)}function C(t,e){return"Absolute"!==t.anchorPointUnits?e:u(t,e)}function M(t,e,r){return{...t,transform:{type:"AnimatedTransform",relativeTranslation:!1,absoluteScale:!1,translation:R([e,r]),rotation:R(0),scale:R(1),parent:t.transform}}}function d(t,e){const r=e?.5*-(e.xmin+e.xmax):0,o=e?.5*-(e.ymin+e.ymax):0;let n=0,a=0;if("x"in t&&"y"in t)n=t.x+r,a=t.y+o;else{const e=i(t);if(e){n=(e[0]+e[2])/2+r,a=(e[1]+e[3])/2+o}}return[n,a]}function S(t,e){switch(e.type){case"CIMPictureMarker":case"CIMVectorMarker":return a(t,e,"Rotation")}return 0}function A(t,e){switch(e.type){case"CIMPictureMarker":case"CIMVectorMarker":return a(t,e,"RotateClockwise")}return 0}function P(t,e){switch(e.type){case"CIMPointSymbol":case"CIMVectorMarker":return[1,1,1,1];case"CIMSolidStroke":case"CIMSolidFill":return a(t,e,"Color");case"CIMPictureMarker":case"CIMPictureStroke":case"CIMPictureFill":return a(t,e,"TintColor")}return[1,1,1,1]}function g(t,e,r){return{type:"AnimatedTransform",relativeTranslation:!1,absoluteScale:!1,translation:O(t,e),rotation:D(t,e),scale:x(t,e),parent:r}}function b(t,e,r){return{type:"AnimatedColor",color:R(P(t,e)),opacity:R(1),parent:r}}function I(t,e,r){const{animations:o}=e;let n=P(t,e);const i=o?.filter((t=>"CIMSymbolAnimationColor"===t.type))[0];return i&&(n=a(t,i,"ToColor")),{type:"AnimatedColor",color:R(n),opacity:R(1),parent:r}}function T(t,e,r){const{animations:o}=e,n=o?.filter((t=>"CIMSymbolAnimationColor"===t.type))[0];return n?{type:"AnimatedColor",color:R([1,1,1,1]),opacity:{from:0,to:1,timing:v(t,n?.animatedSymbolProperties)},parent:[1,1,1,1]}:r}function h(t,e,r){const{animations:o}=e;let n=R(1);const i=o?.filter((t=>"CIMSymbolAnimationTransparency"===t.type))[0];if(i){n=R({type:"Process",op:"Transparency",value:a(t,i,"ToTransparency")})}return{type:"AnimatedColor",color:R([1,1,1,1]),opacity:n,parent:r}}function k(t,e,r){const{animations:o}=e,n=o?.filter((t=>"CIMSymbolAnimationTransparency"===t.type))[0];return n?{type:"AnimatedColor",color:R([1,1,1,1]),opacity:{from:0,to:1,timing:v(t,n?.animatedSymbolProperties)},parent:[1,1,1,1]}:r}function v(t,e){if(!e)return{duration:1,startTimeOffset:0,repeatDelay:0,timeOriginSelector:m.Local,repeatType:o.Loop,easing:n.Linear,playAnimation:1,reverseAnimation:0};const i=a(t,e,"Duration");let c;if(a(t,e,"RandomizeStartTime")){c={type:"Process",op:"Random",min:0,max:i,seed:a(t,e,"RandomizeStartSeed")}}else c=a(t,e,"StartTimeOffset");const l=a(t,e,"RepeatDelay"),p=a(t,e,"PlayAnimation"),f=a(t,e,"ReverseAnimation"),u=s(e.repeatType,r.CIMAnimatedSymbolProperties.repeattype);return{duration:i,startTimeOffset:c,repeatDelay:l,timeOriginSelector:u===o.None?m.Local:m.Global,repeatType:u,easing:s(e.easing,r.CIMAnimatedSymbolProperties.easing),playAnimation:p,reverseAnimation:f}}function x(t,e){const{animations:r}=e;if("CIMPictureMarker"!==e.type&&"CIMVectorMarker"!==e.type&&"CIMPointSymbol"!==e.type)return R(1);let o;o="CIMPictureMarker"===e.type||"CIMVectorMarker"===e.type?a(t,e,"Size"):c(e)||10;const n=r?.filter((t=>"CIMSymbolAnimationScale"===t.type))[0];if(!n){const e=r?.filter((t=>"CIMSymbolAnimationSize"===t.type))[0];if(!e)return R(1);return{from:1,to:{type:"Process",op:"Divide",left:a(t,e,"ToSize"),right:o},timing:v(t,e.animatedSymbolProperties)}}return{from:1,to:a(t,n,"ScaleFactor"),timing:v(t,n.animatedSymbolProperties)}}function O(t,e){const{animations:r}=e,o=r?.filter((t=>"CIMSymbolAnimationOffset"===t.type))[0];if(!o)return R([0,0]);return{from:[0,0],to:[a(t,o,"OffsetX"),a(t,o,"OffsetY")],timing:v(t,o.animatedSymbolProperties)}}function D(t,e){const{animations:r}=e,o=A(t,e),n={type:"Process",op:"Divide",left:S(t,e),right:{type:"Process",op:"Cond",condition:o,ifTrue:-1,ifFalse:1}},i=r?.filter((t=>"CIMSymbolAnimationRotation"===t.type))[0];if(!i)return R(n);const s={type:"Process",op:"Add",left:a(t,i,"ToRotation"),right:{type:"Process",op:"Divide",left:n,right:-1}};return{from:n,to:{type:"Process",op:"Add",left:n,right:{type:"Process",op:"Cond",condition:a(t,i,"RotateClockwise"),ifTrue:{type:"Process",op:"MatchWinding",sign:-1,angle:s},ifFalse:{type:"Process",op:"MatchWinding",sign:1,angle:s}}},timing:v(t,i.animatedSymbolProperties)}}function R(t){return{from:t,to:t,timing:{duration:1,startTimeOffset:0,repeatDelay:0,timeOriginSelector:m.Local,repeatType:o.Loop,easing:n.Linear,playAnimation:1,reverseAnimation:0}}}function L(t){if(null==t)return!1;if("object"!=typeof t)return!1;if(t.animations&&Array.isArray(t.animations)&&t.animations.length>0)return!0;for(const e in t)if(L(t[e]))return!0;return!1}export{L as checkForAnimations,l as getAnimationParams,d as getFrameTranslation,R as getStaticParam,C as handleAbsoluteAnchor,u as handleAnchor,f as handleMarker,y as handleRelativeAnchor,p as shouldUseAnimatedPath,M as translate};