Considering custom Feature Layers by adding notes
The custom Feature Layers can be used to add a custom string to segments.
Using notes as description for other changes
Used in combination with other features, notes can be used as a description for the applied changes.
The following code sample exposes how to add a note to describe other changes to a segment.
var A = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.120200, "y": 49.606628 } } }; var B = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.119985, "y": 49.611071 } } }; var nearPoint = { "x": 6.120951, "y": 49.609041 }; var outputString = ""; var map = new L.Map('map', { center: [nearPoint.y, nearPoint.x], zoom: 16 }); // Add tile layer to map new L.tileLayer.xserver(xServerUrl + '/services/rest/XMap/experimental/tile/{z}/{x}/{y}' + '?layers=background,transport,labels,PTV_TruckAttributes' + '&contentType=JSON', { pane: "overlayPane", maxZoom: 20, }).addTo(map); // Display the point L.circle([nearPoint.y, nearPoint.x], {radius: 3}).addTo(map); //----- Find segment near coordinate ----- function getSegmentToEdit(searchCoord) { var foundSegmentId; xdata.getSegments({ "$type": "SegmentsByCoordinateRequest", "resultFields": { "polyline": true, "descriptors": true }, "coordinate": searchCoord, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(result, exception) { var geoJson = result.segments[0].polyline.geoJSON; displayGeoJson(geoJson, '#481111'); foundSegmentId = result.segments[0].id; }); return foundSegmentId; } function displayGeoJson(geoJson, color) { var jsonObject = JSON.parse(geoJson); var geoJsonLayer = new L.GeoJSON(jsonObject, { style: { color: color, weight: 8 } }).addTo(map); map.fitBounds(geoJsonLayer.getBounds()); }; //----- Create FeatureLayer ----- function createCustomFeatureLayer(segmentIdToEdit) { var createdFeatureLayer; xdata.createFeatureLayer({ "themeId" : "PTV_RoadAttributes", "features" : [ { "segmentIds" : [ segmentIdToEdit ], "descriptions" : [ { "attributes" : [ { "key" : "absoluteSpeed", "value" : 5 }, { "key" : "note", "value" : "walking speed because of roadworks" } ] } ] } ] }, function(result, exception) { createdFeatureLayer = result.binaryFeatureLayer; }); return createdFeatureLayer; }; //----- Route ----- function calculateStandardRoute() { xroute.calculateRoute({ "waypoints": [A, B], "resultFields": { "polyline": true }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(route, exception) { var geoJson = route.polyline.geoJSON; displayGeoJson(geoJson, '#2882C8'); outputString += 'travel time (normal) = ' + route.travelTime + ' s '; print(outputString); }); } function calculateSpecificRoute(binaryFeatureLayer) { xroute.calculateRoute({ "waypoints": [A, B], "routeOptions": { "binaryFeatureLayer": binaryFeatureLayer }, "resultFields": { "polyline": true }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(route, exception) { var geoJson = route.polyline.geoJSON; displayGeoJson(geoJson, '#2882C8'); outputString += 'travel time (using custom feature layer) = ' + route.travelTime + ' s '; print(outputString); }); } calculateStandardRoute(); var segmentIds = getSegmentToEdit(nearPoint); var newBinaryFeatureLayer = createCustomFeatureLayer(segmentIds); calculateSpecificRoute(newBinaryFeatureLayer);When creating the Feature Layer the absolute speed of the segment is set and the note is added. This absolute speed is then considered during the routing, while the note has no influence on the routing though it can be used to give other users an explanation for the applied changes.
Using note without other changes
Notes can also be used without other features to just give some information about a segment or trigger external events.
The following code sample exposes how to add a note to a segment.
var A = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.097304, "y": 49.616625 } } }; var B = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.085438, "y": 49.618328 } } }; var nearPoint = { "x": 6.091092, "y": 49.617585 }; var outputString = ""; var map = new L.Map('map', { center: [nearPoint.y, nearPoint.x], zoom: 16 }); // Add tile layer to map new L.tileLayer.xserver(xServerUrl + '/services/rest/XMap/experimental/tile/{z}/{x}/{y}' + '?layers=background,transport,labels,PTV_TruckAttributes' + '&contentType=JSON', { pane: "overlayPane", maxZoom: 20, }).addTo(map); // Display the point L.circle([nearPoint.y, nearPoint.x], {radius: 3}).addTo(map); //----- Find segment near coordinate ----- function getSegmentToEdit(searchCoord) { var foundSegmentId; xdata.getSegments({ "$type": "SegmentsByCoordinateRequest", "resultFields": { "polyline": true, "descriptors": true }, "coordinate": searchCoord, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(result, exception) { var geoJson = result.segments[0].polyline.geoJSON; displayGeoJson(geoJson, '#481111'); foundSegmentId = result.segments[0].id; }); return foundSegmentId; } function displayGeoJson(geoJson, color) { var jsonObject = JSON.parse(geoJson); var geoJsonLayer = new L.GeoJSON(jsonObject, { style: { color: color, weight: 8 } }).addTo(map); map.fitBounds(geoJsonLayer.getBounds()); }; //----- Create FeatureLayer ----- function createCustomFeatureLayer(segmentIdToEdit) { var createdFeatureLayer; xdata.createFeatureLayer({ "themeId" : "PTV_RoadAttributes", "features" : [ { "segmentIds" : [ segmentIdToEdit ], "descriptions" : [ { "attributes" : [ { "key" : "note", "value" : "damaged road with many potholes" } ] } ] } ] }, function(result, exception) { createdFeatureLayer = result.binaryFeatureLayer; }); return createdFeatureLayer; }; //----- Route ----- function calculateStandardRoute() { xroute.calculateRoute({ "waypoints": [A, B], "resultFields": { "polyline": true }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(route, exception) { var geoJson = route.polyline.geoJSON; displayGeoJson(geoJson, '#2882C8'); outputString += 'travel time (normal) = ' + route.travelTime + ' s '; print(outputString); }); } function calculateSpecificRoute(binaryFeatureLayer) { xroute.calculateRoute({ "waypoints": [A, B], "routeOptions": { "binaryFeatureLayer": binaryFeatureLayer }, "resultFields": { "polyline": true }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(route, exception) { var geoJson = route.polyline.geoJSON; displayGeoJson(geoJson, '#2882C8'); outputString += 'travel time (using custom feature layer) = ' + route.travelTime + ' s '; print(outputString); }); } calculateStandardRoute(); var segmentIds = getSegmentToEdit(nearPoint); var newBinaryFeatureLayer = createCustomFeatureLayer(segmentIds); calculateSpecificRoute(newBinaryFeatureLayer);When creating the Feature Layer the note is added. It has no influence on the routing though it can be used additional information for that segment.