Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a central point from an esri multipoint with javascript

I have created a webpage displaying markers on an ersi map using javasvipt.

Data: 
MapNorth    MapEast
439624  504743
439622  504736
439722  504775
439738  504739
439715  504774
439734  504739

The javascript code:

var points = data.map(function(x){
                    return [x.MapEast, x.MapNorth];
                });

                var myMultiPoint = {"geometry":{"points":points,"spatialReference":27700},"symbol":{"color":[255,255,255,64],
                "size":6,"angle":0,"xoffset":0,"yoffset":0,"type":"esriSMS","style":"esriSMSCircle",
                "outline":{"color":[0,0,0,255],"width":6,"type":"esriSLS","style":"esriSLSSolid"}}};  

                var gra = new esri.Graphic(myMultiPoint);

                myMap.graphics.add(gra);

                var graExtent = esri.graphicsExtent(myMap.graphics.graphics); 
                myMap.setExtent(graExtent); 

What the above code does is plot markers on the map and then zooms into the extent. What my employers want now is for me to find the central point of all of those points and display one marker in the center.

Can this be done? If so and you tell me how?

Thanks Paul

like image 310
Easty Avatar asked Apr 29 '26 18:04

Easty


1 Answers

Couple of things.

  1. Did you know about gis.stackexchange.com? They might better solve your problem.
  2. What you're trying to do is find the centre of a polygon assuming those points aren't all in a line.
  3. Here's a link with an answer to the question I think you're asking https://gis.stackexchange.com/questions/7998/how-can-i-calculate-the-center-point-inside-a-polygon-in-arcgis-9-3

The solution posted there uses getExtent().getCenter() as seen here

var myPolygonCenterLatLon = myPolygon.getExtent().getCenter();
like image 165
Dave Briand Avatar answered May 02 '26 07:05

Dave Briand