Extending esri/dijit/Popup

1094
4
10-04-2013 09:06 AM
GeorgeSimpson
Occasional Contributor
I'm looking to extend Popup to handle my custom results.  The results are not in the format expected by the Popup so the Popup will error out when I try to use them.  I've been playing around a little bit with this and can get fairly close except there are a lot of methods on popup that still error out.  It is very difficult for me to just overwrite these methods because I like the functionality of the Popup which is why I want to extend it.  This was supposed to save me a lot of time by not having to write my own, but it doesn't look that way now.  Anyway, the main idea is for the new Popup to behave exactly as the original, only it can accept a different type of results for .setFeatures().  I could pull all of the functionality I need out and just use .show() and .setContent() but I really like the paging controls, etc and so was hoping to use those.  My results are actually an array of objects from a database query.  Each record has a "features" property that contains the features associated with it.  I do it this way because one record can have multiple features and I want to step through the records, not the features.

Anyone have any ideas or suggestions?

Here's an example of what my results look like:


[
  {id:1,
    field1:"somevalue",
    field2:"somevalue2",
    ...,
    features:[
        {id:1,geometry:{}},
        {id:2,geometry:{}}
    ]
   }
]

0 Kudos
4 Replies
BenFousek
Occasional Contributor III
Why not create an array of features (graphics) and use setFeatures as normal?

The Graphic class allows you to transform data in any format to an object the api understands.

I use php and mysql to store records which are primarily created and edited through web forms, and viewed in reports outside the mapping application. But they have a geographic component, mostly point geometry (x/y). I use both user based queries and pseudo-feature layers (a graphics layer wired up for onPanEnd and onZoomEnd to request using map bounds). The records aren't returned in the same format as arcgis server returns them. So I create graphics with the results, and use them just like I would with ags results from query, identify, etc.

As far as handling multiple features per record:
var features = [];
dojo.forEach(results), function (result) {
  dojo.forEach(result.features, function (feat) {
    var graphic = new esri.Graphic();
    graphic.setSymbol(SOME_SYMBOL);
    graphic.setGeometry(feat.geometry);
    graphic.setAttribures({
      resultId: result.id,
      featureId: feat.id,
      field1: result.field1,
      field2: result.field2
    });
    graphic.setInfoTemplate(new esri.infoTemplate('My Features', '${*}');
    features.push(graphic);
  });
});
0 Kudos
GeorgeSimpson
Occasional Contributor
I thought about that but was hoping to avoid paging through multiple features that represented a single record.  I really want to be able to show the attributes and all of the associated features at one time.  This way the user would see the business data in the popup and the features for that record would be highlighted on the map.
0 Kudos
BenFousek
Occasional Contributor III
If they are points, why not esri.geometry.Multipoint?

If not, I would assume there is a way to create multi-part graphics by merging geometries. I've never done that creating custom graphics, but server returns multi-part features, e.g. a parcel of land with a right-of-way through it, as a single geometry/graphic.
0 Kudos
GeorgeSimpson
Occasional Contributor
Unfortunately, they can be points,lines and/or polygons.

That sounds like a good approach.  I'm going to see if that's doable
0 Kudos