Demographics data shows upon first click but not after, park information does work. I've changed around almost everything with non real solution. I feel like for whatever reason my feature server data is preferred over the dynamiclayer in the map. Is there a way to make the js bounce based on where you click?
var map; require([ "esri/config", "esri/InfoTemplate", "esri/map", "esri/dijit/Popup", "esri/dijit/PopupTemplate", "esri/geometry/Extent", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/FeatureLayer", "esri/layers/ArcGISTiledMapServiceLayer", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "esri/tasks/GeometryService", "esri/tasks/query", "dojo/dom-construct", "dojo/dom-class", "dojo/parser", "esri/Color", "dojo/_base/lang", "dojo/date/locale", "esri/dijit/Geocoder", "esri/dijit/LocateButton", "dojo/domReady!" ], function ( esriConfig, InfoTemplate, Map, Popup, PopupTemplate, Extent, ArcGISDynamicMapServiceLayer, FeatureLayer, ArcGISTiledMapServiceLayer, SimpleFillSymbol, SimpleLineSymbol, GeometryService, Query, domConstruct, domClass, parser, Color, lang, locale, Geocoder, LocateButton ) { parser.parse(); var popup = new Popup({ fillSymbol: new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 0, 0]), 2), new Color([128, 128, 128, 0.25])) }, domConstruct.create("div")); domClass.add(popup.domNode, "myTheme"); map = new Map("map", { basemap: "topo", center: [-122.402, 47], zoom: 9, infoWindow: popup }); var geocoder = new Geocoder({ arcgisGeocoder: { placeholder: "Search " }, map: map }, "ui-esri-dijit-geocoder"); var _countyCensusInfoTemplate = new InfoTemplate(); _countyCensusInfoTemplate.setTitle("Census Information"); var _blockGroupInfoTemplate = new InfoTemplate(); _blockGroupInfoTemplate.setTitle("Census Information"); var _censusInfoContent = "" + "${AGE_5_17:formatNumber}
people ages 5 - 17
" + "${AGE_18_21:formatNumber}
people ages 18 - 21
" + "${AGE_22_29:formatNumber}
people ages 22 - 29
" + "${AGE_30_39:formatNumber}
people ages 30 - 39
" + "${AGE_40_49:formatNumber}
people ages 40 - 49
" + "${AGE_50_64:formatNumber}
people ages 50 - 64
" + "${AGE_65_UP:formatNumber}
people ages 65 and older" + "
"; _countyCensusInfoTemplate.setContent("Demographics for:
${NAME} ${STATE_NAME:getCounty}, ${STATE_NAME}
" + _censusInfoContent); _blockGroupInfoTemplate.setContent("Demographics for:
Tract: ${TRACT:formatNumber} Blockgroup: ${BLKGRP}
" + _censusInfoContent); var demographicsLayerURL = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer"; var demographicsLayerOptions = { "id": "demographicsLayer", "opacity": 0.8, "showAttribution": false }; var demographicsLayer = new ArcGISDynamicMapServiceLayer(demographicsLayerURL, demographicsLayerOptions); demographicsLayer.setInfoTemplates({ 1: { infoTemplate: _blockGroupInfoTemplate }, 2: { infoTemplate: _countyCensusInfoTemplate } }); demographicsLayer.setVisibleLayers([1, 2]); map.addLayer(demographicsLayer); geocoder.startup(); var geoLocate = new LocateButton({ map: map, highlightLocation: false }, "LocateButton" ); geoLocate.startup(); var formatNumber = function(value, key, data) { var searchText = "" + value; var formattedString = searchText.replace(/(\d)(?=(\d\d\d)+(?!\d))/gm, "$1,"); return formattedString; }; var getCounty = function(value, key, data) { if (value.toUpperCase() !== "LOUISIANA") { return "County"; } else { return "Parish"; } }; map.on("click", function (event) { var query = new Query(); query.geometry = pointToExtent(map, event.mapPoint, 10); var deferred = featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW); map.infoWindow.setFeatures([deferred]); map.infoWindow.show(event.mapPoint); }); var template = new InfoTemplate(); template.setTitle("Park Information"); template.setContent(getTextContent); var featureLayer = new FeatureLayer("https://services3.arcgis.com/J1Locv0GPOt6yBRR/ArcGIS/rest/services/Parks_polygons_Feb2012/FeatureServer/0", { outFields: ["*"], infoTemplate: template }); map.addLayer(featureLayer); function getTextContent (graphic) { var attributes = graphic.attributes; var namepark = attributes.ParkName .replace('"', "") .split("::") .map(function (name) { return lang.trim(name); }); var parkdata = namepark[0]; var commonName = namepark[1]; var parks; if (commonName) { parks = "" + commonName + "
" + "" + parkdata + ""; } else { parks = "" + parkdata + ""; } return parks + "
" + attributes.Owner + "
" + attributes.ParkWebLin } function pointToExtent (map, point, toleranceInPixel) { var pixelWidth = map.extent.getWidth() / map.width; var toleranceInMapCoords = toleranceInPixel * pixelWidth; return new Extent(point.x - toleranceInMapCoords, point.y - toleranceInMapCoords, point.x + toleranceInMapCoords, point.y + toleranceInMapCoords, map.spatialReference); } });
link to is http://students.washington.edu/sbuffor/combined_census_parks.html
أكثر...
var map; require([ "esri/config", "esri/InfoTemplate", "esri/map", "esri/dijit/Popup", "esri/dijit/PopupTemplate", "esri/geometry/Extent", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/FeatureLayer", "esri/layers/ArcGISTiledMapServiceLayer", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "esri/tasks/GeometryService", "esri/tasks/query", "dojo/dom-construct", "dojo/dom-class", "dojo/parser", "esri/Color", "dojo/_base/lang", "dojo/date/locale", "esri/dijit/Geocoder", "esri/dijit/LocateButton", "dojo/domReady!" ], function ( esriConfig, InfoTemplate, Map, Popup, PopupTemplate, Extent, ArcGISDynamicMapServiceLayer, FeatureLayer, ArcGISTiledMapServiceLayer, SimpleFillSymbol, SimpleLineSymbol, GeometryService, Query, domConstruct, domClass, parser, Color, lang, locale, Geocoder, LocateButton ) { parser.parse(); var popup = new Popup({ fillSymbol: new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 0, 0]), 2), new Color([128, 128, 128, 0.25])) }, domConstruct.create("div")); domClass.add(popup.domNode, "myTheme"); map = new Map("map", { basemap: "topo", center: [-122.402, 47], zoom: 9, infoWindow: popup }); var geocoder = new Geocoder({ arcgisGeocoder: { placeholder: "Search " }, map: map }, "ui-esri-dijit-geocoder"); var _countyCensusInfoTemplate = new InfoTemplate(); _countyCensusInfoTemplate.setTitle("Census Information"); var _blockGroupInfoTemplate = new InfoTemplate(); _blockGroupInfoTemplate.setTitle("Census Information"); var _censusInfoContent = "" + "${AGE_5_17:formatNumber}
people ages 5 - 17
" + "${AGE_18_21:formatNumber}
people ages 18 - 21
" + "${AGE_22_29:formatNumber}
people ages 22 - 29
" + "${AGE_30_39:formatNumber}
people ages 30 - 39
" + "${AGE_40_49:formatNumber}
people ages 40 - 49
" + "${AGE_50_64:formatNumber}
people ages 50 - 64
" + "${AGE_65_UP:formatNumber}
people ages 65 and older" + "
"; _countyCensusInfoTemplate.setContent("Demographics for:
${NAME} ${STATE_NAME:getCounty}, ${STATE_NAME}
" + _censusInfoContent); _blockGroupInfoTemplate.setContent("Demographics for:
Tract: ${TRACT:formatNumber} Blockgroup: ${BLKGRP}
" + _censusInfoContent); var demographicsLayerURL = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer"; var demographicsLayerOptions = { "id": "demographicsLayer", "opacity": 0.8, "showAttribution": false }; var demographicsLayer = new ArcGISDynamicMapServiceLayer(demographicsLayerURL, demographicsLayerOptions); demographicsLayer.setInfoTemplates({ 1: { infoTemplate: _blockGroupInfoTemplate }, 2: { infoTemplate: _countyCensusInfoTemplate } }); demographicsLayer.setVisibleLayers([1, 2]); map.addLayer(demographicsLayer); geocoder.startup(); var geoLocate = new LocateButton({ map: map, highlightLocation: false }, "LocateButton" ); geoLocate.startup(); var formatNumber = function(value, key, data) { var searchText = "" + value; var formattedString = searchText.replace(/(\d)(?=(\d\d\d)+(?!\d))/gm, "$1,"); return formattedString; }; var getCounty = function(value, key, data) { if (value.toUpperCase() !== "LOUISIANA") { return "County"; } else { return "Parish"; } }; map.on("click", function (event) { var query = new Query(); query.geometry = pointToExtent(map, event.mapPoint, 10); var deferred = featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW); map.infoWindow.setFeatures([deferred]); map.infoWindow.show(event.mapPoint); }); var template = new InfoTemplate(); template.setTitle("Park Information"); template.setContent(getTextContent); var featureLayer = new FeatureLayer("https://services3.arcgis.com/J1Locv0GPOt6yBRR/ArcGIS/rest/services/Parks_polygons_Feb2012/FeatureServer/0", { outFields: ["*"], infoTemplate: template }); map.addLayer(featureLayer); function getTextContent (graphic) { var attributes = graphic.attributes; var namepark = attributes.ParkName .replace('"', "") .split("::") .map(function (name) { return lang.trim(name); }); var parkdata = namepark[0]; var commonName = namepark[1]; var parks; if (commonName) { parks = "" + commonName + "
" + "" + parkdata + ""; } else { parks = "" + parkdata + ""; } return parks + "
" + attributes.Owner + "
" + attributes.ParkWebLin } function pointToExtent (map, point, toleranceInPixel) { var pixelWidth = map.extent.getWidth() / map.width; var toleranceInMapCoords = toleranceInPixel * pixelWidth; return new Extent(point.x - toleranceInMapCoords, point.y - toleranceInMapCoords, point.x + toleranceInMapCoords, point.y + toleranceInMapCoords, map.spatialReference); } });
link to is http://students.washington.edu/sbuffor/combined_census_parks.html
أكثر...