Last active
June 22, 2017 18:10
-
-
Save hugonr/647928f920a8f5439be89a903c5b51df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
"cdf/AddIn", | |
"cdf/Dashboard.Clean", | |
"cdf/lib/jquery", | |
"amd!cdf/lib/underscore" | |
], function(AddIn, Dashboard, $, _) { | |
"use strict"; | |
var inlineGeoJSON = { | |
name: "inlineGeoJSON", | |
label: "Inline GeoJSON shape resolver", | |
defaults: { | |
colIdx: null, //column index containing the json map definitions | |
idPropertyName: "" //GeoJSON feature property that will be used to index the feature | |
}, | |
implementation: function(tgt, st, opt) { | |
var map = _.chain(st.tableData.resultset) | |
.map(function(row, idx){ | |
return [ | |
st.ids[idx], polygonToGeoJson(row[opt.colIdx]) | |
]; | |
}) | |
.object() | |
.value(); | |
var deferred = $.Deferred(); | |
deferred.resolve(map); | |
return deferred.promise(); | |
} | |
}; | |
function polygonToGeoJson(coordinatesStr){ | |
return { | |
type: "Feature", | |
geometry: { | |
type: "MultiPolygon", // you need to change this to Polygon if your coordinates are Polygon | |
coordinates: JSON.parse(coordinatesStr) | |
} | |
}; | |
} | |
Dashboard.registerGlobalAddIn("NewMapComponent", "ShapeResolver", new AddIn(inlineGeoJSON)); | |
return inlineGeoJSON; | |
}); | |
// Crusso's Pentaho forum code | |
// http://forums.pentaho.com/showthread.php?184502-newMapComponent-dynamic-source-for-shape-information |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(){ | |
this.shapeResolver = "inlineGeoJSON"; | |
this.setAddInOptions("ShapeResolver", "inlineGeoJSON", { colIdx: 2}); | |
} | |
// Crusso's Pentaho forum code | |
// http://forums.pentaho.com/showthread.php?184502-newMapComponent-dynamic-source-for-shape-information |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment