Created
June 1, 2013 21:35
-
-
Save ungoldman/5691799 to your computer and use it in GitHub Desktop.
ArcGIS JS spatial reference helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define([], function(){ | |
| return { | |
| // check if an object is a geometry | |
| isGeometry: function(object){ | |
| return object.isInstanceOf(esri.geometry.Geometry); | |
| }, | |
| // check if an object is a graphic | |
| isGraphic: function(object){ | |
| return object.isInstanceOf(esri.Graphic); | |
| }, | |
| // Check if a geometry or graphic is Geographic (Lat,Lng) | |
| isGeographic: function(object){ | |
| if(this.isGraphic(object)){ | |
| return object.geometry.spatialReference.wkid === 4326; | |
| } else if(this.isGeometry(object)) { | |
| return object.spatialReference.wkid === 4326; | |
| } else { | |
| return false; | |
| } | |
| }, | |
| // Check if a geometry or graphic is In Web Mercator | |
| isWebMercator: function(object){ | |
| if(this.isGraphic(object)){ | |
| return object.geometry.spatialReference.wkid === 102100; | |
| } else if(this.isGeometry(object)) { | |
| return object.spatialReference.wkid === 102100; | |
| } else { | |
| return false; | |
| } | |
| }, | |
| // Convert a geometry to webmercator if neccessary | |
| convertToWebMercator: function(geometry){ | |
| if(this.isGeographic(geometry)) { | |
| return esri.geometry.geographicToWebMercator(geometry); | |
| } else { | |
| return geometry; | |
| } | |
| }, | |
| // Convert a geometry to webmercator if neccessary | |
| convertToGeographic: function(geometry){ | |
| if(this.isWebMercator(geometry)) { | |
| return esri.geometry.webMercatorToGeographic(geometry); | |
| } else { | |
| return geometry; | |
| } | |
| }, | |
| convert: function(geometry) { | |
| if (this.isWebMercator(geometry)) { | |
| return this.convertToGeographic(geometry); | |
| } else if (this.isGeographic(geometry)) { | |
| return this.convertToWebMercator(geometry); | |
| } | |
| } | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment