3

I have created a map with a simple marker at a specified location but I cannot figure out how to have an infowindow attached to the position open automatically on page load.

This is my init function:

//Lay out the required libraries
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.TitlePane");
dojo.require("esri.map");
dojo.require("esri.dijit.Popup");
dojo.require("esri.symbol");
dojo.require("esri.dijit.BasemapGallery");
dojo.require("esri.arcgis.utils");
dojo.require("esri.dijit.Geocoder");

var map = null;
var gsvc = null;
var pt = null;

function init() {

    esri.config.defaults.geometryService = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

    // create the map
    map = new esri.Map("map", {
        basemap: "topo", //Possibilities: "streets" , "satellite" , "hybrid", "topo", "gray", "oceans", "national-geographic", "osm"
        center: [@Model.Longitude.ToString(), @Model.Latitude.ToString()], //long, lat (Middle of the USA)2140164826
        zoom: 11,
        logo: false
    });



    //add the basemap gallery
    var basemapGallery = new esri.dijit.BasemapGallery({
        showArcGISBasemaps: true,
        map: map
    }, "basemapGallery");

    basemapGallery.startup();

    var Geocoder = new esri.dijit.Geocoder({
        map: map
    }, dojo.byId("search"));

    Geocoder.startup();

    dojo.connect(basemapGallery, "onError", function (msg) {
        console.log(msg)
    });

    dojo.connect(map, "onClick", projectToLatLong);

    var point = new esri.geometry.Point(@Model.Longitude, @Model.Latitude);
    point = esri.geometry.geographicToWebMercator(point);
    var symbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([255, 0, 0, 0.5]));
    var graphic = new esri.Graphic(point, symbol);
    var layer = new esri.layers.GraphicsLayer();

    layer.add(graphic);
    map.addLayer(layer);
}
  • Can you please clarify "an infowindow attached to the position"? What is "the position"? Where will the infoWindow come from - is it your variable layer? That doesn't seem to have an infoWindow or attributes associated with it – Stephen Lead Nov 7 '14 at 2:19
2

The API Documentation shows 4 parameters that you can use when creating a graphic ...

new Graphic(geometry?, symbol?, attributes?, infoTemplate?)

see API Documentation for "Graphic". You just need to set up your info Template and then attach it to the graphic when you make that call. You are currently only using 2 of the 4 parameters.

See this sample Geocode an Address. In that sample, you enter an address and the script adds a graphic point for that address and constructs an info template for it. That should help.

If you actually want it to popup with the information when it loads, you will just have to add a function that runs when the map loads.

map.on("load", executeIdentifyTask);

This is going to be the same function you would normally call on the click event

 map.on("click", executeIdentifyTask);

but instead you are running it from the load event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.