Drawing a polygon using Easting and Northings

2326
4
Jump to solution
02-15-2012 05:06 AM
PeterBridger
New Contributor II
I'm using the polygon drawing code here to draw my own polygon retrieved using AJAX.

This is for a web application designed to run in the UK, so the points retrieved are eastings and northings.

However I don't understand how to get ESRI ArcGIS to display polygons using eastings and northing are points.

I've been looking through the documentation and examples, but I'm struggling to find anything that can help me.

My code is as follows:

               var points = new Array();                var csv = result.Value.split(','); // CSV of eastings and northings                for( var i = 0; i < csv.length; i+=2){                 points[points.length] = new esri.geometry.Point(csv, csv[i+1]);                }                                 // Draw polygon                var polygon = new esri.geometry.Polygon();                polygon.addRing(points);                polygon.spatialReference = new esri.SpatialReference({ wkid: 27700 }); // British National Grid                                  // Add the polygon to map                 var symbol = new esri.symbol.SimpleFillSymbol().setStyle(esri.symbol.SimpleFillSymbol.STYLE_SOLID);                 polygonGraphic = new esri.Graphic(polygon, symbol);                 map.graphics.add(polygonGraphic);



Any help would be very much appreciated

Thanks
Peter Bridger
0 Kudos
1 Solution

Accepted Solutions
PeterBridger
New Contributor II
I wasn't able to change projections using ESRI's JavaScript methods (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/util_project.html), due to it requiring a proxy and unresolved issues when I attempted to setup this up.

Instead I've implemented a server-side solution that converts from

British National Grid (27700)
to
WGS84 (4326)
to
Web Mercator (102100)

I've achieved this by using Proj.Net for the British National Grid (27700) to WGS84 (4326) conversion

Then for the WGS84 (4326) to Web Mercator (102100) conversion I used the code in this article

Hope this is of help for someone else
Peter

View solution in original post

0 Kudos
4 Replies
derekswingley1
Frequent Contributor
What's the spatial reference of your map? If it's anything other than British National Grid, you'll need to project your polygon to your map's spatial reference before you can add it to the map:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/util_project.html That sample projects a point but the same workflow applies to other geometry types.

Also, you linked to a 1.6 version of the help. The most current version of the help (and API) is 2.7). We recommend you use that. Here's the same sample, but using 2.7:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/util_simplify.html
0 Kudos
PeterBridger
New Contributor II
Hi Derek

Thanks for your response.

I've used Google Maps in the past on many projects, but we're planning to use ESRI's web service due to the scale of what we're planning to deliver with this project.

I'm afraid I'm struggling to get to grips with the ESRI web client, I'm used to dealing with simple Google Map implementations using just lat/longs. The move to a more complex system which benefits from more in depth knowledge of projections, spatial references and a whole new library is causing me grief.


We are storing our spatial data in SQL Server 2008. We need to plot new points, polylines and polygon through the ESRI web client and then store in the SQL Server backend. We also need the ESRI web client to display the points, polylines and polygons returned by the server.

We are using a spatial reference of OSGB 1936 (British National Grid).

If you could point me to examples that would get me on the right path I would appreciate it. Currently I'm building a Frankenstein's Monster of an web client attempting to get a feel for the concepts and library knowledge I need.

Any guidance or examples you could give would be very much appreciated.

Thanks
Peter
0 Kudos
PeterBridger
New Contributor II
For reference with my problem and in case it helps anyone else, I've found the following article which is discussing the type of issue I'm having. I'll post back if this allows me to sort out my issues.

Conversion of British National Grid (WKID:27700) to WGS84(WKID:4326) and then to Web Mercator (WKID:102100)

I decided to write this article as in my work (local authority) the 90% of the spatial data is created using British National Grid coordinate system.

Working with ArcGIS server there was never problem to display the data properly on the top of OS Mastermap or rasters, however few weeks ago I decided to do some mash up using the ArcGIS Java Script API and the basemap dijit and the problems jumped out.
I had to use the British National Grid data over the basemap having the WebMercator projection or a basemap coming from the basemap gallery
0 Kudos
PeterBridger
New Contributor II
I wasn't able to change projections using ESRI's JavaScript methods (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/util_project.html), due to it requiring a proxy and unresolved issues when I attempted to setup this up.

Instead I've implemented a server-side solution that converts from

British National Grid (27700)
to
WGS84 (4326)
to
Web Mercator (102100)

I've achieved this by using Proj.Net for the British National Grid (27700) to WGS84 (4326) conversion

Then for the WGS84 (4326) to Web Mercator (102100) conversion I used the code in this article

Hope this is of help for someone else
Peter
0 Kudos