Beispiel #1
0
void Wikimapia::urlResponse(ofHttpResponse & response) {

    if(response.status == 200) {

        _json = ofxJSONElement(string(response.data));
        parseJson();

//		lock();
//
//		// Get the loaded url from the async queue and move it into the update queue.
//		entry_iterator it = getEntryFromAsyncQueue(response.request.name);
//		if(it != images_async_loading.end()) {
//			(*it).image->loadImage(response.data);
//			images_to_update.push_back((*it));
//			images_async_loading.erase(it);
//		}
//
//		unlock();
    } else {
        // log error.
        stringstream ss;
        ss << "Could not load from url, response status: " << response.status;
        ofLog(OF_LOG_ERROR, ss.str());

    }
}
Beispiel #2
0
void ofApp::parseJSONString(string str){
    
    mJsonElement = ofxJSONElement(str);
    
    mEvent = mJsonElement["event"].asString();
    mId = mJsonElement["id"].asInt();
    
    float x = mJsonElement["x"].asFloat();
    float y = mJsonElement["y"].asFloat();
    mScreenPoint = normalizedPointToScreenPoint(ofVec2f(x, y));
    
    
}
Beispiel #3
0
//--------------------------------------------------------------
void ofApp::update() {
    
    ofSetWindowTitle("fps: "+ ofToString(ofGetFrameRate()));
    
    cam.update();

    display.update(cam.getNumFaces());
    
    if(oscRecvr.hasWaitingMessages()){ //TODO: check how dangerous this blocking while is
        ofxOscMessage m;
        oscRecvr.getNextMessage(&m);
        cout<< "m.getAddress: "<<m.getAddress()<<endl;
        string incomingHostIp = m.getRemoteIp();
        cout << "\n-----------------\n\nRECVD OSC MESSAGE FROM IP: "+m.getRemoteIp()<<endl;
        cout << " /address: "<< m.getAddress() << endl;
        //cout << "\t MSG: "+ getOscMsgAsString(m) << "\n\n------------";
        if(std::find(knownClients.begin(), knownClients.end(), incomingHostIp)
           == knownClients.end()){
            knownClients.push_back(incomingHostIp); //add new host to list
        }
        if(m.getAddress() == "/round"){
            ofxJSONElement thisObj;
            thisObj = ofxJSONElement(m.getArgAsString(0));
            
            //send callback
            ofxOscMessage n;
            n.setAddress("/callback");
            n.addIntArg(1);
            oscSender.sendMessage(n);
            
            display.startRound(thisObj);
        }
        else if(m.getAddress() == "/callback"){
            cout << "GOT CALLBACK, STARTING ROUND";
            waitingCallback = false;
            display.startRound(thisPair[0]);
            dataConnect.sendShowing(thisPair[0]["objectId"].asString(), thisPair[1]["objectId"].asString(), ofToString(CURR_CAT_URL));

        }
    }
    
    if(waitingCallback){
        ofSleepMillis(100);
        sendRound();
    }
}
void testApp::exportRectsAsJson(string name) {
	
	json["type"]="FeatureCollection";

	for(int i=0; i<rects.size(); i++) {
		// { "type"      : "Feature", 
		//   "id"        : 0, 
		//   "properties": { "longitude"  : 37.486007, 
		//                   "latitude"   : 55.677358 }, 
		//   "geometry"  : { "type"       : "Polygon", 
		//                   "coordinates": [ [ [ 37.486007, 55.677358 ], 
		//                                      [ 37.484710, 55.676092 ], 
		//                                      [ 37.482117, 55.676092 ], 
		//                                      [ 37.480821, 55.677358 ], 
		//                                      [ 37.482117, 55.678624 ], 
		//                                      [ 37.484710, 55.678624 ], 
		//                                      [ 37.486007, 55.677358 ] ] ] } }
		json["features"][i]["type"] = "Feature";
		json["features"][i]["id"  ] = i;

		json["features"][i]["properties"]["longitude"] = min_lng+(rects[i].y+rects[i].height/2)/lng_s;
		json["features"][i]["properties"]["latitude" ] = min_lat+(rects[i].x+rects[i].width /2)/lat_s;
		json["features"][i]["properties"]["count"    ] = integrals[i];


		json["features"][i]["geometry"]["type"] = "Polygon";
		json["features"][i]["geometry"]["coordinates"] = ofxJSONElement("[ [ [ "+
			ofToString(min_lng+ rects[i].y                 /lng_s)+ ","+
			ofToString(min_lat+ rects[i].x                 /lat_s)+"],["+
			ofToString(min_lng+ rects[i].y                 /lng_s)+ ","+
			ofToString(min_lat+(rects[i].x+rects[i].width )/lat_s)+"],["+
			ofToString(min_lng+(rects[i].y+rects[i].height)/lng_s)+ ","+
			ofToString(min_lat+(rects[i].x+rects[i].width )/lat_s)+"],["+
			ofToString(min_lng+(rects[i].y+rects[i].height)/lng_s)+ ","+
			ofToString(min_lat+ rects[i].x                 /lat_s)+
			"] ] ]");
	}
	json.save(name+".geojson");

}