US and Worldwide: +1 (866) 660-7555
Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: newMapComponent - dynamic source for shape information?

  1. #11
    Join Date
    Feb 2017
    Posts
    17

    Default

    i got this error:
    addinshape.js?v=1497978999742:44 Uncaught ReferenceError: inlineGeoJSON is not defined
    at addinshape.js?v=1497978999742:44
    at Object.define (cdf-bootstrap-script-includes.js?v=decdbcb…:54)
    at define (cdf-bootstrap-script-includes.js?v=decdbcb…:54)
    at addinshape.js?v=1497978999742:1
    i will try to solve it here
    Last edited by hugonr; 06-20-2017 at 01:18 PM. Reason: double post.

  2. #12
    Join Date
    Feb 2017
    Posts
    17

    Default

    This is the data from my query:

    Code:
    key     |fill |shape                                                                                             
    --------|-----|--------------------------------------------------------------------------------------------------
    3100104 |100  |[[[[-47.429672447,-18.1654308175596],[-47.429427,-18.1660609975595],[-47.4293999999999,-18.1664979
    3100203 |100  |[[[[-45.1392989999999,-19.2104779965869],[-45.139383,-19.2103539965869],[-45.139648,-19.2099619965
    3100302 |100  |[[[[-42.310709,-20.1427889966106],[-42.310904,-20.1429489966106],[-42.3110859999999,-20.1430979966
    3100401 |100  |[[[[-43.023869,-20.4102179966173],[-43.023848,-20.4102799966173],[-43.02379,-20.4105099966173],[-4
    3100500 |100  |[[[[-42.3620830000001,-18.9256939975795],[-42.3621019999999,-18.9257289965795],[-42.362184,-18.926
    3100609 |100  |[[[[-42.322711,-17.7842679965493],[-42.32248,-17.7844979965493],[-42.322056,-17.7847289965494],[-4
    and the script its like this now:

    Code:
    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)
            .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: "Polygon",
            coordinates: JSON.parse(coordinatesStr)
          }
        };
      }
    
    
      Dashboard.registerGlobalAddIn("NewMapComponent", "ShapeResolver", new AddIn(inlineGeoJSON));
    
    
      return inlineGeoJSON;
    });
    the error: one ";" in the polygonToGeoJson and the caps in the var name "inlineGeoJSON".

    now there are no errors, is not working but i will try from this code, thanks again Crusso!!!!!!
    Last edited by hugonr; 06-20-2017 at 01:42 PM. Reason: ident / correct code / insert data from query

  3. #13
    Join Date
    Feb 2017
    Posts
    17

    Default

    Quote Originally Posted by hugonr View Post
    This is the data from my query:

    Code:
    key     |fill |shape                                                                                             
    --------|-----|--------------------------------------------------------------------------------------------------
    3100104 |100  |[[[[-47.429672447,-18.1654308175596],[-47.429427,-18.1660609975595],[-47.4293999999999,-18.1664979
    3100203 |100  |[[[[-45.1392989999999,-19.2104779965869],[-45.139383,-19.2103539965869],[-45.139648,-19.2099619965
    3100302 |100  |[[[[-42.310709,-20.1427889966106],[-42.310904,-20.1429489966106],[-42.3110859999999,-20.1430979966
    3100401 |100  |[[[[-43.023869,-20.4102179966173],[-43.023848,-20.4102799966173],[-43.02379,-20.4105099966173],[-4
    3100500 |100  |[[[[-42.3620830000001,-18.9256939975795],[-42.3621019999999,-18.9257289965795],[-42.362184,-18.926
    3100609 |100  |[[[[-42.322711,-17.7842679965493],[-42.32248,-17.7844979965493],[-42.322056,-17.7847289965494],[-4
    and the script its like this now:

    Code:
    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)
            .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: "Polygon",
            coordinates: JSON.parse(coordinatesStr)
          }
        };
      }
    
    
      Dashboard.registerGlobalAddIn("NewMapComponent", "ShapeResolver", new AddIn(inlineGeoJSON));
    
    
      return inlineGeoJSON;
    });
    the error: one ";" in the polygonToGeoJson and the caps in the var name "inlineGeoJSON".

    now there are no errors, is not working but i will try from this code, thanks again Crusso!!!!!!
    Update:
    in my pre-execution code i got the caps problem, so i change it to this:

    Code:
    function f(){
      this.shapeResolver = "inlineGeoJSON";
      this.setAddInOptions("ShapeResolver", "inlineGeoJSON", { colIdx: 2});
    }
    correct caps.

    and now i got this error in console:

    CDF: Addin Error [inlineGeoJSON]: SyntaxError: Unexpected token o in JSON at position 1


    Dashboards.log @ cdf-bootstrap-script-includes.js?v=decdbcb…:4546
    AddIn.call @ cdf-bootstrap-script-includes.js?v=decdbcb…:4816
    resolveShapes @ CDF.js?v=ac929f4…:102
    resolveFeatures @ CDF.js?v=ac929f4…:107
    onDataReady @ CDF.js?v=ac929f4…:158
    (anonymous) @ cdf-bootstrap-script-includes.js?v=decdbcb…:5706
    (anonymous) @ cdf-bootstrap-script-includes.js?v=decdbcb…:4836
    fire @ cdf-bootstrap-script-includes.js?v=decdbcb…:176
    fireWith @ cdf-bootstrap-script-includes.js?v=decdbcb…:181
    done @ cdf-bootstrap-script-includes.js?v=decdbcb…:637
    callback @ cdf-bootstrap-script-includes.js?v=decdbcb…:673

    trying here to find out what is wrong

    UPDATE:
    Should be JSON.stringify and not JSON.parse?
    with that change, i got no errors, but i have no shapes yet.
    Last edited by hugonr; 06-20-2017 at 03:08 PM. Reason: maybe the parse?

  4. #14
    Join Date
    Jan 2014
    Posts
    161

    Default

    The shape column is supposed to be of type string, hence the JSON. parse.

  5. #15
    Join Date
    Jan 2014
    Posts
    161

    Default

    oh, it's not st.tableData[][], it's st.tableData.resultset[][]

  6. #16
    Join Date
    Jan 2014
    Posts
    161

  7. #17
    Join Date
    Feb 2017
    Posts
    17

    Default

    Quote Originally Posted by crusso View Post
    i tried, only corrected this:
    Code:
    function(){
      this.shapeResolver = "inlineGeoJSON";
      this.setAddInOptions("ShapeResolver", "inlineGeoJSON", { colIdx: 2});
    }
    because of caps.

    in the js file i logged the parse, and its showing the parse from my (now text) coordinates:

    Code:
      function polygonToGeoJson(coordinatesStr){
        console.log(JSON.parse(coordinatesStr));
        return {
          type: "Feature",
          geometry: {
            type: "Polygon",
            coordinates: JSON.parse(coordinatesStr)
          }
        };
      }
    but still i have no shapes.

    any ideas?

    (i will try here some other things in that code)
    Last edited by hugonr; 06-22-2017 at 01:42 PM. Reason: final result

  8. #18
    Join Date
    Feb 2017
    Posts
    17

    Default

    i did a console.log in the map var, and got this:

    Code:
    1100130: Object
      geometry: Object
        coordinates: Array(1)
          0: Array(1)
          length: 1
          __proto__: Array(0)
          type: "Polygon"
        __proto__: Object
        type: "Feature"
      __proto__: Object
    when i did a select in my database i got this (not my datasource, but the data from my table) i got this:
    Code:
    {"type":"MultiPolygon","coordinates":[[[[-62.050437771,-11.8673517413802],[-62.048899646,-11.8680616163802
    maybe this can help? Polygon and MultiPolygon?

    cheers

  9. #19
    Join Date
    Feb 2017
    Posts
    17

    Default

    OH YESSSSSS!!!!!!!!!!

    Code:
      function polygonToGeoJson(coordinatesStr){
        return {
          type: "Feature",
          geometry: {
            type: "MultiPolygon",
            coordinates: JSON.parse(coordinatesStr)
          }
        };
      }
    I changed this and now i have the shapes, all black, now i will work in the colors....

    Crusso, REAAAAAAALLY THANKS!!!!!!!!!

  10. #20
    Join Date
    Feb 2017
    Posts
    17

    Default

    For future reference (corrected codes, maybe other people will use it):

    https://gist.github.com/hugonr/64792...e89a903c5b51df

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •