#include "MapSource.h" void MapSource::process_cmd_line_args(int argc,char *argv[]) { std::string bbox=""; argc--; argv++; width=800; height=600; while(argc>0) { if(argv[0][0]=='-' && strlen(argv[0])>1) { switch(argv[0][1]) { case 's': setSource(argv[1]); argv+=2; argc-=2; break; case 'w': width=atoi(argv[1]); argv+=2; argc-=2; break; case 'h': height=atoi(argv[1]); argv+=2; argc-=2; break; case 'x': xmlfile=argv[1]; argv+=2; argc-=2; break; case 'i': osmfile=argv[1]; argv+=2; argc-=2; break; case 'b': bbox=argv[1]; argv+=2; argc-=2; break; case 'z': zoom_start=atoi(argv[1]); argv+=2; argc-=2; break; case 'Z': zoom_end=atoi(argv[1]); argv+=2; argc-=2; break; case 't': tiled=true; argv+=1; argc-=1; break; case 'm': multirqst=true; argv+=1; argc-=1; break; case 'u': url=argv[1]; argv+=2; argc-=2; break; case 'o': outfile=argv[1]; argv+=2; argc-=2; break; } } else { argv++; argc--; } } if(bbox!="") { typedef boost::tokenizer > tokenizer; boost::char_separator comma(","); tokenizer t (bbox,comma); int count=0; for(tokenizer::iterator i=t.begin(); i!=t.end(); i++) { if(count==0) w=atof(i->c_str()); else if (count==1) s=atof(i->c_str()); else if (count==2) e=atof(i->c_str()); else if (count==3) n=atof(i->c_str()); count++; } } if(zoom_end == -1) zoom_end = zoom_start; } void MapSource::generateMaps() { if(tiled) { // code to convert a bbox to a series of tiles (see FreemapMobile?) // iterate through each tile and convert back to bboxes, zooming // for each (can use old 'render' code for this) // break the input into a series of 0.1 x 0.1 requests to osmxapi double curlon, curlat,nextlon,nextlat; curlon= (getSource()=="api" && multirqst)? 0.1*((int)(w*10)):w; while(curlon bb (metres_w-32*metres_per_pixel, metres_s-32*metres_per_pixel, metres_e+32*metres_per_pixel, metres_n+32*metres_per_pixel); m.zoomToBox(bb); agg_renderer r(m,buf); r.apply(); string filename=""; std::ostringstream str; str<< z<< "."< (buf.data(),str.str(),"png"); } } metres_per_pixel /= 2; } curlat = nextlat; } curlon = nextlon; } } else { // standard rendering Map m(width,height); parameters p; p["type"] = "osm"; p["file"] = osmfile; load_map(m,xmlfile); setOSMLayers(m,p); Envelope latlon= (hasBbox()) ? Envelope(w,s,e,n): m.getLayer(0).envelope(); EarthPoint bottomLeft = GoogleProjection::fromLLToGoog(latlon.minx(),latlon.miny()), topRight = GoogleProjection::fromLLToGoog(latlon.maxx(),latlon.maxy()); Envelope bb = Envelope(bottomLeft.x,bottomLeft.y, topRight.x,topRight.y); m.zoomToBox(bb); Image32 buf (m.getWidth(), m.getHeight()); agg_renderer r(m,buf); r.apply(); save_to_file(buf.data(),outfile,"png"); } } void MapSource::setOSMLayers(Map& m, const parameters &p) { parameters q; for(int count=0; countparams(); if(boost::get(q["type"])=="osm") { m.getLayer(count).set_datasource (datasource_cache::instance()->create(p)); } } } void MapSource::addSRTMLayers(Map& m,double w,double s,double e,double n) { // Get the layers from the map vector layers=m.layers(); cerr<<"***addSRTMLayers():w s e n="<=0 ? "E":"W") << setw(3)<=0 ? lon:-lon)<<"c10"; p["file"] = str.str(); cerr<<"ADDING SRTM LAYER: " << p["file"] << endl; m.getLayer(i).set_datasource(datasource_cache::instance()->create(p)); // do we have more than one srtm layer? if(floor(w) != floor(e) || floor(s) != floor(n)) { // remove all layers from the SRTM layer onwards. This is because there // are multiple SRTM layers (if the current tile spans a lat/lon square // boundary) for(int j=i+1; j=0 ? "E":"W") << setw(3)<=0 ? lon:-lon)<<"c10"; p["file"] = str.str(); cerr<<"ADDING SRTM LAYER: " << p["file"] << endl; Layer layer("srtm_" + str.str()); layer.add_style("contours"); layer.add_style("contours-text"); layer.set_datasource (datasource_cache::instance()->create(p)); m.addLayer(layer); } } } // Add the other layers back for(int j=i+1; j