popup.setContent(content)
popup.setFeatures([graphic])
<!DOCTYPE html> <html> <head> <title>Create a Map</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9"> <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/dojo/dijit/themes/claro/claro.css"> <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/esri/css/esri.css"> <style> html,body,#mapDiv,.map.container{ padding:0; margin:0; height:100%; } </style> <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/"></script> <script> dojo.require("esri.map"); dojo.require("esri.dijit.PopupMobile"); dojo.require("esri.layers.FeatureLayer"); var map; function init(){ var popup = new esri.dijit.PopupMobile({}, dojo.create("div")); map = new esri.Map("mapDiv", { center: [-122.41, 37.77], infoWindow:popup, zoom: 14, basemap: "streets" }); var template = new esri.InfoTemplate(); template.setContent(getTextContent); var featureLayer = new esri.layers.FeatureLayer("http://servicesbeta.esri.com/arcgis/rest/services/SanFrancisco/SFStreetTreesRendered/MapServer/0",{ mode: esri.layers.FeatureLayer.MODE_SNAPSHOT, outFields: ["*"], infoTemplate:template }); dojo.connect(featureLayer, "onClick", function(evt){ map.infoWindow.setFeatures([evt.graphic]); }); map.addLayer(featureLayer); } function getTextContent(graphic) { var attr = graphic.attributes.qSpecies.replace('"',"").split("::"); var content; var scientificName = attr[0]; //display the common name if it exists - otherwise just the scientific if(attr[1]){ content = "<b>" + dojo.string.trim(attr[1].replace('"',"")) + "</b><br/><i>" + scientificName + "</i>"; } else { content = "<i>" + scientificName + "</i>" } return content + "<br>" + graphic.attributes.qAddress + "<br/> Planted on " + formatDate(graphic.attributes.PlantDate); } function formatDate(value){ var inputDate = new Date(value); return dojo.date.locale.format(inputDate, { selector: 'date', datePattern: 'MMMM d, y' }); } dojo.ready(init); </script> </head> <body class="claro"> <div id="mapDiv"></div> </body> </html>
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.