refactoring: used hasSource, hasTarget routines throughout the code
This commit is contained in:
		
							parent
							
								
									a39a35df73
								
							
						
					
					
						commit
						f9877fd8ba
					
				@ -228,4 +228,4 @@ hasTarget: function() {
 | 
			
		||||
		return true;
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
});
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -37,9 +37,9 @@ function updateLocation(marker_id) {
 | 
			
		||||
 | 
			
		||||
// process input request and call geocoder if needed
 | 
			
		||||
function callGeocoder(marker_id, query) {
 | 
			
		||||
	if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0].dirty_move == false && my_markers.route[0].dirty_type == false)
 | 
			
		||||
	if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource() && my_markers.route[0].dirty_move == false && my_markers.route[0].dirty_type == false)
 | 
			
		||||
		return;
 | 
			
		||||
	if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL && my_markers.route[my_markers.route.length-1].dirty_move == false && my_markers.route[my_markers.route.length-1].dirty_type == false)
 | 
			
		||||
	if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget() && my_markers.route[my_markers.route.length-1].dirty_move == false && my_markers.route[my_markers.route.length-1].dirty_type == false)
 | 
			
		||||
		return;
 | 
			
		||||
	if(query=="")
 | 
			
		||||
		return;
 | 
			
		||||
@ -143,10 +143,10 @@ OSRM.REVERSE_GEOCODE_POST = 'http://nominatim.openstreetmap.org/reverse?format=j
 | 
			
		||||
 | 
			
		||||
//update reverse geocoder informatiopn in input boxes
 | 
			
		||||
