POST
|
I'm new to javaScript and mobile applications. I've cobbled together an application using various smaples. I want to be able to run a query on a mapservice and populate an array of valid names. then pass that array to a search box to create a list of valid names and create a list of matches as the user types in the box. At this point, I don't know how to populate the box, and then what to do when the user types in the box. The function onSearch isn't incomplete. I haven't found any good samples online. Any help is appreciated. -Also, I'd like to be able to make it so that the View goes back to the map and runs a query to zoom to the park. Thanks! Brendan Below is my code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=yes">
<title>Henderson Parks and Trails</title>
<link type="text/css" rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dojox/mobile/themes/iPhone/iPhone.css" />
<link type="text/css" rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dojox/mobile/themes/buttons.css" />
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css" />
<link rel="stylesheet" type='text/css' href='http://serverapi.arcgisonline.com/jsapi/arcgis/2.4/js/esri/dijit/css/PopupMobile.css'/>
<style type="text/css">
html, body {
height: 100%;
margin: 5px;
padding: 0px;
width: 100%;
}
</style>
<script type="text/javascript">var djConfig = {parseOnLoad: true};</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3compact"></script>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.8.1/dojo/dojo.js" data-dojo-config="async:true"></script>
<script language="JavaScript" type="text/javascript">
dojo.require("dojox.mobile.parser");
dojo.require("dojox.mobile");
dojo.require("dojox.mobile.Button");
dojo.require("dojox/mobile/SearchBox");
dojo.require("dojox/mobile/RoundRectList");
dojo.require("dojox/mobile/ListItem");
dojo.require("dojo/store/Memory");
dojo.require("dojo/_base/array");
dojo.require("dojo.data.ItemFileReadStore");
dojo.requireIf(!dojo.isWebKit, "dojox.mobile.compat");
dojo.require("esri.map");
dojo.require("esri.dijit.Legend");
dojo.require("esri.arcgis.utils");
dojo.require("esri.tasks.identify");
dojo.require("esri.tasks.query");
dojo.require("esri.tasks.find");
dojo.require("esri.layers.FeatureLayer");
dojo.require("esri.tasks.geometry");
dojo.require("esri.dijit.PopupMobile");
var store;
var map;
var symbol, polylineSymbol, startSymbol;
var identifyTask, identifyParams;
var query, queryTask;
var findparams, findTask;
var featureSet;
var legendLayers = [];
var content;
var startGraphic
var watchID;
var popup;
function init()
{
var popup = new esri.dijit.PopupMobile(null,dojo.create("div"));
map = new esri.Map("map", {logo:false, sliderStyle:"small", infoWindow:popup});
// Add basemap
var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server/ArcGIS/rest/services/public/BaseMap_no_parcels/MapServer");
map.addLayer(basemap);
//resize the map when the browser resizes
dojo.connect(map, 'onLoad', function(theMap) {
dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
});
}
function locationError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
alert("Permission Denied");
break;
case error.POSITION_UNAVAILABLE:
alert("Current location not available");
break;
case error.TIMEOUT:
alert("Timeout");
break;
default:
alert("unknown error");
break;
}
}
function getCurrent_Loc(){
if (navigator.geolocation) {
map.graphics.clear();
navigator.geolocation.getCurrentPosition(showLocation, locationError);
}
}
function showLocation(location) {
if (location.coords.accuracy <= 500) {
var geoService = new esri.tasks.GeometryService("http://server/ArcGIS/rest/services/Tools/Geometry/GeometryServer");
var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude, new esri.SpatialReference ({wkid:4236}));
//var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
var outSR = new esri.SpatialReference({wkid: 3421});
geoService.project([pt], outSR, function(projectedPoints) {
pt = projectedPoints[0]; // current location
map.centerAndZoom(pt, 4);
startGraphic = new esri.Graphic(pt, startSymbol);
map.graphics.add(startGraphic);
});
}
else {
console.log("Point not added due to low accuracy: " + location.coords.accuracy);
}
}
function makeList(){
// Query to search box with names
query = new esri.tasks.Query();
query.returnGeometry = false;
query.where = "EXISTING = 'Y'";
query.outFields = ["NAME"];
// Run query on startup
queryTask = new esri.tasks.QueryTask("http://server/ArcGIS/rest/services/public/ParksTrails/MapServer/5");
queryTask.execute(query,populateCbo);
}
function populateCbo(results) {
//Populate the search box with values
var parkName;
var values = new Array();
var features = results.features;
// Loop thru park names and add to array to populate drop-down
dojo.forEach (features, function(feature) {
parkName = feature.attributes.NAME;
values.push({name:parkName});
});
store = new Memory({data: values});
}
function onSearch(results, query, options){
if(options.start == 0){
list.destroyDescendants();
}
list.addChild(new ListItem({label: 'Page '+(options.start/options.count+1)+
' of '+Math.ceil(results.total/options.count), header:true }));
array.forEach(results, function(item){
list.addChild(new ListItem({label: item.name}));
});
if((options.start+results.length) < results.total){
results.nextPage();
}
};
dojo.addOnLoad(init);
</script>
</head>
<body>
<div id="homeView" dojoType="dojox.mobile.View" selected="true" style="width:100%;height:100%;">
<div style="width:100%;height:90%;" id="map"></div>
<ul dojoType="dojox.mobile.RoundRectList">
<li id="search" dojoType="dojox.mobile.ListItem" moveTo="searchView">
Search
</li>
</ul>
</div>
<div id="searchView" dojoType="dojox.mobile.View">
<h1 dojoType="dojox.mobile.Heading" back="Map" moveTo="homeView">Search</h1>
<ul dojoType="dojox.mobile.RoundRectList">
<li id="parkName" dojoType="dojox.mobile.ListItem" moveTo="parknameView" onClick="makeList();">
Park Name
</li>
<li id="nearMe" dojoType="dojox.mobile.ListItem" moveTo="homeView" onClick="getCurrent_Loc();">
Near Me
</li>
</ul>
</div>
<div id="parknameView" dojoType="dojox.mobile.View">
<h1 dojoType="dojox.mobile.Heading" back="Back" moveTo="searchView">Park Name Search</h1>
<input data-dojo-type="dojox.mobile.SearchBox" id="searchBox" type="search" placeHolder="Enter Park Name"
data-dojo-props='store:store, searchAttr:"name", ignoreCase:true, onSearch:onSearch, pageSize:5'>
<ul data-dojo-type="dojox.mobile.RoundRectList" jsId="list"></ul>
</div>
</body>
</html>
... View more
02-05-2013
02:35 PM
|
0
|
1
|
452
|
POST
|
I am a javascript newbie. I am working on a mobile app that will use geolocating to map the user's path along a trail. Eventually I'd like it to return the distance they travelled. I think I'm on the right track but I'm having some issues. I got it to map the path, but when the button to end is clicked the app hangs and becomes unresponsive. This only happens if it is a long path and I would imagine it is because the polyline I'm creating is becoming too large. I am using a custom basemap in my application and have to project the points returned by the geolocator. Should I use a Feature layer rather than the graphics layer? Is there another solution? Here is the code:
function startWatch(){
if (navigator.geolocation) {
map.graphics.clear();
pnts = [];
watchID = navigator.geolocation.watchPosition(showLocation, locationError, {maximumAge:30000, timeout:30000});
}
}
function endWatch(){
navigator.geolocation.clearWatch(watchID);
}
function showLocation(location) {
if (location.coords.accuracy <= 100) {
var geoService = new esri.tasks.GeometryService("http://myserver/ArcGIS/rest/services/Tools/Geometry/GeometryServer");
//var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude, new esri.SpatialReference ({wkid:4236}));
var outSR = new esri.SpatialReference({wkid: 3421});
geoService.project([pt], outSR, function(projectedPoints) {
pt = projectedPoints[0]; // current location
pnts.push(pt);
if (pnts.length === 1){
map.centerAndZoom(pt, 4);
polyline = new esri.geometry.Polyline(map.spatialReference);
startGraphic = new esri.Graphic(pt, startSymbol);
map.graphics.add(startGraphic);
}
if (pnts.length >= 2){
var pnt1 = new esri.geometry.Point(pnts[pnts.length - 2], map.spatialReference); // last point
if (location.coords.speed > 0){
polyline.addPath([pnt1, pt]);
map.graphics.add(new esri.Graphic(polyline, polylineSymbol));
if (endGraphic) { //if an end symbol already exists remove it
map.graphics.remove(endGraphic);
}
endGraphic = new esri.Graphic(pt, endSymbol);
map.graphics.add(endGraphic);
}
}
});
}
else {
console.log("Point not added due to low accuracy: " + location.coords.accuracy);
}
}
... View more
11-19-2012
07:50 AM
|
0
|
1
|
808
|
POST
|
Got a few questions for you 1. How do you know that it's a memory issue? 2. Is your RAM usage getting higher every time you add/remove a map layer? 3. Is ArcGIS Server and the Flex application on the same machine? 4. If so, can you reproduce the problem if the Flex application is on a different machine? 5. Have you also tried testing ArcGIS Server and the Flex application on a different machine? If you can't reproduce the problem using different machines then more than likely the problem isn't with the API so then I would check your web server logs. The server stops responding and we are unable to log in or reboot it. We're still troubleshooting but it seems to be a memory issue. I've since removed all maplex labeling and have broke the largest map services into smaller ones. The maps draw much faster. We are still having issues occassionally. It's now looking like it might be something to do with queries overloading the server. I have a pop-up that displays info from several layers when the user does an identify. It can be up to 10 successive queries. Is there a limit on the number of queries before you run into problems? I think I read somewhere it's 25 consecutive per second. Everything is on the same server (data, ArcGIS Server and the flex app). We moved everything to a different sever and it happens occassionally.
... View more
05-29-2012
01:22 PM
|
0
|
0
|
225
|
POST
|
I have an application that adds/removes dynamic map layers based on the user selection from a combobox. I am using Flex API 1.9. The map services are running on ArcServer 9.3 on a Windows 2003 server. One of the map services has 37 layers (including a couple of group layers). Should I break it up? I'm also using labeling on a lot of the layers. Lately we've been having issues with our server having memory problems. I suspect it is either one of my map services, or the way my application adds/removes dynamic layers that is causing the trouble. Here is my code for adding/removing layers. I am adding them over my base map and aerial caches. This code is called when the user selects a new "view" from the drop-down. Is there potential memory problems here? Something with the soc/som? The list in the switch block is actually much longer. I just put in a few to save space private function addLayers():void
{
myGraphicsLayer.clear();
// Some layers will not have anything visible at full extent
// Add busy cursor so user knows something is happening
// Then remove it when layer has been loaded
CursorManager.setBusyCursor();
// Remove layers that have already been loaded
for (var n:Number = MainMap.layers.length -1; n >= 0; n--) //loop thru all map layers
{
var layer:Layer = MainMap.getLayer(MainMap.layerIds );
if (layer.id == "viewLayer" || layer.id == "viewLayer2")
{
MainMap.removeLayer(layer);
}
}
// Create 2 new Dynamic Map layers
var lyr:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer;
var lyr2:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer;
// Create an array collection so only certain layers can be displayed
// If nothing is added to this ArrayCollection all visible layers in mxd are displayed
var visibleLayers:ArrayCollection = new ArrayCollection;
var visibleLayers2:ArrayCollection = new ArrayCollection;
// Set up map layer based on the currently selected view
switch (cbViews.text)
{
case "Annexations (City Limits)":
lyr.url = SERVER_NAME + "intranet/CityViewWeb/MapServer";
visibleLayers.addItem([12]);
lyr.alpha = 0.5;
break;
case "Building Inspection Areas":
lyr.url = SERVER_NAME + "intranet/CityViewWeb/MapServer";
visibleLayers.addItem([2, 3]); // Only draw the inspection areas layer
lyr.alpha = 0.5;
break;
case "Business Licenses":
lyr.url = SERVER_NAME + "public/buslicense/MapServer";
break;
case "Cell Sites":
lyr.url = SERVER_NAME + "intranet/CityViewWeb/MapServer";
lyr.alpha = 0.7;
visibleLayers.addItem([36, 37]);
break;
default: // For any view not in list above
CursorManager.removeBusyCursor();
break;
}
lyr.id = "viewLayer";
lyr.addEventListener(LayerEvent.LOAD, lyrLoad);
// Only draw layers added to ArrayCollection,
// if nothing has been added all visible layers in mxd are shown
if (visibleLayers.length > 0){lyr.visibleLayers = visibleLayers};
// Add layer to stack, just before parcel layer (so parcels appear on top)
MainMap.addLayer(lyr, 1);
// Add 2nd layer if it is needed
if (lyr2.url != null)
{
lyr2.id = "viewLayer2";
if (visibleLayers2.length > 0){lyr2.visibleLayers = visibleLayers2;}
MainMap.addLayer(lyr2, 2);
}
// Move map tips layer back to top so map tips work
MainMap.reorderLayer("MapTipsGraphicsLayer", MainMap.layers.length);
}
// Removes busy cursor after layer has been loaded
private function lyrLoad(event:Event):void
{
CursorManager.removeBusyCursor();
}
... View more
05-01-2012
02:34 PM
|
0
|
2
|
2448
|
POST
|
I am working on a project now that could potentially need to have a large number of map layers added. Not all layers will be visible at the same time and will turn on/off based on different user selections. My question is, is there a limit on the number of layers that can be added to a map? Does the number of layers added affect performance? Thanks!
... View more
08-31-2011
12:34 PM
|
0
|
3
|
399
|
POST
|
Is there a way to do this with ArcGIS API for Flex 1.3? I can't upgrade to 2.3 yet...so I'm hoping I can get to the domain values and not have to do a lot of coding to assign the values. Thanks!
... View more
06-29-2011
10:36 AM
|
0
|
0
|
1024
|
POST
|
You can set the pop up's x and y. pop1 = myPopUp(PopUpManager.createPopUp(this, myPopUp, false, PopUpManagerChildList.POPUP)); pop1.x=80; pop1.y=300;
... View more
06-29-2011
09:58 AM
|
0
|
0
|
156
|
POST
|
Here are some new ones added: Zoning and Land Use Points of Interest Schools More coming soon!
... View more
02-23-2011
11:05 AM
|
0
|
0
|
431
|
POST
|
The icons for the buttons are a combination of in-house custom graphics and those that came with ESRI's FlexViewer. Most of them are custom however.
... View more
02-23-2011
11:01 AM
|
0
|
0
|
431
|
POST
|
Figured it out. Just added the graphics to a new graphics layer and all works perfectly.
... View more
09-07-2010
10:43 AM
|
0
|
0
|
114
|
POST
|
In my application I have a combo box with a list of types of facilities. When the user picks one from the list a query is run that selects all facilities for that type and populates a datagrid. It then zooms to the extent of all facilities. When the user mouses over the datagrid the facility is highlighted with an infowindow. I have the following code which works perfectly with polygons. But the polygons are small and don't appear when zoomed out. So I want to add a pointmarker to the graphics layer for each polygon. When I add the point my code doesn't work...only the FIRST polygon added responds to the mouseover. I've tried adding the point graphic first but then nothing responds to the mouseover. Any help would be appreciated.
function onResult( featureSet : FeatureSet, token : Object = null ) : void
{
if (featureSet.features.length == 0)
{
Alert.show("No facilities found.");
}
else
{
// Clear previous selection
myGraphicsLayer.clear();
var selectedExtent : Extent;
var g1:Graphic = featureSet.features[0];
var pms:PictureMarkerSymbol = new PictureMarkerSymbol(PushPinIcon, 60, 60);
var pnt:MapPoint;
selectedExtent = Polygon(g1.geometry).extent;
for each (var g:Graphic in featureSet.features)
{
g.symbol = (sfs);
// Adds facility name and address as tool tip
g.toolTip = "Facility Name: " + g.attributes.FACILITY + "\nAddress: " + g.attributes.ADDRESS;
g.autoMoveToTop = true;
// Add graphic to graphics layer
myGraphicsLayer.add(g);
// Add listeners so mouse over the map will highlight parcel in datagrid
g.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
g.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
// update extent of selected facilities
selectedExtent = selectedExtent.union(Polygon(g.geometry).extent);
// EVERYTHING WORKS IF I COMMENT OUT THE FOLLOWING SECTION
// Add point marker
pnt = new MapPoint(g.geometry.extent.center.x, g.geometry.extent.center.y,
MainMap.spatialReference);
var myGraphicPic:Graphic = new Graphic(pnt);
myGraphicPic.symbol = pms;
myGraphicsLayer.add(myGraphicPic);
}
// Zoom to extent of all facilities
MainMap.extent = selectedExtent.expand(2);
}
}
// Highlight facility on map as user moves mouse over datagrid
private function onItemRollOver(event:ListEvent):void
{
var g:Graphic = findGraphicByAttribute(event.itemRenderer.data);
g.symbol = highlightSymbol;
// Move graphic to top so highlight symbol is visible
myGraphicsLayer.moveToTop(g);
// Info for pop-up
mapPoint = new MapPoint( g.geometry.extent.center.x, g.geometry.extent.center.y, MainMap.spatialReference );
myInfoWin.facility = event.itemRenderer.data["FACILITY"];
myInfoWin.address = event.itemRenderer.data["ADDRESS"];
MainMap.infoWindow.content = myInfoWin;
MainMap.infoWindow.labelVisible = false;
MainMap.infoWindow.closeButtonVisible = false;
MainMap.infoWindow.show(mapPoint);
// to zoom to select record in datagrid
//MainMap.extent = g.geometry.extent.expand(2);
}
// Find the graphic on the map for the row highlighted in datagrid
private function findGraphicByAttribute(attributes:Object):Graphic
{
for each (var graphic:Graphic in myGraphicsLayer.graphicProvider)
{
if (graphic.attributes["FACILITY"] == attributes["FACILITY"])
{
return graphic;
}
}
return null;
}
... View more
08-31-2010
08:57 AM
|
0
|
1
|
2012
|
POST
|
Thanks for the reply. That's the approach I ended up using. I was just looking for a "cleaner" way to do it.
... View more
07-13-2010
01:33 PM
|
0
|
0
|
104
|
POST
|
Is there a way to set the alpha on individual layers? In the code below I would like to set the alpha for the first 2 to 100% and the 3rd to 60%.
<esri:ArcGISDynamicMapServiceLayer id="ElemZones"
url="http://myServer/ArcGIS/rest/services/public/Schools/MapServer"
show="layerShowHandler(event)" alpha=".5"
visible="{bb.selectedIndex == 1}">
<esri:visibleLayers>
<mx:ArrayCollection>
<mx:Number>3</mx:Number>
<mx:Number>4</mx:Number>
<mx:Number>5</mx:Number>
</mx:ArrayCollection>
</esri:visibleLayers>
</esri:ArcGISDynamicMapServiceLayer>
... View more
07-13-2010
09:10 AM
|
0
|
2
|
485
|
POST
|
Easy enough. Got that working. Now is there a way to set the alpha on individual layers? I want some layers to be 100% and then others to be 60%.
... View more
07-13-2010
08:24 AM
|
0
|
0
|
133
|
POST
|
I want to use a toggle button bar to turn layers on/off similar to the Switching Basemaps sample. I would have 3 options (zone 1, zone 2, zone 3) and would need to turn layers on/off based on the selection. I have one dynamic map service that has layers for all 3 zones...I don't want to make a map service for each. Are there any examples/samples on how to do this? Thanks!
... View more
07-08-2010
03:17 PM
|
0
|
3
|
997
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|