Well I tried that code and it does not work. Click event never fires, then if I try manually setting the selection to a specific layer, then changing the onclicks first parameter back to Map the click event works but now it is not updating the to the current selected "permit" and the popups are calling out the same info. Feeling discouraged with this. I'm thinking the same as kmacleod, how am I going to easily set the active layer after I can just get the click Event to behave. Anyone want to take a peek at what I have so far. <!DOCTYPE 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="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Permit Locator</title>
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">
<style>
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#map {
padding:0;
}
</style>
<script>var dojoConfig = { parseOnLoad: true };</script>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>
<script>
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
dojo.require("esri.dijit.Popup");
var map;
var permits;
var properties;
function init() {
var sfs = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([111, 0, 255]), 2), new dojo.Color([111, 0, 255, 0.15]));
var popup = new esri.dijit.Popup({
fillSymbol: sfs
}, dojo.create("div"));
map = new esri.Map("map",{
basemap: "streets",
center: [-84.183, 39.734],
zoom: 13,
infoWindow: popup
});
dojo.addClass(map.infoWindow.domNode, "myTheme");
//Add all the permits and parcels to see on load
var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://map.miamiconservancy.org:6080/arcgis/rest/services/MCDPropertiesGeoDB/MapServer", {"opacity":0.9});
map.addLayer(operationalLayer);
//apply a popup template to the permits layer to format popup info
var popupTemplate = new esri.dijit.PopupTemplate({
title: "{Permits.MASTERUSER.%PERMIT.ISSUEDTO}",
fieldInfos: [{
fieldName: "Permits.MASTERUSER.%PERMIT.MCDNUM",
label: 'Permit Number (MCDNUM):',
visible: true
}, {
fieldName: "Permits.MASTERUSER.%PERMIT.LOCATION",
label: "Location:",
visible: true
}]
});
//apply a popup template to the MCD Parcels layer to format popup info
var popupTemplateParcels = new esri.dijit.PopupTemplate({
title: "{MCDID}",
fieldInfos: [{
fieldName: "MCDID",
label: 'MCD ID:',
visible: true
}, {
fieldName: "PARCELID",
label: "Parcel ID:",
visible: true
}]
});
//add the permits layer to the map as a feature layer in selection mode we'll use this layer to query and display the selected permits
permits = new esri.layers.FeatureLayer("http://map.miamiconservancy.org:6080/arcgis/rest/services/MCDPropertiesJOINToSQL/MapServer/2", {
outFields: ["*"],
infoTemplate: popupTemplate,
mode: esri.layers.FeatureLayer.MODE_SELECTION
});
//add the Properties layer to the map as a feature layer in selection mode
properties = new esri.layers.FeatureLayer("http://map.miamiconservancy.org:6080/arcgis/rest/services/MCDPropertiesJOINToSQL/MapServer/0", {
outFields: ["*"],
infoTemplate: popupTemplateParcels,
mode: esri.layers.FeatureLayer.MODE_SELECTION
});
permits.setSelectionSymbol(sfs);
properties.setSelectionSymbol(sfs);
// map.infoWindow.setFeatures(permits);
//*****when users click on the map select the permit using the map point and update the url parameter
dojo.connect(map, 'onClick', function (e)
{
var query = new esri.tasks.Query();
query.geometry = e.mapPoint;
permits.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (selection)
{
//update the url param if a permit was located
if (selection.length > 0)
{
var mcdnum = selection[0].attributes["Permits.MASTERUSER.%PERMIT.MCDNUM"];
//Refresh the URL with the currently selected permit
if (typeof history.pushState !== 'undefined')
{
window.history.pushState(null, null, "?mcdnum=" + selection[0].attributes["Permits.MASTERUSER.%PERMIT.MCDNUM"]);
}
}
});
// map.infoWindow.setFeatures(selection);
map.infoWindow.setFeatures(permits);
map.infoWindow.show(e.mapPoint);
});
// Now for the Properties layer
dojo.connect(properties, 'onClick', function (e)
{
var query = new esri.tasks.Query();
query.geometry = e.mapPoint;
map.infoWindow.setFeatures(selection);
map.infoWindow.show(e.mapPoint);
});
dojo.connect(map, 'onLayersAddResult', function (result) {
// Add a link into the InfoWindow Actions panel
var emailLink = dojo.create("a", {
"class": "action",
"innerHTML": "Email Map",
"href": "javascript:void(0);"
}, dojo.query(".actionList", map.infoWindow.domNode)[0]);
// Register a function to be called when the user clicks on
// the above link
dojo.connect(emailLink, "onclick", function (evt) {
var feature = map.infoWindow.getSelectedFeature();
var url = window.location;
var emailLink = "mailto:?subject=Permit Map of :" + feature.attributes["Permits.MASTERUSER.%PERMIT.MCDNUM"]+ "&body=Check out this permit: %0D%0A " + window.location;
window.location.href = emailLink;
});
//When users navigate through the history using the browser back/forward buttons select appropriate permit
//https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history
window.onpopstate = function (event) {
var mcdnum = getPermitFromUrl(document.location.href);
if (mcdnum) {
selectPermit(mcdnum);
} else {
permits.clearSelection();
map.infoWindow.hide();
}
};
//if a mcdnum is specified in url param select that feature
var mcdnum = getPermitFromUrl(document.location.href);
selectPermit(mcdnum);
});
map.addLayers([permits]);
map.addLayers([properties]);
}
//extract the permit id from the url
function getPermitFromUrl(url) {
var urlObject = esri.urlToObject(url);
if (urlObject.query && urlObject.query.mcdnum) {
return urlObject.query.mcdnum;
} else {
return null;
}
}
//select permit from the feature layer by creating a query to look for the input mcdnum id
function selectPermit(mcdnum) {
if (mcdnum) {
var query = new esri.tasks.Query();
query.where = "Permits.MASTERUSER.%PERMIT.MCDNUM = " + mcdnum + "";
//query.where = "Permits.MASTERUSER.%PERMIT.MCDNUM = 2963";
var deferred = permits.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (selection) {
var center = esri.graphicsExtent(selection).getCenter();
var extHandler = dojo.connect(map, 'onExtentChange', function () {
dojo.disconnect(extHandler);
//zoom to the center then display the popup
map.infoWindow.setFeatures(selection);
map.infoWindow.show(center);
});
map.centerAt(center);
});
}
}
dojo.ready(init);
</script>
</head>
<body class="claro">
<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'" style="border:1px solid #000;padding:0;"></div>
</div>
</body>
</html>