|
POST
|
Here's an example of using a popup with a dynamic map service:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title></title>
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.5/js/dojo/dijit/themes/tundra/tundra.css">
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.5/js/esri/dijit/css/Popup.css">
<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
#map{ margin: 0; padding: 0; }
</style>
<script>var dojoConfig = { parseOnLoad: true };</script>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.5"></script>
<script>
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("esri.map");
dojo.require("esri.tasks.query");
dojo.require("esri.dijit.Popup");
var map;
function init() {
var dynSvc = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer",{"opacity":0.5});
var ext = new esri.geometry.Extent({"xmin":-97.968323,"ymin":32.405333,"xmax":-86.220025,"ymax":37.006985,"spatialReference":{"wkid":4269}});
var popup = new esri.dijit.Popup(null, dojo.create("div"));
map = new esri.Map("map", {
"extent": ext,
"infoWindow": popup
});
map.addLayer(dynSvc);
dojo.connect(map, 'onClick', queryCounties);
dojo.connect(map, 'onLoad', function() {
dojo.connect(dijit.byId('map'), 'resize', map, map.resize);
});
}
function queryCounties(e) {
// build an extent around the click point
var pad = map.extent.getWidth() / map.width * 3;
var queryGeom = new esri.geometry.Extent(e.mapPoint.x - pad, e.mapPoint.y - pad, e.mapPoint.x + pad, e.mapPoint.y + pad, map.spatialReference);
var q = new esri.tasks.Query();
q.outSpatialReference = {"wkid": 4269};
q.returnGeometry = true;
q.outFields = ["NAME", "STATE_FIPS", "CNTY_FIPS"];
q.geometry = queryGeom;
var popupTemplate = new esri.dijit.PopupTemplate({
title: "{NAME}",
fieldInfos: [
{ fieldName: "CNTY_FIPS", visible: true, label: "County FIPS: " },
{ fieldName: "STATE_FIPS", visible: true, label: "State FIPS: " }
]
});
var qt = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3");
var def = qt.execute(q);
def.addCallback(function(result) {
return dojo.map(result.features, function(f) {
f.setInfoTemplate(popupTemplate);
return f;
});
});
// use the deferred returned from the query task to set
// the popup features
map.infoWindow.setFeatures([def]);
// show the popup
map.infoWindow.show(e.screenPoint, map.getInfoWindowAnchor(e.screenPoint));
}
dojo.ready(init);
</script>
</head>
<body class="tundra">
<div data-dojo-type="dijit.layout.BorderContainer"
data-dojo-props="design:'headline',gutters:false"
style="width: 100%; height: 100%; margin: 0;">
<div id="map"
data-dojo-type="dijit.layout.ContentPane"
data-dojo-props="region:'center'">
</div>
</div>
</body>
</html>
JSFiddle: http://jsfiddle.net/swingley/Bkswj/ This sample is using a query task to get features that intersect a click point and then using the deferred returned by the query task to set features for the map's popup. If you're underlying data is time-enabled, use a timeExtent property on your query to query by time.
... View more
11-04-2011
07:11 AM
|
0
|
0
|
2481
|
|
POST
|
By default, the UI seems to act as if obscured markers just don't exist. Can you elaborate? Maybe post some code that reproduces this? It's pretty straightforward to get all graphics under a mouse click: http://blogs.esri.com/dev/blogs/arcgisserver/archive/2010/02/08/find-graphics-under-a-mouse-click-with-the-arcgis-api-for-javascript.aspx It works fine, except that to get the mouse event in the first place to my system, I have had to tie into the layer's event handlers. I.e., each layer gets its mouse events, and then just hands them off to the new system, which handles all layers together. I would much rather turn off the marker layers' event handlers altogether, as I don't need them anymore, and just handle all mouse events directly, but still pass those that aren't over a marker on to the underlying map event handlers (for pan, zoom, etc.). This would be faster (the toolkit has an unnecessary delay when clicking on markers in crowded areas), and I wouldn't have to worry about my marker detection having any pixel-level inaccuracies vis-a-vis the layer's detection, which is currently the "mouse gatekeeper". I think we need to back up for a second and confirm you're solving a problem that needs to be solved (and not just re-writing the API). Can you talk more about "the toolkit has an unnecessary delay when clicking on markers in crowded areas" and how you solved that? Again, repro code would be the simplest way to show this problem exists. I would like to hear more specifics about those "pixel-level inaccuracies" as well. How many graphics are in your map? Apologies if I'm not answering your question directly. You're outlining some significant issues and rather than talking about how to circumvent the existing API, I'd like to isolate any existing issue(s) so we can potentially fix them.
... View more
11-04-2011
06:02 AM
|
0
|
0
|
1688
|
|
POST
|
I think you're getting bogged down in semantics. True, layer is a generic, over-used (abused?) term but if you look at the context in which it is used, I think you'll find the meaning is clear.
... View more
11-04-2011
05:52 AM
|
0
|
0
|
1443
|
|
POST
|
I prefer to use dojo.connect() to wire up events as it keeps JavaScript separate from HTML. I do not like to embed JS in my markup. Separation of concerns and all that... For the first argument to dojo.connect, I prefer using dojo.byId() because it's explicit what is happening. It's perfectly reasonable to just use a string that corresponds to a DOM node's ID.
... View more
11-03-2011
10:30 AM
|
0
|
0
|
1181
|
|
POST
|
JavaScript is case-sensitive. Your function name is "myzoom" but your onClick says "myZoom". I probably should have posted a more complete code sample in the other thread where this was recently discussed. Here's a simple page demoing this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Zoom to Extent Test</title>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript">djConfig = { parseOnLoad: true }</script>
<script type="text/javascript">
dojo.require("esri.map");
var map, layer;
function Init() {
map = new esri.Map("mapDiv");
layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer");
map.addLayer(layer);
dojo.connect(dojo.byId('button2'), 'onclick', myzoom);
}
function myzoom() {
console.log('my zoom fired');
var axtent = new esri.geometry.Extent(55.6153456, 5.7191691, 105.6673614, 37.0016790, map.SpatialReference);
// var axtent = new esri.geometry.Extent(105.6673614, 37.0016790, 55.6153456, 5.7191691, map.SpatialReference);
console.log('xmin: ', axtent.xmin, '; ymin: ', axtent.ymin);
map.setExtent(axtent);
}
dojo.ready(Init);
</script>
</head>
<body class="tundra">
<div id = "mapDiv" style="width:800px; height:300px"> </div>
<input id="button2" type="button" value="Zoom To India" />
</body>
</html>
... View more
11-03-2011
09:24 AM
|
0
|
0
|
1181
|
|
POST
|
The version in the URL needs to be changed to the JS API version. Here's the one for 2.5: http://serverapi.arcgisonline.com/jsapi/arcgis/2.5/js/dojo/dijit/themes/soria/soria.css the dijitOffScreen class is defined in that file.
... View more
11-02-2011
03:59 PM
|
0
|
0
|
619
|
|
POST
|
Happy to try to help. Thanks for posting your code. Few things... -the order for params for esri.geometry.Extent is xmin, ymin, xmax, ymax, sr. I think you have xmin/xmax and ymin/ymax swapped. Try this:
var axtent = new esri.geometry.Extent(55.6153456, 5.7191691, 105.6673614, 37.0016790, map.SpatialReference);
-you're using 1.6...is that a requirement? If not, please use the latest version, currently 2.5: http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.5 (also update the link to the tundra CSS if you do this: http://serverapi.arcgisonline.com/jsapi/arcgis/2.5/js/dojo/dijit/themes/tundra/tundra.css -add a class attribute on your body tag to get the tundra theme: <body class="tundra"> -use dojo.ready() to call your init function instead of body onload
... View more
11-01-2011
10:51 AM
|
0
|
0
|
1217
|
|
POST
|
Can you post some more of your code? I don't see a problem with your general workflow or the code snippets you posted.
... View more
10-31-2011
08:37 PM
|
0
|
0
|
1217
|
|
POST
|
Hi James, The first issue you're describing is usually CSS related. It's hard to say exactly what's happening without seeing your markup and CSS. Your layer timing out should be a red flag. You can increase the default timeout but I would caution against this for a couple of reasons: -do you want to make your users wait 15-20s(or longer?) for your app's data to load? -displaying 3-4k features in any browser will likely cause noticeable performance issues There are a couple of ways to address this: -start your app at a larger scale so less features are displayed -use scale dependencies and a dynamic map service to show your data
... View more
10-31-2011
08:34 AM
|
0
|
0
|
1441
|
|
POST
|
If you're using the JS API, use esri.request. If you don't want to do that, I'd take this question to a site like stackoverflow.
... View more
10-28-2011
03:23 PM
|
0
|
0
|
816
|
|
POST
|
Yes, that should cover it. If you're using IE, give fiddler a shot to monitor http traffic: http://www.fiddler2.com/fiddler2/
... View more
10-28-2011
01:24 PM
|
0
|
0
|
2980
|
|
POST
|
Hi Mark, Yes, this relates to URL length. Once you generate a URL over 2048 characters, the JS API switches to using the proxy. When you get a map image via a proxy, the proxy returns a URL to the image. For this to work, you need to enable a virtual output directory for your service (this is where the map image will be written). What are you seeing in firebug/chrome dev tools? Are you seeing a request to the proxy? What is the response from your server? Screen shots would be helpful.
... View more
10-28-2011
12:52 PM
|
0
|
0
|
2980
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-23-2012 07:54 AM | |
| 1 | 05-28-2010 08:31 AM | |
| 1 | 11-12-2012 08:12 AM | |
| 3 | 02-23-2012 10:57 AM | |
| 1 | 06-27-2011 08:51 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|