function updateReverseGeocoder(marker_id) {
 | 
			
		||||
	if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource()==true) { //&& my_markers.route[0].dirty == true ) {
 | 
			
		||||
	if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource()) { //&& my_markers.route[0].dirty == true ) {
 | 
			
		||||
		//document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6);
 | 
			
		||||
		callReverseGeocoder("source", my_markers.route[0].getPosition().lat, my_markers.route[0].getPosition().lng);
 | 
			
		||||
	} else if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget()==true) { //&& my_markers.route[my_markers.route.length-1].dirty == true) {
 | 
			
		||||
	} else if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget()) { //&& my_markers.route[my_markers.route.length-1].dirty == true) {
 | 
			
		||||
		//document.getElementById("input-target-name").value = my_markers.route[my_markers.route.length-1].getPosition().lat.toFixed(6) + ", " + my_markers.route[my_markers.route.length-1].getPosition().lng.toFixed(6);
 | 
			
		||||
		callReverseGeocoder("target", my_markers.route[my_markers.route.length-1].getPosition().lat, my_markers.route[my_markers.route.length-1].getPosition().lng);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -88,13 +88,13 @@ or see http://www.gnu.org/licenses/agpl.txt.
 | 
			
		||||
    <table class="full">
 | 
			
		||||
    <tr>
 | 
			
		||||
    <td id="gui-search-source-label">Start:</td>
 | 
			
		||||
    <td><input id="input-source-name" class="input-box" type="text" maxlength="200" value="" title="Startposition eingeben" onchange="if( my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) my_markers.route[0].dirty_type = true;" onblur="callGeocoder(OSRM.SOURCE_MARKER_LABEL, document.getElementById('input-source-name').value);" onkeypress="if(event.keyCode==13) {callGeocoder(OSRM.SOURCE_MARKER_LABEL, document.getElementById('input-source-name').value);}" /></td>
 | 
			
		||||
    <td><input id="input-source-name" class="input-box" type="text" maxlength="200" value="" title="Startposition eingeben" onchange="if( my_markers.hasSource() ) my_markers.route[0].dirty_type = true;" onblur="callGeocoder(OSRM.SOURCE_MARKER_LABEL, document.getElementById('input-source-name').value);" onkeypress="if(event.keyCode==13) {callGeocoder(OSRM.SOURCE_MARKER_LABEL, document.getElementById('input-source-name').value);}" /></td>
 | 
			
		||||
    <td class="right"><a class="button not-selectable" id="gui-search-source" onclick="centerMarker('source')">Zeigen</a></td>
 | 
			
		||||
    </tr>
 | 
			
		||||
    
 | 
			
		||||
    <tr>
 | 
			
		||||
    <td id="gui-search-target-label">Ende:</td>
 | 
			
		||||
    <td><input id="input-target-name" class="input-box" type="text" maxlength="200" value="" title="Zielposition eingeben" onchange="if( my_markers.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL) my_markers.route[my_markers.route.length-1].dirty_type = true;" onblur="callGeocoder(OSRM.TARGET_MARKER_LABEL, document.getElementById('input-target-name').value);" onkeypress="if(event.keyCode==13) {callGeocoder(OSRM.TARGET_MARKER_LABEL, document.getElementById('input-target-name').value);}" /></td>
 | 
			
		||||
    <td><input id="input-target-name" class="input-box" type="text" maxlength="200" value="" title="Zielposition eingeben" onchange="if( my_markers.route.hasTarget() ) my_markers.route[my_markers.route.length-1].dirty_type = true;" onblur="callGeocoder(OSRM.TARGET_MARKER_LABEL, document.getElementById('input-target-name').value);" onkeypress="if(event.keyCode==13) {callGeocoder(OSRM.TARGET_MARKER_LABEL, document.getElementById('input-target-name').value);}" /></td>
 | 
			
		||||
	<td class="right"><a class="button not-selectable" id="gui-search-target" onclick="centerMarker('target');">Zeigen</a></td>	
 | 
			
		||||
    </tr>
 | 
			
		||||
    </table>
 | 
			
		||||
 | 
			
		||||
@ -156,12 +156,10 @@ function initMap() {
 | 
			
		||||
 | 
			
		||||
	// click on map to set source and target nodes
 | 
			
		||||
	map.on('click', function(e) {
 | 
			
		||||
		if( !my_markers.route[0] || my_markers.route[0].label != OSRM.SOURCE_MARKER_LABEL) {
 | 
			
		||||
		if( !my_markers.hasSource() )
 | 
			
		||||
			onclickGeocoderResult("source", e.latlng.lat, e.latlng.lng, true, false );
 | 
			
		||||
		}
 | 
			
		||||
		else if( !my_markers.route[my_markers.route.length-1] || my_markers.route[ my_markers.route.length-1 ].label != OSRM.TARGET_MARKER_LABEL) {
 | 
			
		||||
		else if( !my_markers.hasTarget() )
 | 
			
		||||
			onclickGeocoderResult("target", e.latlng.lat, e.latlng.lng, true, false );
 | 
			
		||||
		}		
 | 
			
		||||
	} );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -379,9 +379,9 @@ function snapRoute() {
 | 
			
		||||
// 	updateLocation( "source" );
 | 
			
		||||
// 	updateLocation( "target" );
 | 
			
		||||
	
 | 
			
		||||
	//if(OSRM.dragid == 0 && my_markers.hasSource()==true)
 | 
			
		||||
	//if(OSRM.dragid == 0 && my_markers.hasSource())
 | 
			
		||||
		updateReverseGeocoder("source");
 | 
			
		||||
	//else if(OSRM.dragid == my_markers.route.length-1 && my_markers.hasTarget()==true)
 | 
			
		||||
	//else if(OSRM.dragid == my_markers.route.length-1 && my_markers.hasTarget())
 | 
			
		||||
		updateReverseGeocoder("target"); 	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -473,9 +473,9 @@ function reverseRouting() {
 | 
			
		||||
 | 
			
		||||
// click: button "show"
 | 
			
		||||
function centerMarker(marker_id) {
 | 
			
		||||
	if( marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL && !my_markers.route[0].dirty_type ) {
 | 
			
		||||
	if( marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource() && !my_markers.route[0].dirty_type ) {
 | 
			
		||||
		my_markers.route[0].centerView();
 | 
			
		||||
	} else if( marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL && !my_markers.route[my_markers.route.length-1].dirty_type) {
 | 
			
		||||
	} else if( marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget() && !my_markers.route[my_markers.route.length-1].dirty_type) {
 | 
			
		||||
		my_markers.route[my_markers.route.length-1].centerView();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user