I had a tricky problem recently of trying to parse very poorly formed Shapefiles from a client to create this map (still a work in progress): http://www.lynxgeos.com/TasHCVmap/#
I had already built a shapefile to Polygon converter (using vanrikom's excellent as classes) for some other projects, but this time I built a shapefile to Encoded Polygon converter. It creates an XML file that can be parsed to create polygons from the sets of encoded polylines at runtime. The nice thing about this method is that it shows interior shapes as transparent (eg. the doughnut with hole problem). You can use it here at: http://www.lynxgeos.com/shpConverter/shpConverter.html Please let me know if you use it and any issues you have. The shapefiles must be polygons, and they must be in WGS84 projection to work correctly. Other than that, they should work for any size shapefile. And you would use this sort of code to implement (below in actionscript): private function encodedDataLoaderComplete(event:Object):void { trace("encoded Data loaded"); var xmlData:XML = new XML(event.currentTarget.data); for each(var xmlPolygon:XML in xmlData.elements()) { var groupName:String= xmlPolygon.Group; var latSouthwest:Number=xmlPolygon.latSouthwest; var lngSouthwest:Number=xmlPolygon.lngSouthwest; var latNortheast:Number=xmlPolygon.latNortheast; var lngNortheast:Number=xmlPolygon.lngNortheast; var polygonBounds:LatLngBounds=new LatLngBounds(new LatLng(latSouthwest,lngSouthwest),new LatLng(latNortheast,lngNortheast)); var encodedPolylines:Array=[]; for each (var polyline:XML in xmlPolygon.child("polyline")){ var encodedPLdata:EncodedPolylineData=new EncodedPolylineData(polyline.points, 2, polyline.levels, 18); //EncodedPolylineData(points:String, zoomFactor:Number, levels:String, numLevels:Number) encodedPolylines.push(encodedPLdata); } var shape:Object={ groupName: groupName, Bounds:polygonBounds, Polylines:encodedPolylines } shpObjectArray.push(shape); }//end each shape dataLoaded=true; mapPolygons(); }//end Function //CREATE THE POLYS ON THE MAP: public function mapPolygons():void{ trace("mapPolygons called"); if (mapReady && dataLoaded){ trace ("mapPolygons started"); //Only now can we create the polygons--for some reason creating a polygon before the map is ready, crash. //create the colors for the poly: var polOpt:PolygonOptions = new PolygonOptions({ strokeStyle: new StrokeStyle({ color: 0xFFBB08,thickness: 2,alpha: 1}), fillStyle: new FillStyle({color: 0xFFBB08,alpha:0.2}) }); for each (var shp:Object in shpObjectArray){ var groupName:String=shp.groupName; var polygonBounds:LatLngBounds=shp.Bounds; var encodedPolyLines:Array = shp.Polylines as Array; var polygon:Polygon = Polygon.fromEncoded(encodedPolyLines, polOpt); //crashes if done before mapReady(?) polygon.addEventListener(MapMouseEvent.ROLL_OVER, polyMouseIn); polygon.addEventListener(MapMouseEvent.ROLL_OUT, polyMouseOut); map.addOverlay(polygon); -- You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.
