Loading src/App.jsx +4 −1 Original line number Diff line number Diff line Loading @@ -14,9 +14,12 @@ export default class App extends Component { } componentDidMount() { let map = new AstroMap("map-container", "Mars", {}); let map = new AstroMap("map-container", "mars", {}); let projectionControl = new Projection(); projectionControl.addTo(map); let scaleControl = new L.Control.Scale({ imperial: false }); scaleControl.addTo(map); } render() { Loading src/js/AstroMap.js +12 −12 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ export default L.Map.AstroMap = L.Map.extend({ center: [0, 0], zoom: 1, maxZoom: 8, crs: L.CRS.EPSG4326, attributionControl: false }, Loading @@ -33,16 +32,20 @@ export default L.Map.AstroMap = L.Map.extend({ initialize: function(mapDiv, target, options) { this.mapDiv = mapDiv; this.target = target; this.AstroProj = new AstroProj(); this.astroProj = new AstroProj(); this.radii = this.astroProj.getRadii(this.target); this.layers = { geodesic: new LayerCollection(this.target, "cylindrical"), cylindrical: new LayerCollection(this.target, "cylindrical"), northPolar: new LayerCollection(this.target, "north-polar stereographic"), southPolar: new LayerCollection(this.target, "south-polar stereographic") }; this.defaultProj = L.extend({}, L.CRS.EPSG4326, { R: this.radii["a"] }); this.options["crs"] = this.defaultProj; L.setOptions(this, options); L.Map.prototype.initialize.call(this, this.mapDiv, this.options); this.loadLayerCollection("geodesic"); this.loadLayerCollection("cylindrical"); }, // @method loadLayerCollection(name: String) Loading @@ -55,21 +58,18 @@ export default L.Map.AstroMap = L.Map.extend({ // Changes the projection of the map and resets the center and view. changeProjection: function(name, center) { let newCRS = null; if (name == "geodesic") { newCRS = L.CRS.EPSG4326; if (name == "cylindrical") { newCRS = this.defaultProj; } else { let proj = this.AstroProj.getStringAndCode(this.target, name); let proj = this.astroProj.getStringAndCode(this.target, name); newCRS = new L.Proj.CRS(proj["code"], proj["string"], { resolutions: [8192, 4096, 2048, 1024, 512, 256, 128], origin: [0, 0] }); } this.options.crs = newCRS; this._resetView(center, 1, true); this.setView(center, 1, true); this.loadLayerCollection(name); } }); // exports.L.map.astroMap = function(mapDiv, target, options) { // return new L.map.astroMap(mapDiv, target, options); // }; src/js/AstroProj.js +33 −38 Original line number Diff line number Diff line const projectionDefs = { mars: [ { name: "northpolar", code: "EPSG:32661", string: "+proj=stere +lat_0=90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=3396190 +b=3396190 +units=m +no_defs" }, { name: "southpolar", code: "EPSG:32761", string: "+proj=stere +lat_0=-90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=3396190 +b=3376200 +units=m +no_defs" }, { name: "geodesic", code: "EPSG:4326", string: "+proj=longlat +a=3396190 +b=3396190 +no_defs" } ] }; import { MY_JSON_MAPS } from "./layers"; /* * @class AstroProj Loading @@ -27,30 +7,45 @@ const projectionDefs = { * by the USGS. */ export default class AstroProj { // @method getString(target: String, code: String): String // Returns the proj-string for a requested target given the proj-code. getString(target, code) { let projections = projectionDefs[target.toLowerCase()]; for (let i = 0; i < projections.length; i++) { if (code == projections[i]["code"]) { return projections[i]["string"]; getRadii(target) { var targets = MY_JSON_MAPS["targets"]; let radii = {}; for (let i = 0; i < targets.length; i++) { let currentTarget = targets[i]; if (currentTarget["name"].toLowerCase() == target.toLowerCase()) { radii["a"] = parseFloat(currentTarget["aaxisradius"] * 1000); radii["c"] = parseFloat(currentTarget["caxisradius"] * 1000); break; } } console.log("No projection found for the target"); return radii; } // @method getStringAndCode(target: String, name: String): [String, String] // Returns the proj-string for a requested target and projection name. getStringAndCode(target, name) { let projections = projectionDefs[target.toLowerCase()]; for (let i = 0; i < projections.length; i++) { if (name.toLowerCase() == projections[i]["name"]) { let radii = this.getRadii(target); if (name == "northPolar") { return { code: projections[i]["code"], string: projections[i]["string"] code: "EPSG:32661", string: "+proj=stere +lat_0=90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=${radii['a']} +b=${radii['c']} +units=m +no_defs" }; } else if (name == "southPolar") { return { code: "EPSG:32761", string: "+proj=stere +lat_0=-90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=${radii['a']} +b=${radii['c']} +units=m +no_defs" }; } else if (name == "cylindrical") { return { code: "EPSG:4326", string: "+proj=longlat +a=${radii['a']} +b=${radii['c']} +no_defs" }; } else { console.log("No projection found for the target and name given."); } } console.log("No projection found for the target"); } } src/js/LayerCollection.js +0 −4 Original line number Diff line number Diff line Loading @@ -125,7 +125,3 @@ export default L.LayerCollection = L.Class.extend({ L.LayerCollection.layerControl.addTo(map); } }); // exports.L.layerCollection = function(target, projName) { // return new L.LayerCollection(target, projName); // }; src/js/Projection.js +4 −8 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ export default L.Control.Projection = L.Control.extend({ this.northPolar = L.DomUtil.get("projectionNorthPole"); L.DomEvent.on(this.northPolar, "click", this.loadNorthPolar, this); this.geodesic = L.DomUtil.get("projectionCylindrical"); L.DomEvent.on(this.geodesic, "click", this.loadGeodesic, this); this.cylindrical = L.DomUtil.get("projectionCylindrical"); L.DomEvent.on(this.cylindrical, "click", this.loadCylindrical, this); this.southPolar = L.DomUtil.get("projectionSouthPole"); L.DomEvent.on(this.southPolar, "click", this.loadSouthPolar, this); Loading @@ -39,12 +39,8 @@ export default L.Control.Projection = L.Control.extend({ // @method loadGeodesic(e: DomEvent) // Sets the map's projection to geodesic. loadGeodesic: function(e) { loadCylindrical: function(e) { let center = [0, 0]; this._map.changeProjection("geodesic", center); this._map.changeProjection("cylindrical", center); } }); // exports.L.control.projection = function(options) { // return new L.Control.Projection(options); // }; Loading
src/App.jsx +4 −1 Original line number Diff line number Diff line Loading @@ -14,9 +14,12 @@ export default class App extends Component { } componentDidMount() { let map = new AstroMap("map-container", "Mars", {}); let map = new AstroMap("map-container", "mars", {}); let projectionControl = new Projection(); projectionControl.addTo(map); let scaleControl = new L.Control.Scale({ imperial: false }); scaleControl.addTo(map); } render() { Loading
src/js/AstroMap.js +12 −12 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ export default L.Map.AstroMap = L.Map.extend({ center: [0, 0], zoom: 1, maxZoom: 8, crs: L.CRS.EPSG4326, attributionControl: false }, Loading @@ -33,16 +32,20 @@ export default L.Map.AstroMap = L.Map.extend({ initialize: function(mapDiv, target, options) { this.mapDiv = mapDiv; this.target = target; this.AstroProj = new AstroProj(); this.astroProj = new AstroProj(); this.radii = this.astroProj.getRadii(this.target); this.layers = { geodesic: new LayerCollection(this.target, "cylindrical"), cylindrical: new LayerCollection(this.target, "cylindrical"), northPolar: new LayerCollection(this.target, "north-polar stereographic"), southPolar: new LayerCollection(this.target, "south-polar stereographic") }; this.defaultProj = L.extend({}, L.CRS.EPSG4326, { R: this.radii["a"] }); this.options["crs"] = this.defaultProj; L.setOptions(this, options); L.Map.prototype.initialize.call(this, this.mapDiv, this.options); this.loadLayerCollection("geodesic"); this.loadLayerCollection("cylindrical"); }, // @method loadLayerCollection(name: String) Loading @@ -55,21 +58,18 @@ export default L.Map.AstroMap = L.Map.extend({ // Changes the projection of the map and resets the center and view. changeProjection: function(name, center) { let newCRS = null; if (name == "geodesic") { newCRS = L.CRS.EPSG4326; if (name == "cylindrical") { newCRS = this.defaultProj; } else { let proj = this.AstroProj.getStringAndCode(this.target, name); let proj = this.astroProj.getStringAndCode(this.target, name); newCRS = new L.Proj.CRS(proj["code"], proj["string"], { resolutions: [8192, 4096, 2048, 1024, 512, 256, 128], origin: [0, 0] }); } this.options.crs = newCRS; this._resetView(center, 1, true); this.setView(center, 1, true); this.loadLayerCollection(name); } }); // exports.L.map.astroMap = function(mapDiv, target, options) { // return new L.map.astroMap(mapDiv, target, options); // };
src/js/AstroProj.js +33 −38 Original line number Diff line number Diff line const projectionDefs = { mars: [ { name: "northpolar", code: "EPSG:32661", string: "+proj=stere +lat_0=90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=3396190 +b=3396190 +units=m +no_defs" }, { name: "southpolar", code: "EPSG:32761", string: "+proj=stere +lat_0=-90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=3396190 +b=3376200 +units=m +no_defs" }, { name: "geodesic", code: "EPSG:4326", string: "+proj=longlat +a=3396190 +b=3396190 +no_defs" } ] }; import { MY_JSON_MAPS } from "./layers"; /* * @class AstroProj Loading @@ -27,30 +7,45 @@ const projectionDefs = { * by the USGS. */ export default class AstroProj { // @method getString(target: String, code: String): String // Returns the proj-string for a requested target given the proj-code. getString(target, code) { let projections = projectionDefs[target.toLowerCase()]; for (let i = 0; i < projections.length; i++) { if (code == projections[i]["code"]) { return projections[i]["string"]; getRadii(target) { var targets = MY_JSON_MAPS["targets"]; let radii = {}; for (let i = 0; i < targets.length; i++) { let currentTarget = targets[i]; if (currentTarget["name"].toLowerCase() == target.toLowerCase()) { radii["a"] = parseFloat(currentTarget["aaxisradius"] * 1000); radii["c"] = parseFloat(currentTarget["caxisradius"] * 1000); break; } } console.log("No projection found for the target"); return radii; } // @method getStringAndCode(target: String, name: String): [String, String] // Returns the proj-string for a requested target and projection name. getStringAndCode(target, name) { let projections = projectionDefs[target.toLowerCase()]; for (let i = 0; i < projections.length; i++) { if (name.toLowerCase() == projections[i]["name"]) { let radii = this.getRadii(target); if (name == "northPolar") { return { code: projections[i]["code"], string: projections[i]["string"] code: "EPSG:32661", string: "+proj=stere +lat_0=90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=${radii['a']} +b=${radii['c']} +units=m +no_defs" }; } else if (name == "southPolar") { return { code: "EPSG:32761", string: "+proj=stere +lat_0=-90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=${radii['a']} +b=${radii['c']} +units=m +no_defs" }; } else if (name == "cylindrical") { return { code: "EPSG:4326", string: "+proj=longlat +a=${radii['a']} +b=${radii['c']} +no_defs" }; } else { console.log("No projection found for the target and name given."); } } console.log("No projection found for the target"); } }
src/js/LayerCollection.js +0 −4 Original line number Diff line number Diff line Loading @@ -125,7 +125,3 @@ export default L.LayerCollection = L.Class.extend({ L.LayerCollection.layerControl.addTo(map); } }); // exports.L.layerCollection = function(target, projName) { // return new L.LayerCollection(target, projName); // };
src/js/Projection.js +4 −8 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ export default L.Control.Projection = L.Control.extend({ this.northPolar = L.DomUtil.get("projectionNorthPole"); L.DomEvent.on(this.northPolar, "click", this.loadNorthPolar, this); this.geodesic = L.DomUtil.get("projectionCylindrical"); L.DomEvent.on(this.geodesic, "click", this.loadGeodesic, this); this.cylindrical = L.DomUtil.get("projectionCylindrical"); L.DomEvent.on(this.cylindrical, "click", this.loadCylindrical, this); this.southPolar = L.DomUtil.get("projectionSouthPole"); L.DomEvent.on(this.southPolar, "click", this.loadSouthPolar, this); Loading @@ -39,12 +39,8 @@ export default L.Control.Projection = L.Control.extend({ // @method loadGeodesic(e: DomEvent) // Sets the map's projection to geodesic. loadGeodesic: function(e) { loadCylindrical: function(e) { let center = [0, 0]; this._map.changeProjection("geodesic", center); this._map.changeProjection("cylindrical", center); } }); // exports.L.control.projection = function(options) { // return new L.Control.Projection(options); // };