0

I want to display objectid information in url link according to this sample for my point feature layer. I´m able to use this sample for my polygon layers, but not for points. My adapted function:

//when users click on the map select the parcel using the map point and update the url parameter
    map.on("click", function (e) {
        alert("test");
      var query = new Query();
      query.geometry = e.screenPoint;
      var deferred = parcels.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (selection) {
          alert("test01");
        //update the url param if a parcel was located
          if (selection.length > 0) {
              alert("test1");
            var parcelid = selection[0].attributes["OBJECTID"];
          //Refresh the URL with the currently selected parcel
            if (typeof history.pushState !== "undefined") {
                alert("test2");
              window.history.pushState(null, null, "?parcelid=" + selection[0].attributes.OBJECTID);
          }
        }
      });
      map.infoWindow.setFeatures([deferred]);
      map.infoWindow.show(e.screenPoint);
    });

Console error: Cannot read property '_getInfo' of undefined

Popup is displayed both for polygons and points.

Can someone explain me why I can use polygon layers but not point layer ?

  • 1
    Are you getting a point returned by the query? You may have to buffer the clicked point – kenbuja Mar 10 '17 at 14:02
  • What version of ArcGIS JavaScript API are you using? I assume 3.x but that information would be helpful. – PMK Mar 10 '17 at 14:16
1

Try using "evt.mapPoint" to get the point geometry of the clicked position not "evt.screenPoint" in API 3.x. the screenPoint property will return the x and y coordinates of the screen and not the map so your query will execute in the wrong location if it even executes at all.

Try the following:

//when users click on the map select the parcel using the map point and update the url parameter
    map.on("click", function (e) {
        alert("test");
      var query = new Query();
      query.geometry = e.mapPoint;
      var deferred = parcels.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (selection) {
          alert("test01");
        //update the url param if a parcel was located
          if (selection.length > 0) {
              alert("test1");
            var parcelid = selection[0].attributes["OBJECTID"];
          //Refresh the URL with the currently selected parcel
            if (typeof history.pushState !== "undefined") {
                alert("test2");
              window.history.pushState(null, null, "?parcelid=" + selection[0].attributes.OBJECTID);
          }
        }
      });
      map.infoWindow.setFeatures([deferred]);
      map.infoWindow.show(e.screenPoint);
    });
  • thanks for advice. I tried your solution, but when I use e.mapPoint, the popup is empty with "No information available" and without error in console. It works with polygon layer perfectly. Any other advice how to solve this with point layer ? And It´s api 3.19. – Martin Zápotocký Mar 13 '17 at 14:49
0

Solved with buffer ! :-)

map.on("click", function (e) {
        var query = new Query();

        var centerPoint = new esri.geometry.Point
            (e.mapPoint.x, e.mapPoint.y, e.mapPoint.spatialReference);
        var mapWidth = map.extent.getWidth();

        //Divide width in map units by width in pixels
        var pixelWidth = mapWidth / map.width;

        //Calculate a 10 pixel envelope width (5 pixel tolerance on each side)
        var tolerance = 10 * pixelWidth;

        //Build tolerance envelope and set it as the query geometry
        var queryExtent = new esri.geometry.Extent
                (1, 1, tolerance, tolerance, e.mapPoint.spatialReference);
        query.geometry = queryExtent.centerAt(centerPoint);

      var deferred = parcels.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (selection) {
          alert("test01");
        //update the url param if a parcel was located
          if (selection.length > 0) {
              alert("test1");
            var parcelid = selection[0].attributes["OBJECTID"];
          //Refresh the URL with the currently selected parcel
            if (typeof history.pushState !== "undefined") {
                alert("test2");
              window.history.pushState(null, null, "?parcelid=" + selection[0].attributes.OBJECTID);
          }
        }
      });
      map.infoWindow.setFeatures([deferred]);          
    });

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.