Select to view content in your preferred language

Problem with using "WebMercatorUtil.geographicToWebMercator"

2926
1
Jump to solution
04-20-2011 07:36 AM
by Anonymous User
Not applicable
Original User: tbrophy

All,
I downloaded and am using "Shape File Overlay for Sample Viewer" from the ArcGIS resource Center, submitted 3-4-2010 by "HardWork". It works great, but I need it go a step further.
""Shape File Overlay for Sample Viewer""
http://resources.esri.com/arcgisserver/apis/flex/index.cfm?fa=codeGalleryDetails&scriptID=16846

Problem:
My application is in Web Mercator (102100). So every time my users want to use this tool, they need to convert their shapefile from WGS 1984 Geographic (4326) into Web Mercator (102100) in ArcMap first.
The conversion would always be the same (4326) --> (102100).
--------------------------------------------------------------------------------------------------------------------------------
Dasa Paddock from ESRI response:
You can use this to do the conversion:
http://resources.esri.com/help/9.3/arcgisserver/apis/flex/apiref/com/esri/ags/utils/WebMercatorUtil....

"geographicToWebMercator"
--------------------------------------------------------------------------------------------------------------------------------
I tried the conversion Dasa suggested and got it to work half way using the attached wgs84 zipped shapefile, "CHLORINE_Release_Model4326.zip". It zooms the right location (Dallas, TX) but the graphic does not show up. I think the problem is in the "loadShapefile" function, at line:138.

//
private function loadShapefile(shpByteArray:ByteArray, dbfByteArray:ByteArray):void
{
var index:int = 0;
const array:Array = [];
const shpReader:ShpReader = new ShpReader(shpByteArray);
const dbfHeaderbfHeader = new DbfHeader(dbfByteArray);
while (shpReader.hasMore())
{
var shpPolygon:ShpPolygon = shpReader.readShpPolygon();
var dbfRecordbfRecord = DbfTools.getRecord(dbfByteArray, dbfHeader, index++);
var myGraphic:Graphic = new Graphic(shpPolygon, shpSymbol, dbfRecord.values);
array.push(myGraphic);
//array.push(new Graphic(shpPolygon, shpSymbol, dbfRecord.values));
}
/*Code from "Live sample - Bing Maps geocoder"
var veResult:VEGeocodeResult = results[0];
var myGraphic:Graphic = new Graphic();
myGraphic.geometry = WebMercatorUtil.geographicToWebMercator(veResult.location);
myGraphic.symbol = mySymbol;
myGraphic.toolTip = veResult.displayName;
myGraphic.id = "graphic";
myGraphicsLayer.add(myGraphic);
myMap.extent = WebMercatorUtil.geographicToWebMercator(veResult.bestView) as Extent;
*/
//var arrayGraphic:Graphic = new Graphic();
//arrayGraphic.geometry = WebMercatorUtil.geographicToWebMercator(array.location);
//graphicsLayer.add(arrayGraphic);
graphicsLayer.graphicProvider = new ArrayCollection(array);
map.addLayer(graphicsLayer);
//map.extent = shpReader.extent.expand(1.5);
map.extent = WebMercatorUtil.geographicToWebMercator(shpReader.extent.expand(1.5)) as Extent;
msgBox.text = "Polygon footprint has been successfully loaded.";
}
//

CAN ANYONE HELP ME? PLEASE?

The mxml is attached, "ShpOverlay_wgs84.zip".
********************************************
*** I am using older SFV environment:
********************************************
flexviewer-src-1.0.zip (Build 06.12.09)
agslib-1.2.swc
flex_sdk_3.2
********************************************
********************************************
�??
Note:
I have this threat in Forum: ArcGIS API for Flex and thought it makes more sense over here.
Title: Load WGS84 Local Shapefile and Display in Web Mercator
URL: http://forums.arcgis.com/threads/17440-Load-WGS84-Local-Shapefile-and-Display-in-Web-Mercator-Applic...

Sinceraly,
Thomas
0 Kudos
1 Solution

Accepted Solutions
ThomasBrophy
Regular Contributor
Melinda Frost helped me with the answer on another post:
Load WGS84 Local Shapefile and Display in Web Mercator Application
http://forums.arcgis.com/threads/17440-Load-WGS84-Local-Shapefile-and-Display-in-Web-Mercator-Applic...

Here's the final code for "loadShapefile":

private function loadShapefile(shpByteArray:ByteArray, dbfByteArray:ByteArray):void
{
var index:int = 0;
const array:Array = [];
const shpReader:ShpReader = new ShpReader(shpByteArray);
const dbfHeaderbfRecord = DbfTools.getRecord(dbfByteArray, dbfHeader, index++);
//geoToWebM Start
var myGraphic:Graphic = new Graphic();
myGraphic.geometry = WebMercatorUtil.geographicToWebMercator(shpPolygon.toPolygon());
myGraphic.symbol = myPoly;
graphicsLayer.add(myGraphic);
//geoToWebM End
//array.push(new Graphic(shpPolygon, shpSymbol, dbfRecord.values));
}
//graphicsLayer.graphicProvider = new ArrayCollection(array);
map.addLayer(graphicsLayer);
//map.extent = shpReader.extent.expand(1.5);
//geoToWebM Start
map.extent = WebMercatorUtil.geographicToWebMercator(shpReader.extent.expand(2.0)) as Extent;
//geoToWebM End
msgBox.htmlText = "Polygon footprint has been successfully loaded.";
}

I also attached the mxml.

Thanks again Melinda!

View solution in original post

0 Kudos
1 Reply
ThomasBrophy
Regular Contributor
Melinda Frost helped me with the answer on another post:
Load WGS84 Local Shapefile and Display in Web Mercator Application
http://forums.arcgis.com/threads/17440-Load-WGS84-Local-Shapefile-and-Display-in-Web-Mercator-Applic...

Here's the final code for "loadShapefile":

private function loadShapefile(shpByteArray:ByteArray, dbfByteArray:ByteArray):void
{
var index:int = 0;
const array:Array = [];
const shpReader:ShpReader = new ShpReader(shpByteArray);
const dbfHeaderbfRecord = DbfTools.getRecord(dbfByteArray, dbfHeader, index++);
//geoToWebM Start
var myGraphic:Graphic = new Graphic();
myGraphic.geometry = WebMercatorUtil.geographicToWebMercator(shpPolygon.toPolygon());
myGraphic.symbol = myPoly;
graphicsLayer.add(myGraphic);
//geoToWebM End
//array.push(new Graphic(shpPolygon, shpSymbol, dbfRecord.values));
}
//graphicsLayer.graphicProvider = new ArrayCollection(array);
map.addLayer(graphicsLayer);
//map.extent = shpReader.extent.expand(1.5);
//geoToWebM Start
map.extent = WebMercatorUtil.geographicToWebMercator(shpReader.extent.expand(2.0)) as Extent;
//geoToWebM End
msgBox.htmlText = "Polygon footprint has been successfully loaded.";
}

I also attached the mxml.

Thanks again Melinda!
0 Kudos