Select to view content in your preferred language

infoTemplates and featureTemplates

791
3
12-08-2010 02:51 PM
mdonnelly
Esri Contributor
Hi,

I'm trying to edit the infoTemplate for a featureTemplate that I created. Basically, I want to change the format from the standard one that comes with the template picker.

Does anyone know how to do this?

Regards,

Mark
Regards,
Mark
0 Kudos
3 Replies
mdonnelly
Esri Contributor
I'm not 100% sure this is the easiest way to go but it looks like I can use the feature template picker without the editor and program all the editor stuff myself.

Not exactly what I want to do as I like all the default editor handling. It's a hell of a work around just to get control of the infoTemplate.

Does anyone have any better ideas?

Mark
Regards,
Mark
0 Kudos
mdonnelly
Esri Contributor
I'm attempting to replace the editor widget with my own code to get greater control of the infotemplate.

When I create a new feature using the template picker I then want to show an info window with the attributes of that feature class. However, I'm running into problems:

If I use the 'onDrawEnd' event with the following code, the info window does not show the attributes. It simply shows the literal infoTemplate string: '{*}'.

dojo.connect(drawToolbar, "onDrawEnd", function(geometry) {
     drawToolbar.deactivate();
     editToolbar.deactivate();
     var newAttributes = dojo.mixin({},selectedTemplate.template.prototype.attributes);
     selectedTemplate.featureLayer.applyEdits([newGraphic], null, null);
     var infoTemplateInst = new esri.InfoTemplate("Attributes", "${*}");
     newGraphic.setInfoTemplate(infoTemplateInst);
     map.infoWindow.show(map.toScreen(newGraphic.geometry), map.getInfoWindowAnchor(map.toScreen(newGraphic.geometry)));
 });


If I use the 'onBeforeApplyEdits' event with the following code, info window does not show or is initially blank.

dojo.connect(featureLayers,"onBeforeApplyEdits", function(adds,updates,deletes) {
    dojo.forEach(adds, function(add) {
        var infoTemplateInst = new esri.InfoTemplate("Attributes", "${*}");
        add.setInfoTemplate(infoTemplateInst);
        map.infoWindow.show(map.toScreen(add.geometry),    map.getInfoWindowAnchor(map.toScreen(add.geometry)));
     });
 });


If I use the 'onClick' even with the following code it does work but it is initially blank. After I click again on the new feature, the info window displays correctly and continues to for subsequently created features.

dojo.connect(featureLayers, 'onClick', function(e) {
  var infoTemplateInst = new esri.InfoTemplate("Attributes", "${*}");
  e.graphic.setInfoTemplate(infoTemplateInst);
  map.infoWindow.show(map.toScreen(e.graphic.geometry),     map.getInfoWindowAnchor(map.toScreen(e.graphic.geometry)));
});


Has someone got an example of creating a new feature and then displaying an info window with the feature's attributes?
Regards,
Mark
0 Kudos
mdonnelly
Esri Contributor
Sorry, my first example for 'onDrawEnd' is missing the line that creates a the new graphic:

dojo.connect(drawToolbar, "onDrawEnd", function(geometry) {
     drawToolbar.deactivate();
     editToolbar.deactivate();
     var newAttributes = dojo.mixin({},selectedTemplate.template.prototype.attributes);
     var newGraphic = new esri.Graphic(geometry,null,newAttributes);
     selectedTemplate.featureLayer.applyEdits([newGraphic], null, null);
     var infoTemplateInst = new esri.InfoTemplate("Attributes", "${*}");
     newGraphic.setInfoTemplate(infoTemplateInst);
     map.infoWindow.show(map.toScreen(newGraphic.geometry), map.getInfoWindowAnchor(map.toScreen(newGraphic.geometry)));
 });


Note, I have also tried putting the setInfoTemplate statement before the applyEdits statement but it made no difference.
Regards,
Mark
0 Kudos