{"id":26582,"library":"vega2ol","title":"vega2ol","description":"A TypeScript library that transpiles Vega expressions to OpenLayers array-based expression format. v1.1.1 (latest), stable release. Key differentiator: bridges Vega-Lite/Vega visualization specs with OpenLayers map styling by converting conditional logic, math/string/array functions, and member access (e.g., datum.field) into OpenLayers expressions like ['case', ['>', ['get', 'value'], 100], 'red', 'blue']. Ideal for OpenLayers users who prefer Vega's concise JavaScript-like syntax.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/geojupyter/vega2ol","tags":["javascript","vega","openlayers","expression","transpiler","geospatial","typescript"],"install":[{"cmd":"npm install vega2ol","lang":"bash","label":"npm"},{"cmd":"yarn add vega2ol","lang":"bash","label":"yarn"},{"cmd":"pnpm add vega2ol","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Parses Vega expression strings into an Abstract Syntax Tree (AST) for transpilation.","package":"vega-expression","optional":false}],"imports":[{"note":"ESM-only, shipped with TypeScript type definitions. Named export only; no default export.","wrong":"const vega2ol = require('vega2ol')","symbol":"vega2ol","correct":"import { vega2ol } from 'vega2ol'"},{"note":"Only a named export exists. Default import is not valid and will throw at runtime.","wrong":"import vega2ol from 'vega2ol'","symbol":"vega2ol (default import)","correct":"import { vega2ol } from 'vega2ol'"},{"note":"Class for advanced usage if you need to extend or customize the transpiler. Exported but typically not imported directly; use vega2ol() function instead.","wrong":"import { Visitor } from 'vega2ol'","symbol":"VegaToOLVisitor","correct":"import { VegaToOLVisitor } from 'vega2ol'"}],"quickstart":{"code":"import { vega2ol } from 'vega2ol';\n\nconst vegaExpr = \"datum.population > 1000000 ? '#FF0000' : '#0000FF'\";\nconst olExpr = vega2ol(vegaExpr);\nconsole.log(olExpr);\n// ['case', ['>', ['get', 'population'], 1000000], '#FF0000', '#0000FF']\n\nconst style = {\n  'fill-color': olExpr,\n  'fill-opacity': vega2ol(\"datum.category == 'important' ? 1 : 0.5\")\n};\nconsole.log(style);","lang":"typescript","description":"Transpile a Vega conditional expression to OpenLayers format and apply to a style object."},"warnings":[{"fix":"Check the documentation for a list of supported functions. Use only supported functionality or manually translate complex expressions.","message":"vega2ol does not support all Vega functions (e.g., instanceof, regexp). Unsupported functions will cause a runtime error.","severity":"gotcha","affected_versions":"<=1.1.1"},{"fix":"Ensure your Vega expression is valid per Vega specification; avoid trailing commas or invalid operators.","message":"The library uses vega-expression to parse expressions, which may have its own quirks (e.g., strict syntax). Incorrect Vega syntax will throw parse errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the returned array directly in OpenLayers style objects; do not call JSON.stringify() unless you intend to send it as data.","message":"OpenLayers expression format is array-based, not an object or string. vega2ol returns arrays; do not stringify them prematurely.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use only datum.fieldName pattern; OpenLayers expressions use ['get', 'x'] to access feature attributes. Ensure your feature has the expected property keys.","message":"Member access like datum.x is always converted to ['get', 'x'], which reads from OpenLayers feature properties. If your data is stored differently (e.g., in a different property name), you need to adjust the expression.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure the package is installed: npm install vega2ol. Use ESM import syntax: import { vega2ol } from 'vega2ol'.","cause":"Missing installation or incorrect import in CommonJS environment.","error":"TypeError: Cannot find module 'vega2ol'"},{"fix":"Use only supported functions: floor, ceil, round, abs, sqrt, pow, log, exp, sin, cos, tan, min, max, tostring, upper, lower, substring, length, indexof, slice, type, isvalid, isnumber, isstring, isboolean.","cause":"The expression uses a function not supported by vega2ol.","error":"Error: Unsupported expression type: CallExpression with function 'myFunc'"},{"fix":"Remove trailing semicolons and ensure valid Vega expression syntax. For example, use datum.x > 5 ? 'a' : 'b' without semicolons.","cause":"Vega expression syntax error, often due to trailing semicolon or extra punctuation.","error":"SyntaxError: Expected ')' but got ';'"},{"fix":"Change import statement to import { vega2ol } from 'vega2ol'.","cause":"Using default import instead of named import.","error":"TypeError: vega2ol is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}