UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) • 7.72 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import t from"../../core/Logger.js";import{animationDebugFlags as e}from"./animationDebugFlags.js";import{defaultCIMValues as n}from"./defaultCIMValues.js";import{AnimatedSymbolEasingType as o,AnimatedSymbolRepeatType as i}from"./enums.js";import{getExtent as r}from"./SDFHelper.js";import{getProcessParam as a,hasProcessParam as s,getSize as m,getValue as l}from"./utils.js";import{TimeOrigin as c}from"../../views/2d/engine/webgl/animations/instructions.js";function f(t,e,n){return{transform:k(t,e,n.transform),fromColor:v(t,e,n.fromColor),toColor:O(t,e,n.toColor),colorMix:x(t,e,n.colorMix),toOpacity:D(t,e,n.toOpacity),opacityMix:L(t,e,n.opacityMix),shift:R(t,e,n.shift),hasAnimations:n.hasAnimations||p(e),hasShiftAnimation:n.hasShiftAnimation||u(e),hasMotionAnimations:n.hasMotionAnimations||S(e)}}function p(t){return!!t.animations&&t.animations.length>0}function u(t){return!!t.animations&&t.animations.some((t=>"CIMSymbolAnimationMoveAlongLine"===t.type))}const y=new Set(["CIMSymbolAnimationOffset","CIMSymbolAnimationRotation","CIMSymbolAnimationSize","CIMSymbolAnimationScale"]);function S(t){return!!t.animations&&t.animations.some((t=>y.has(t.type)))}function d(t){return!e.forceStaticPath&&(e.forceAnimatedPath||t.hasAnimations)}function M(e,n,o){if("CIMCharacterMarker"===n.type)return t.getLogger("animationUtils").error("#handleMarker()","CIM character markers do not support animations"),o;const i=a(e,n,"OffsetX"),r=a(e,n,"OffsetY");if("CIMPictureMarker"===n.type)return{...o,transform:{type:"AnimatedTransform",relativeTranslation:!1,absoluteScale:!0,translation:V([i,r]),rotation:V(0),scale:V(a(e,n,"Size")),parent:o.transform}};const s=n.frame,m=s.ymax-s.ymin;return{...o,transform:{type:"AnimatedTransform",relativeTranslation:!1,absoluteScale:!1,translation:V([i,r]),rotation:V(0),scale:V({type:"Process",op:"Divide",left:a(e,n,"Size"),right:m}),parent:o.transform}}}function A(t,e){let n=0,o=0;const i="Absolute"!==t.anchorPointUnits;return t.anchorPoint&&(n=-t.anchorPoint.x,o=-t.anchorPoint.y),{...e,transform:{type:"AnimatedTransform",relativeTranslation:i,absoluteScale:!1,translation:V([n,o]),rotation:V(0),scale:V(1),parent:e.transform}}}function C(t,e){return"Absolute"===t.anchorPointUnits?e:A(t,e)}function g(t,e){return"Absolute"!==t.anchorPointUnits?e:A(t,e)}function h(t,e,n){return{...t,transform:{type:"AnimatedTransform",relativeTranslation:!1,absoluteScale:!1,translation:V([e,n]),rotation:V(0),scale:V(1),parent:t.transform}}}function P(t,e){const n=e?.5*-(e.xmin+e.xmax):0,o=e?.5*-(e.ymin+e.ymax):0;let i=0,a=0;if("x"in t&&"y"in t)i=t.x+n,a=t.y+o;else{const e=r(t);if(e){i=(e[0]+e[2])/2+n,a=(e[1]+e[3])/2+o}}return[i,a]}function b(t,e){switch(e.type){case"CIMPictureMarker":case"CIMVectorMarker":return a(t,e,"Rotation")}return 0}function I(t,e){switch(e.type){case"CIMPictureMarker":case"CIMVectorMarker":return a(t,e,"RotateClockwise")}return 0}function T(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 k(t,e,n){return{type:"AnimatedTransform",relativeTranslation:!1,absoluteScale:!1,translation:z(t,e),rotation:F(t,e),scale:j(t,e),parent:n}}function v(t,e,n){return{type:"AnimatedColor",color:V(T(t,e)),opacity:V(1),parent:n}}function O(t,e,n){const{animations:o}=e;let i=T(t,e);const r=o?.filter((t=>"CIMSymbolAnimationColor"===t.type))[0];return r&&(i=a(t,r,"ToColor")),{type:"AnimatedColor",color:V(i),opacity:V(1),parent:n}}function x(t,e,n){const{animations:o}=e,i=o?.filter((t=>"CIMSymbolAnimationColor"===t.type))[0];return i?{type:"AnimatedColor",color:V([1,1,1,1]),opacity:{from:0,to:1,timing:w(t,i?.animatedSymbolProperties)},parent:[1,1,1,1]}:n}function D(t,e,n){const{animations:o}=e;let i=V(1);const r=o?.filter((t=>"CIMSymbolAnimationTransparency"===t.type))[0];if(r){i=V({type:"Process",op:"Transparency",value:a(t,r,"ToTransparency")})}return{type:"AnimatedColor",color:V([1,1,1,1]),opacity:i,parent:n}}function L(t,e,n){const{animations:o}=e,i=o?.filter((t=>"CIMSymbolAnimationTransparency"===t.type))[0];return i?{type:"AnimatedColor",color:V([1,1,1,1]),opacity:{from:0,to:1,timing:w(t,i?.animatedSymbolProperties)},parent:[1,1,1,1]}:n}function R(t,e,n){const{animations:o}=e,i=o?.filter((t=>"CIMSymbolAnimationMoveAlongLine"===t.type))[0];if(!i)return n;let r,m;const l=w(t,i.animatedSymbolProperties),c=s(t,i,"DistanceAlong"),f=s(t,i,"Speed"),p=c&&a(t,i,"DistanceAlong"),u=f&&a(t,i,"Speed"),y=!0===i.continuous;if(!1!==p)r={type:"Process",op:"Divide",left:p,right:100},m=!0;else if(!1!==u)r={type:"Process",op:"Multiply",left:u,right:l.duration},m=!1;else{if(!y)throw new Error("Either distanceAlong, speed or continuous must be specified.");r=1,m=!0}return{type:"AnimatedShift",multiplyByLineLength:m,shift:{from:0,to:r,timing:l},parent:n}}function w(t,e){if(!e)return{duration:1,startTimeOffset:0,repeatDelay:0,timeOriginSelector:c.Local,repeatType:i.Loop,easing:o.Linear,playAnimation:1,reverseAnimation:0};const r=a(t,e,"Duration");let s;if(a(t,e,"RandomizeStartTime")){s={type:"Process",op:"Random",min:0,max:r,seed:a(t,e,"RandomizeStartSeed")}}else s=a(t,e,"StartTimeOffset");const m=a(t,e,"RepeatDelay"),f=a(t,e,"PlayAnimation"),p=a(t,e,"ReverseAnimation"),u=l(e.repeatType,n.CIMAnimatedSymbolProperties.repeattype);return{duration:r,startTimeOffset:s,repeatDelay:m,timeOriginSelector:u===i.None?c.Local:c.Global,repeatType:u,easing:l(e.easing,n.CIMAnimatedSymbolProperties.easing),playAnimation:f,reverseAnimation:p}}function j(t,e){const{animations:n}=e;let o;o="CIMPictureMarker"===e.type||"CIMVectorMarker"===e.type?a(t,e,"Size"):"CIMSolidStroke"===e.type||"CIMPictureStroke"===e.type?a(t,e,"Width"):m(e)||10;const i=n?.filter((t=>"CIMSymbolAnimationScale"===t.type))[0];if(!i){const e=n?.filter((t=>"CIMSymbolAnimationSize"===t.type))[0];if(!e)return V(1);return{from:1,to:{type:"Process",op:"Divide",left:a(t,e,"ToSize"),right:o},timing:w(t,e.animatedSymbolProperties)}}return{from:1,to:a(t,i,"ScaleFactor"),timing:w(t,i.animatedSymbolProperties)}}function z(t,e){const{animations:n}=e,o=n?.filter((t=>"CIMSymbolAnimationOffset"===t.type))[0];if(!o)return V([0,0]);return{from:[0,0],to:[a(t,o,"OffsetX"),a(t,o,"OffsetY")],timing:w(t,o.animatedSymbolProperties)}}function F(t,e){const{animations:n}=e,o=I(t,e),i={type:"Process",op:"Divide",left:b(t,e),right:{type:"Process",op:"Cond",condition:o,ifTrue:-1,ifFalse:1}},r=n?.filter((t=>"CIMSymbolAnimationRotation"===t.type))[0];if(!r)return V(i);const s={type:"Process",op:"Add",left:a(t,r,"ToRotation"),right:{type:"Process",op:"Divide",left:i,right:-1}};return{from:i,to:{type:"Process",op:"Add",left:i,right:{type:"Process",op:"Cond",condition:a(t,r,"RotateClockwise"),ifTrue:{type:"Process",op:"MatchWinding",sign:-1,angle:s},ifFalse:{type:"Process",op:"MatchWinding",sign:1,angle:s}}},timing:w(t,r.animatedSymbolProperties)}}function V(t){return{from:t,to:t,timing:{duration:1,startTimeOffset:0,repeatDelay:0,timeOriginSelector:c.Local,repeatType:i.Loop,easing:o.Linear,playAnimation:1,reverseAnimation:0}}}function U(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(U(t[e]))return!0;return!1}export{U as checkForAnimations,f as getAnimationParams,P as getFrameTranslation,V as getStaticParam,g as handleAbsoluteAnchor,A as handleAnchor,M as handleMarker,C as handleRelativeAnchor,d as shouldUseAnimatedPath,h as translate};