|
POST
|
This is probably how I would handle it. You can create one function to capture all the button clicks and let that function handle what happens. You can also make sure the Identify Task will not fire when you just want to zoom or pan.
<fx:Script>
<![CDATA[
protected static const IDENTIFY:String = "identify";
protected function activateIdentify():void {
map.addEventListener(MapMouseEvent.MAP_CLICK, onMapClicked_handler);
}
protected function onMapClicked_handler(event:MapMouseEvent):void {
var idParams:IdentifyParameters = new IdentifyParameters();
idParams.layerIds = [layerId];
idParams.tolerance = 2;
idParams.returnGeometry = true;
// grab your event.mapPoint and use it for your Identify tool
idParams.geometry = event.mapPoint;
idParams.width = _map.width;
idParams.height = _map.height;
idParams.mapExtent = _map.extent;
idParams.spatialReference = _map.spatialReference;
idParams.layerOption = "all";
var idSym:SimpleMarkerSymbol = new SimpleMarkerSymbol("x", 12, 0xFF0000);
var g:Graphic = new Graphic(event.mapPoint, idSym);
// idLayer is a graphicsLayer I use to
// just show where I clicked on the map
idLayer.clear();
idLayer.add(g);
idTask.url = "urlForIdentifyTaskToUse";
idTask.execute(idParams, new AsyncResponder(onIdentifyResults_handler, onFault, g));
}
protected function removeMapListener():void {
if (map.hasEventListener(MapMouseEvent.MAP_CLICK))
map.removeEventListener(MapMouseEvent.MAP_CLICK, onMapClicked_handler);
}
protected function navigate(type:String):void {
removeMapListener(); // you can reuse this function for each of your other button clicks
switch(type) {
case NavigationTool.ZOOM_IN:
navTool.activate(NavigationTool.ZOOM_IN);
break;
case NavigationTool.ZOOM_OUT:
navTool.activate(NavigationTool.ZOOM_OUT);
break;
case NavigationTool.PAN:
navTool.activate(NavigationTool.PAN);
break;
case IDENTIFY:
activateIdentify();
break;
}
}
]]>
</fx:Script>
<s:HGroup>
<s:Button label="Zoom In" click="navigate(NavigationTool.ZOOM_IN)"/>
<s:Button label="Zoom Out" click="navigate(NavigationTool.ZOOM_OUT)"/>
<s:Button label="Pan" click="navigate(NavigationTool.PAN)"/>
<s:Button label="Identify" click="navigate(IDENTIFY)"/>
</s:HGroup>
... View more
11-12-2010
05:42 AM
|
0
|
0
|
811
|
|
POST
|
If I understand you right, what you'd probably want to do is add an EventListener to the Map on that button click.
// For arguments sake, let's say a user clicks the Identify button twice.
// Call your remove function before adding another listener
removeMapListener(); // you can reuse this function for each of your other button clicks
map.addEventListener(MapMouseEvent.MAP_CLICK, onMapClicked_handler);
protected function onMapClicked_handler(event:MapMouseEvent):void {
// grab your event.mapPoint and use it for your Identify tool
// you can call removeMapListener() again if you'd like
}
protected function removeMapListener():void {
if (map.hasEventListener(MapMouseEvent.MAP_CLICK))
map.removeEventListener(MapMouseEvent.MAP_CLICK, onMapClicked_handler);
} I think that makes sense, and that's similar to how I handle it for my Identify Tool.
... View more
11-10-2010
01:15 PM
|
0
|
0
|
811
|
|
POST
|
Thanks Bjorn. Looking forward to getting some test projects done this weekend. AIR lets me work in my comfort zone, but I'm still looking forward to an Android SDK. I like to get native when I can 😉
... View more
11-03-2010
06:13 AM
|
0
|
0
|
825
|
|
POST
|
Ok, this was a weird problem. If I add the GraphicsLayer to the map right after initializing it at the same time as I dynamically add my service layers, the graphics are backwards. So services is an array map service layers
for each (var layer:Layer in services) {
map.addLayer(layer);
}
map.addLayer(parcelLayer);
But if I wait until the after I do the first query and add it, it works ok. I just add this "if" statement in my Query Result handler
if (!map.getLayer(parcelLayer.id)) {
map.addLayer(parcelLayer);
}
I don't know if it has to do with adding the GraphicsLayer before the map has been added to the stage or what exactly, but I'm going to enjoy the solution I found.
... View more
10-21-2010
09:59 AM
|
0
|
0
|
452
|
|
POST
|
I am having an odd problem this morning with graphics. I have a query that I use to query a layer, then populate the results to a GraphicsLayer. Problem is, the graphics seem to be coming back in mirrored form from the actual data. I have attached an image. The green shaded area is the service and the dark shaded area is the same polygon after it has been queried and displayed. Weird huh? Unfortunately the service is not available to the public, but here is the REST data for it.
{
"id" : 1,
"name" : "Landbase.SDE.LA_Parcels",
"type" : "Feature Layer",
"description" : "",
"definitionExpression" : "",
"geometryType" : "esriGeometryPolygon",
"copyrightText" : "",
"parentLayer" : null,
"subLayers" : [],
"minScale" : 10000,
"maxScale" : 0,
"defaultVisibility" : true,
"extent" : {
"xmin" : -13241845.3287006,
"ymin" : 3867765.81297817,
"xmax" : -13096080.9165718,
"ymax" : 4139925.57253608,
"spatialReference" : {
"wkid" : 102113
}
},
Here is the query.
public function findParcelFeatures(ains:Array):AsyncToken {
var query:Query = new Query();
query.outFields = ['*'];
query.returnGeometry = true;
query.where = queryStringFromArray(ains, "AIN");
trace(query.where);
return parcelFeaturesTask.execute(query);
function queryStringFromArray(items:Array, fieldName:String):String {
var where:String = fieldName;
for each (var item:String in items) {
if (item != "")
where += " = " + item + " OR " + fieldName;
}
var fieldL:int = fieldName.length;
var trim:int = (where.length - fieldL) - 4;
return where.substr(0, trim);
}
}
private function onParcelFeaturesLoaded_handler(fSet:FeatureSet):void {
trace("got parcel features results", fSet.features.length);
parcelLayer.clear();
//parcelLayer.graphicProvider = fSet.features;
for each (var g:Graphic in fSet.features) {
parcelLayer.add(g);
}
map.extent = GraphicUtil.getGraphicsExtent(fSet.features);
}
I deleted the service, created a new MXD, created a new MSD and rebuilt the service, but the results are the same? Any clues as to what can be causing this? Thanks.
... View more
10-21-2010
08:49 AM
|
0
|
2
|
911
|
|
POST
|
I'm not too familiar with the Javascript API, so there may be a function for this built in, but you could pull the REST in JSON for any layer in a service like this http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Petroleum/KGS_OilGasFields_Kansas/MapServer/0?f=json&pretty=true Than you can iterate through the "fields" element which is an array of objects that has a "type" element that will tell you what type the field is. I find that for some needs, it's just easier for me to make REST requests to get that kind of detailed information.
... View more
10-13-2010
02:45 PM
|
0
|
0
|
1585
|
|
POST
|
Problem is you'll need to use an EventListener or use the AsyncResponder method. var qt:QueryTask = new QueryTask();
qt.addEventListener(QueryEvent.EXECUTE_COMPLETE, onExecuteComplete);
qt.execute(query);
// somewhere else in your code
private function onExecuteComplete(event:QueryEvent):void {
// stuff
} Without them, you have no way of knowing when the query is done. I'm thinking maybe you need to use the queryTask.executeLastResult somewhere else in the code outside the function, which is why you want to avoid the AsyncResponder method you posted. EventListeners work fine as well. I never did like the name 'executeLastResult', it's misleading. I'd think it should just be 'lastResult'.
... View more
10-07-2010
12:28 PM
|
0
|
0
|
639
|
|
POST
|
LayerDetails has a fields element, which I think contains a Field object. So what you could do is something like this pseudocode var ld:LayerDetails = fLayer.layerDetails;
var field:Field;
for each (field in ld.fields) {
// probably loop through graphics
var g:Graphic;
for each (g in fLayer.graphicsProvider) {
g.attributes[field.name] = "somedata"; // probably some if/else/switch to grab address info
}
} That could be a start, you'd just need to get your data to the right fields. Either way, you should be able to find Field names/aliases/types in fLayer.layerDetails.fields.
... View more
10-07-2010
06:57 AM
|
0
|
0
|
559
|
|
POST
|
Hi Jim, If I go to the Flex API page for example, and click on the Code Gallery tab, no filter options show up. http://help.arcgis.com/en/webapi/flex/index.html Code Gallery tab goes here http://help.arcgis.com/en/webapi/flex/gallery.html If I go to the Code Gallery for the JavaScript API, I do get filters http://help.arcgis.com/EN/webapi/javascript/arcgis/help/gallery.html I haven't gone through all Code Gallery pages, but some have filters and some don't(Silverlight API). It's odd when navigating.
... View more
10-06-2010
10:02 AM
|
0
|
0
|
1107
|
|
POST
|
Thanks. After some head scratching and looking over API docs, I figured it out.
// will find if the x/y point for an address is inside of a graphic on my GraphicsLayer
var onMapExtentChangeHandle = dojo.connect(map, "onExtentChange", function() {
dojo.disconnect(onMapExtentChangeHandle);
console.log("address result zoomed");
var point = geometry.toScreenGeometry(map.extent, map.width, map.height, pointMeters);
for (var i in gLayer.graphics) {
var g = gLayer.graphics;
if (g.geometry.contains(pointMeters)) {
var info = map.infoWindow;
info.setTitle(g.getTitle());
info.setContent(g.getContent());
info.show(point, map.getInfoWindowAnchor(point));
}
}
});
... View more
10-05-2010
11:08 AM
|
0
|
0
|
908
|
|
POST
|
Thanks. That eliminated the error, but the infoWindow is still blank. It's not a deal breaker. I think I can work around it, but was hoping it would be simple. I'll keep cracking at it.
... View more
10-04-2010
10:19 AM
|
0
|
0
|
908
|
|
POST
|
I've been spending some time with the JavaScript API, but I'm a little stumped on this one. Most of the samples I have seen simply use the map.graphics GraphicsLayer to hold graphics. In my case, I have added a new GraphicsLayer so that I can hold persistent graphics on the map. I use map.graphics to hold Geocode Results or temporary graphics. What I am trying to do is display the infoWindow for the GraphicsLayer I added to the map, but it's not working as I expected. On page load, after populating my GraphicsLayer, I add it to the map with a defined InfoTemplate. gLayer = new esri.layers.GraphicsLayer();
gLayer.id = "features";
var graphic = new esri.Graphic(new esri.geometry.Polygon(geometry), symbol, attributes, infoTemplate);
gLayer.add(graphic);
map.addLayer(gLayer); During it's use, someone can search for an address and I add that result to map.graphics. Then try to display the infoWindow after it has zoomed in. var pointMeters = esri.geometry.geographicToWebMercator(geocodeResults[0].location);
map.setExtent(esri.geometry.geographicToWebMercator(geocodeResults[0].bestView));
var onMapZoomHandle = dojo.connect(map, "onZoomEnd", function() {
dojo.disconnect(onMapZoomHandle);
console.log("add result zoomed");
var point = esri.geometry.toScreenPoint(map.extent, map.width, map.height, pointMeters);
map.infoWindow.show(point, map.getInfoWindowAnchor(point)); // throws error
//map.getLayer("features").infoWindow.show(point, map.getInfoWindowAnchor(point));
// tried having layer show directly, long shot, but no go
}); This throws an error and a blank infoWindow exception in animation handler for: onEnd
TypeError: pt is null
[Break on this error] if(!dojo._hasResource["dijit._base.man...h","tr","xx","zh","zh-cn","zh-tw"]);\r\n
arcgis?v=2.1 (line 48 I can click anywhere else on the added GraphicsLayer and get the predefined InfoWindow just fine. Does that InfoWindow display on the map.click() or the graphicsLayer.click()? If so, is there a way I can throw that event after the zoom to mimic the behavior? Thanks.
... View more
10-01-2010
06:25 AM
|
0
|
4
|
3935
|
|
POST
|
One solution would be to use the REST export to grab png's of the map service and stack them in Flex to send to print. This wouldn't grab any hand drawn graphics you have added though. http://help.arcgis.com/EN/arcgisserver/10.0/apis/rest/export.html I think high-quality prints would require server side ArcObjects to produce the image.
... View more
09-28-2010
02:13 PM
|
0
|
0
|
1325
|
|
POST
|
I updated the download page with info on how to compile in to your own project. You can also look here and it briefly tells you how to add your own widgets to a project. http://help.arcgis.com/en/webapps/flexviewer/help/developers/widget_framework.htm Thanks.
... View more
09-22-2010
02:22 PM
|
0
|
0
|
793
|
|
POST
|
As in only what's visible? At that scale level as well? If I don't have time this week, I can implement that this weekend. Thanks for feedback.
... View more
09-22-2010
09:12 AM
|
0
|
0
|
793
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-13-2025 03:13 PM | |
| 2 | 11-06-2025 11:10 AM | |
| 3 | 11-05-2025 02:54 PM | |
| 1 | 11-04-2025 02:38 PM | |
| 1 | 10-27-2025 08:17 AM |
| Online Status |
Offline
|
| Date Last Visited |
12 hours ago
|