|
POST
|
For Flexviewer? This is built in to the Navigation widget in the latest Flexviewer release. Just above the navigation slider.
... View more
05-19-2011
11:31 AM
|
0
|
0
|
1016
|
|
POST
|
I haven't really thoroughly tested this, but it's working for me so far.
// minimum scale of map
// taken from http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer
private const SCALE:Number = 1128.497176;
private const LEVEL:int = 10;
private var _lods:Array;
// add this event listener somewhere
map.addEventListener(ExtentEvent.EXTENT_CHANGE, onMapExtentChange_handler);
protected function onMapExtentChange_handler(event:ExtentEvent):void
{
if (map.level)
{
if (!map.lods && map.scale > SCALE)
{
map.lods = _lods;
imageServiceLayer.visible = true;
}
else if (map.lods && LEVEL === map.level)
{
// somewhere in here
// you will need to turn off any TiledMapServiceLayer
// that has a minimum scale, like the World_Imagery service
// if not, this function will just get stuck in a loop
imageServiceLayer.visible = false;
_lods = map.lods;
map.lods = null;
// need to subtract a minor amout
// because map.scale
// is a number and precision issues
// were throwing off my map.scale > SCALE
// comparison above
map.scale = SCALE - 0.1;
}
}
}
In my case, I adjust the lods to only have 10 levels, but you'll want to use however many levels are in your app. You could probably just assign it from when the Map first loads and grab the map.lods.length and use that value through the rest of your application. I have been putting off really working on this because the functionality was broken in 2.X up until 2.1 or 2.2 I think, and I just have not gotten around to working it back in.
... View more
05-19-2011
08:28 AM
|
0
|
0
|
1176
|
|
POST
|
wsdl web services would probably suit most needs, depending on what you are doing. We started off using web services for some basic db queries, but when we moved to actually needing to do some ArcObjects for things like flow tracing or multiple spatial queries, we moved to WebOrb. I'm a big WebOrb fan, because if you can compile your functions to a dll, it's as simple as dropping it in a folder in your WebOrb directory and you can use it. There's even a browser console that will let you test your functions and provide sample code for Flex/Silverlight/Javascript. If you want to take advantage of using RemoteObjects with WebOrb or even FlourineFX, I put a library up of .net objects that serialize to their Flex counterparts. https://github.com/odoe/esri_dotnet_flex
... View more
05-17-2011
06:26 AM
|
0
|
0
|
661
|
|
POST
|
If it weren't for the mirror image issue, you could. Unfortuntely, I don't know how to get around that without first doing the preview because the Flash player has built in security that will not allow you to save a file without some sort of user interaction such as a button click. You can't do it off a timer or another other event. I have not tried to simulate a button click, but I don't think that would work. If you want to look into a multi-page option, maybe PDF would be a better solution. http://code.google.com/p/alivepdf/ AlivePDF is an actionscript library to save PDF files directly from Flash. It's very popular among many users on this forum and the process is similar to the way you are saving an image.
... View more
05-17-2011
05:44 AM
|
0
|
0
|
769
|
|
POST
|
Sure. The image data doesn't seem to like being added to the printBox until after the printBox is added to the stage. I updated the code sample in the link to reflect this. // I commented out this line of code
// where printImg is created
//printBox.addElement(printImg);
// I added this listener
printBox.addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void {
trace("added to stage");
printBox.addElement(printImg);
}); Now, the image should display and save correctly. I have to admit, I don't know why the image displays backwards if it's added to the component before the component is added to the stage. AddedToStage fires as soon as the component comes on screen (not necessarily viewable), but before it's done being rendered. CreationComplete should fire when the component is fully rendered and ready to be viewed. I can't seem to find a Component Lifecycle reference online directly from Adobe, but here are some slides http://www.flex888.com/1219/flex-4-components-life-cycle.html Here is a diagram of the UIComponent lifecycle (I have this printed and tacked to my office wall) http://danorlando.com/?p=122 Spark skins have a few more things that happen to manage skinning http://help.adobe.com/en_US/flex/using/WS460ee381960520ad-2811830c121e9107ecb-7fff.html#WS460ee381960520ad-2811830c121e9107ecb-7ffc And I know there are quite a few god Flex books that should include a more detailed description of the lifecycle process of what happens when you create a component. You don't usually need to worry about waiting for most of these events anymore, maybe creationComplete if you are modifying an MXML component. Flex 4 and Skinnning have made build components much easier than it used to be. This is just an odd case because we are using a component as a reference to generate an image, so there are considerations that need to be made about when that component is actually fully rendered and ready to be captured. Hope that helps.
... View more
05-13-2011
09:36 AM
|
0
|
0
|
769
|
|
POST
|
That was a weird one. It happened to me while testing, but if I waited for the addedToStage event, then add the image, it worked fine. That shouldn't happen if you wait for the creationComplete event, then view it.
... View more
05-13-2011
05:23 AM
|
0
|
0
|
769
|
|
POST
|
Ok, I tried a few things, modifying the Print Widget in Flexviewer and it's not the addedToStage event you want to listen for. Sorry, I forgot that in Flex, the FlexEvent.CreationComplete is what fires when all flex components are done being created. When that fiires, you can encode the component to PNG/JPG. But, here's the rub. You can't use FileReference on FlexEvents, they're sandboxed for security purposes. So, you would probably need to create a small preview window, then have second button to actually save the data. I reviewed the print functionality in one of my apps,and this how we do it for PDF saves. I need to create a preview, then a button to actually save the file. Rather than post snippets or the whole thing here, you can see the dirty way I modified the print widget to do this. https://gist.github.com/969352 Hope that helps. Sorry I had to dust off the cobwebs on this one 🙂
... View more
05-12-2011
12:21 PM
|
0
|
0
|
1398
|
|
POST
|
Hmm, sorry, at this point, I'm at a loss. I tried pretty much the same to save a map and it worked. Can you see the preview on your screen with everything added to it?
... View more
05-12-2011
10:39 AM
|
0
|
0
|
1398
|
|
POST
|
Looking at your code, I see that you are adding the printbox to your app at some point. I think the bitmap->png code is firing before the component has had a chance to draw. You can try waiting for the addedToStage event printBox.addEventListener(Event.ADDED_TO_STAGE, printBoxReady);
this.addChild(printBox);
function printBoxReady(e:Event):void
{
// code to turn your printbox into bitmapdata and encode to png
// and initialize your filereference
} At that point, you should be able to see your component, so it is fully drawn and ready. You'll probably want to wait to do this.addChild() until after you have added everything into printbox you want to add.
... View more
05-12-2011
10:14 AM
|
0
|
0
|
1398
|
|
POST
|
I ran into similar problem at some point, which I thought was weird. I ended up just parsing the json result, which is fast and gives me a little freedom to do some other stuff with it as well. https://github.com/odoe/LegendViewer/blob/master/src/net/odoe/flexmaptools/components/helpers/LayerExtractor.as
... View more
05-12-2011
10:04 AM
|
0
|
0
|
1112
|
|
POST
|
It looks like it should work and I just tested the BitmapData to PNG part and it works for me. The only thing I can think of is maybe you need to explicitly set height where you set the width. printBox.width = map.width;
printBox.height = map.height; Since you are creating the printBox in your function, it never actually gets added to the application stage, which is ok. But the events that occur when a Component is added (visually) to an application do the leg work for you of defining the componets width/height based on it's children. In this case, since the component is just used in this function, those lifecycle events never happen, thus printBox.height is proabably null. Explicitly setting it should work... I think 🙂
... View more
05-12-2011
07:39 AM
|
0
|
0
|
1398
|
|
POST
|
It's been a while since I've done this, but you can turn the component to a bitmap something like var bmd:BitmapData = new BitmapData(com.width, comp.height);
bmd.draw(comp, new Matrix());
var bm:Bitmap = new Bitmap(bmd); Then you can use a jpeg encoder to save the bitmapdata to a jpeg file. Flex Framework provides it's own JPEGEncoder mx.graphics.codec.JPEGEncoderYou just pass the BitmapData to the encoder and it does the work. Here is a demo of how to use the jpegencoder to save the image to disc. http://ntt.cc/2009/01/09/as3corelib-tutorialhow-to-use-jpegencoder-and-pngencoder-class-in-flex.html Hope that helps.
... View more
05-12-2011
06:09 AM
|
0
|
0
|
1398
|
|
POST
|
Not sure if it would matter, but can you verify of event.layer.loaded is true before adding it to legend? Not sure what the internals of the ESRI legend look like, but if the layers load event fires after adding it to legend, maybe it's adding it again internally.
... View more
05-11-2011
07:42 AM
|
0
|
0
|
344
|
|
POST
|
I would think it's that Flexviewer provides the basic foundation for an app, so someone can quickly get an app up and running without having to fuss with building out their app structure, event dispatchers, controllers and so on. It's pretty quick to get a widget up and going and drop it into Flexviewer. We have a couple of Flexviewer apps at work which has prompted me to build a few widgets in-house. Mainly, I build apps from scratch though, for various reasons and there are tools/workflows to get up and running such as ANT build/structure scripts, ProjectSprouts, Frameworks, etc. That doesn't mean your widgets need to built in such a way that they have to be tightly coupled to Flexviewer. I've been meaning to write more about this, but I put an example up of a widget where the component itself sits in a completely different package than the widget. http://www.arcgis.com/home/item.html?id=708ae903d3994999a3a861f35bf7408d Basewidget just adds the component and provides the map instance.
protected function basewidget_creationCompleteHandler(event:FlexEvent):void
{
var legend:LegendViewer=new LegendViewer();
legend.percentHeight=100;
legend.percentWidth=100;
legend.map=map;
wTemplate.addElement(legend);
}
The same component can be used in a completely non-Flexviewer app. I've seen a few other widgets built this way as well and I think it's good practice, especially when a Flexviewer update comes out. Then you would not need to modify the component itself in that case. The most you'd have to worry about is if the API requries you to change your component in some way. Now I'm rambling, but in general, I think it comes down to time restraints and manpower.
... View more
05-10-2011
12:33 PM
|
0
|
0
|
364
|
|
POST
|
It depends on what the event listener is acting upon. ItemRenderers are built to work in Lists/DataGrids that will have a collection of objects. The data object is a reference to that particular item that is selected in a List. Now that you have moved it to your main index.mxml file, what is the function acting upon? I see you're using a MouseEvent, so I assume a Button click. Where the email source coming from when you click that button?
... View more
05-05-2011
01:47 PM
|
0
|
0
|
553
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 2 weeks ago | |
| 1 | 12-09-2025 08:20 AM | |
| 1 | 11-13-2025 03:13 PM | |
| 2 | 11-06-2025 11:10 AM | |
| 3 | 11-05-2025 02:54 PM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|