Getting an error when trying to do a query in esri-leaflet

6154
17
09-12-2014 10:42 AM
Labels (1)
joepublic
New Contributor III

I am trying to created an app that when you click on a button at the top of the page will display only the countries that will satisfy the query attached to the button (see bottom of the file attached).

 

Here is the snippet of the code:

 

$('#NSM').click(function(){

     var buttonType = document.getElementById('NSM');

     countries.setWhere('type="'+ buttonType.value + '"');

});

 

I am using the "querying features #2" as my template.

 

The error I'm getting is

{"error":{"code":400,"message":"Unable to complete operation.","details":["Attribute column not found [Microsoft SQL Server Native Client 11.0: Invalid column name 'NSM'.] [MEP_global_data.DBO.test_bdry]"]}}

 

Any help would be appreciated

 

Thanks

Tags (1)
0 Kudos
17 Replies
PaulCrickard1
Occasional Contributor II

the error says you have no field named NSM. Is there a property named NSM in the data?

What does the HTML for the button look like?

0 Kudos
PaulCrickard1
Occasional Contributor II

and the country value is in a field named type? What does the data table look like? what is the field holding the country?

0 Kudos
joepublic
New Contributor III

Here is the url

"http://dev.consciousglobalchange.org/arcgis/rest/services/MEP/noRelate_tester/FeatureServer/0

The column name is "type" the value is NSM

Let me know if you need any more information

Chris

0 Kudos
PaulCrickard1
Occasional Contributor II

try setWhere(" type like 'nsm' ").

ArcGIS REST Services DirectoryLogin | Get Token

Query: MEP_global_data.DBO.test_bdry (ID: 0)

Where:
Object IDs:
Time:
Input Geometry:
Geometry Type:
Input Spatial Reference:
Spatial Relationship:
Relation:
Out Fields:
Return Geometry: True   False
Max Allowable Offset:
Geometry Precision:
Output Spatial Reference:
Geodatabase Version Name:
Return IDs Only: True   False
Return Count Only: True   False
Order By Fields:
Group By Fields (ForStatistics):
Output Statistics:
ReturnZ: True   False
ReturnM: True   False
Format:

# records: 6

type: NSM

Polygon:

[-1.05925448094E7, 6331610.610799998] , [-1.05925143079E7, 6337259.6477999985] , [-1.05923596851E7, 6339015.385300003] more...

[-1.74327857678E7, 1.1523017382700004E7] , [-1.74324155192E7, 1.15212753389E7] , [-1.74266945879E7, 1.1507461465899996E7] more...

[-1.70654633969E7, 7965857.698700003] , [-1.70644136541E7, 7967666.887500003] , [-1.70635779787E7, 7968250.298199996] more...

[-1.91074667251E7, 9277683.944799997] , [-1.91073749979E7, 9276497.047700003] , [-1.91068790695E7, 9273703.769900002] more...

[-1.4875929794599999E7, 7612574.983099997] , [-1.4875929794599999E7, 7613688.5315999985] , [-1.4873456720800001E7, 7628072.728600003] more...

[-1.51547280122E7, 8013438.626999997] , [-1.5154136794300001E7, 8014083.521700002] , [-1.51351838718E7, 8009271.293399997] more...

[-1.8491374124E7, 8490460.355300002] , [-1.84912484443E7, 8489146.592200004] , [-1.84870155207E7, 8473950.735399999] more...

[-1.5023646974E7, 8052052.3552] , [-1.5023307227E7, 8053469.133299999] , [-1.5022131804499999E7, 8053527.569499999] more...

0 Kudos
joepublic
New Contributor III

$('#NSM').click(function(){

     var buttonType = document.getElementById('NSM');

     countries.setWhere('type like"'+ buttonType.value + '"');

});

Didn't work... Got the same error: .... Invalid column name 'NSM'.

It thinks the column name is NSM instead of type

This is what I see in google's developers tool:

  1. geometryType:esriGeometryEnvelope
  2. geometry:{"xmin":-180.09,"ymin":11.50500000000001,"xmax":-0.08999999999999009,"ymax":85.95612673286779,"spatialReference":{"wkid":4326}}
  3. outFields:*
  4. outSR:4326
  5. inSR:4326
  6. where:type like"NSM"
  7. f:json
0 Kudos
PaulCrickard1
Occasional Contributor II

the field is type and the value is NSM. I got that error when I had NSM wrapped in double quotes

Capture.JPG

when I type like 'NSM' I get the results as expected.

you can use = too but has to be single quotes around NSM.

0 Kudos
PaulCrickard1
Occasional Contributor II

got it.

Capture.JPG

Here is my code. No Jquery.

<!DOCTYPE html>

<html>

  <head>

<title>NSM</title>

     <!-- Load Leaflet from CDN-->

    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />

    <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>

    <!-- Load Esri Leaflet from CDN -->

    <script src="http://cdn-geoweb.s3.amazonaws.com/esri-leaflet/0.0.1-beta.5/esri-leaflet.js"></script>

    <style>

      html, body,  #map {

        width : 100%;

        height : 100%;

      }

    </style>

  </head>

  <body>

<button onclick="NSM()">NSM</button>

<div id="map"></div>

<script>

var you;

//var map = L.map('map');

var map = L.map('map').setView([35.10418,-106.62987], 13);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',{opacity:.4}).addTo(map);

map.locate({watch:true, setView: false ,maxZoom: 16,enableHighAccuracy:true});

var nsm = new L.esri.FeatureLayer("http://dev.consciousglobalchange.org/arcgis/rest/services/MEP/noRelate_tester/FeatureServer/0");

      var popupTemplate = "<h3>{type}</h3>";

      nsm.bindPopup(function(feature){

        return L.Util.template(popupTemplate, feature.properties)

      });

function NSM(){

nsm.setWhere("type like "+ "'NSM'");

nsm.addTo(map);

}

    </script>

  </body>

</html>

0 Kudos
joepublic
New Contributor III

Paul,

Using the single quotes worked!!

I made some changes similar to the code you posted above so that the tilemap is displayed initially. 

When you click on the button the countries that satisfy the query are over-layed on the map

Now I am getting the following error:  Uncaught TypeError: Cannot read property 'getBounds' of undefined

$('#NSM').click(function(){

      var buttonType = document.getElementById('NSM')

      countries.setWhere("type like "+"'"+buttonType.value+"'");

      countries.addTo(map);  <- placing this line here causes the error

});

Link to demo: Esri Leaflet Demo

Can you tell me what I'm doing wrong??

Thanks

0 Kudos
PaulCrickard1
Occasional Contributor II

I got the same error. It was because I was not running the sample on a server, but from my desktop. You have to run the code from a webserver or it will not work. Could that be what is happening when you run it?

I ran it from my server and it worked perfect. Had the countries and when I clicked them they turned red and data was on the right side of screen.

0 Kudos