Retain popup data after it is closed

1597
24
Jump to solution
04-01-2020 08:50 PM
rsharma
Occasional Contributor III

I want to retain popupdata which i filled in it, when i close the popup coming from marker symbol , and again open it, my popup refreshed.??

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Rajni,

   You have a lot of unneeded redundancy in your code right now.

view.toMap({x:evt.x, y: evt.y})

This portion produces a point class in WKID 102100 (web mercator).

So there is no need for all this code:

var coords = "Lat/Lon " + pt.latitude + " " +pt.longitude;
/* console.log(markertype+" "+comment);*/
var p = new Point({
  longitude: pt.latitude,
  latitude: pt.longitude,
  spatialReference: {wkid: 4326}
});

So your code would look like this instead:

view.on("click", function(evt) {
  if(getmarkerclick==true){
    var p = view.toMap({x:evt.x, y: evt.y});
    var changedSymbol = changedsymbol(markertype);
    var g = new Graphic({
      geometry: p,
      symbol: changedSymbol,
      attributes: {
        newDevelopment: "new marker",
        state: "new",
        uniquetype: markertype,
        markerId: "static",
        comment: comment
      }
    });
  }
}); //End view click‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I assume that "markertype" is a global var somewhere else in your code?

View solution in original post

24 Replies
RobertScheitlin__GISP
MVP Emeritus

Rajni,

   It is as simple as saving that text as an attribute to the graphic in your database and then when you recreate from the DB you you set the popup content to that attribute.

0 Kudos
rsharma
Occasional Contributor III

can you pls give one example, as i have multiple markers with popup, each have different popup values in its textbox. how can i differentiate between each of them

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Rajni,

   This is what the popup has always been designed to do. Show unique data based on the feature clicked. It does this using the features attributes.

      function addMarker() {
        var getmarker = [{
          x: "172.49720789367655",
          y: "-43.48319644512304",
          content: "This popup one content"
        }, {
          x: "172.50933147842412",
          y: "-43.48894119812065",
          content:"This popup two content"
        }]
        getmarker.forEach(function (marker) {
          var p = new Point({
            longitude: marker.x,
            latitude: marker.y,
            spatialReference: {
              wkid: 4326
            }
          });
          var g = new Graphic({
            geometry: webMercatorUtils.geographicToWebMercator(p),
            symbol: textSymbol,
            attributes: {
              newDevelopment: "new marker",
              state: "new"
            },
            popupTemplate : {
              title: '',
              content: marker.content
            }
          });
          markerGL.add(g);
        });
      }
rsharma
Occasional Contributor III

Sir,

I think you haven't understood, user will enter any value in textbox of popup and on save buton i am saving it in db, but when i again open that popup my popup do contain content body,but data gone entered by user???

actually i m looking for tht data to stay. Your example only change body of popup

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Are you saying that you already have the part of entering and saving to the database working? If so then my code above should work for you as it takes values from your database and adds them as the content of the features popup.

0 Kudos
rsharma
Occasional Contributor III

Yes, i have already done entering and saving data in db, i have one textbox which takes data from user and save in db, but your code do not work, as i am already defining body for in its content popup for all markers and and this code below of urs wiill replace my basic editable html. actually i have to see those popup data on my same editing mode popup

content: marker.content
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Rajni,

   Without seeing how you are defining the markers popup to begin with I am not sure how I would know what you are doing.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Rajni,

  OK, Here is my tested solution:

      function addMarker() {
        var getmarker = [{
          x: "172.49720789367655",
          y: "-43.48319644512304",
          content: "This popup one content"
        }, {
          x: "172.50933147842412",
          y: "-43.48894119812065",
          content:"This popup two content"
        }]
        getmarker.forEach(function (marker) {
          var p = new Point({
            longitude: marker.x,
            latitude: marker.y,
            spatialReference: {
              wkid: 4326
            }
          });
          var g = new Graphic({
            geometry: webMercatorUtils.geographicToWebMercator(p),
            symbol: textSymbol,
            attributes: {
              newDevelopment: "new marker",
              state: "new",
              content: marker.content
            }
          });

          //add content of popup body here
          g.popupTemplate = {
            title : ' ',
            content: setContentInfo
          };
          markerGL.add(g);
        });
      }

      function setContentInfo(feature){
        var popup_html = '<div class="be-form-wrapper">';
              popup_html += '<div>';
              popup_html += '<textarea cols="4" rows="4" class="form-control b_radius mt-20 write_comment" id="write_comment" name="write_comment" placeholder="Write a comment">' + feature.graphic.attributes.content + '</textarea>';
              popup_html += '</div>';
              popup_html += '<div>';
              popup_html += '<button class="btn btn-width" data-url="">Cancel</button>';
              popup_html += '</div>';
              popup_html += '<div>';
              popup_html += '<button class="btn btn-width" data-url="">Save</button>';
              popup_html += '</div>';
              popup_html += '</div>';
        var node = domConstruct.toDom(popup_html);
        return node;
      }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
rsharma
Occasional Contributor III

sir Robert Scheitlin, GISP

The issue in it, is that data from db come on my page when my editor page is refreshed it, but what if i do not refresh page.

At the time, when i save data in db and without refreshing page, i want my data to stay in my popup, so when i close popup and again open and check it to edit , at that time my popup is empty.

I want to retain data of popups in it without refreshing page even it is saved in db or user close that popup in between without saving.

Is their any way to get any unique ids of popup or markers dropped, so that i can try to access them individually when searching through layer

0 Kudos