Skip to content

Commit

Permalink
Update PoiLocator
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverheilig committed Apr 2, 2024
1 parent 0cfc98c commit 7ca5d50
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 81 deletions.
6 changes: 3 additions & 3 deletions boilerplate/cesium.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<title>Example page for xMap2 @Cesium</title>

<!-- For debugging client-side code, use the "Unminified" Cesium-Unminified.js. -->
<script src="https://cdn.jsdelivr.net/npm/cesium@1.113.0/Build/Cesium/Cesium.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.116.0/Build/Cesium/Cesium.js"></script>
<script src="../token.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.113.0/Build/Cesium/Widgets/widgets.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.116.0/Build/Cesium/Widgets/widgets.css" />
<style>
body,
#viewerContainer {
Expand Down Expand Up @@ -92,7 +92,7 @@

viewer.scene.fog.enabled = false;
viewer.baseLayerPicker.viewModel.selectedImagery = imageryViewModels[3];

function terrainChanged(element) {
var idx = element.checked ? 1 : 0;
viewer.baseLayerPicker.viewModel.selectedTerrain = viewer.baseLayerPicker.viewModel.terrainProviderViewModels[
Expand Down
6 changes: 3 additions & 3 deletions premium-samples/admin-regions/admin-3d-choropleth.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<!-- This single-page Cesium application demonstrates the ability to request CZML from the server. -->
<title>Example page for xMap2 @Cesium</title>

<script src="https://cdn.jsdelivr.net/npm/cesium@1.113.0/Build/Cesium/Cesium.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.116.0/Build/Cesium/Cesium.js"></script>
<script src="../../token.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.113.0/Build/Cesium/Widgets/widgets.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.116.0/Build/Cesium/Widgets/widgets.css" />
<style>
body,
#viewerContainer {
Expand Down Expand Up @@ -115,7 +115,7 @@

entity.polygon.shadows = Cesium.ShadowMode.ENABLED;

//Extrude the polygon based on the state's population density.
//Extrude the polygon based on the state's population density.
entity.polygon.extrudedHeight = entity.properties.popdens * 10;
}
});
Expand Down
6 changes: 3 additions & 3 deletions premium-samples/admin-regions/admin-regions-cesium-webgl.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

<!-- This single-page Cesium application demonstrates the ability to request CZML from the server. -->
<title>Example page for xMap2 @Cesium</title>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.113.0/Build/Cesium/Cesium.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.116.0/Build/Cesium/Cesium.js"></script>

<script src="../../token.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.113.0/Build/Cesium/Widgets/widgets.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.116.0/Build/Cesium/Widgets/widgets.css" />
<style>
body,
#viewerContainer {
Expand Down Expand Up @@ -87,7 +87,7 @@
fill: Cesium.Color.WHITE.withAlpha(0.6),
strokeWidth: 3
}));

//Set the camera to a US centered tilted view and switch back to moving in world coordinates.
viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(6.130833, 49.611389), new Cesium.Cartesian3(0.0, -479000.0, 393000.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
Expand Down
22 changes: 1 addition & 21 deletions premium-samples/poi-locator/helper.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
// convert a wkt linestring to a closed geoson polygon
function isoToPoly(wkt) {
x = replaceAll('LINESTRING', '', wkt);
x = x.trim();
x = replaceAll(', ', '],[', x);
x = replaceAll(' ', ',', x);
x = replaceAll('(', '[', x);
x = replaceAll(')', ']', x);
x = '[[' + x + ']]';
return JSON.parse(x);
}

function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
}

function replaceAll(find, replace, str) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}

// runRequest executes a json request on PTV xServer internet,
// given the url endpoint, the token and the callback to be called
// upon completion.
// upon completion.
function runRequest(url, request, token, handleSuccess) {
var r = d3.request(url)
.header('Content-Type', 'application/json')
Expand Down
8 changes: 4 additions & 4 deletions premium-samples/poi-locator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@
</div>
<div style="padding-top:6px">Search method</div>
<div class="pure-g">
<div class="pure-u-1-3"><input type="radio" name="searchmethod" checked="true" onclick="setSearchMethod(0);">airline</div>
<div class="pure-u-1-3"><input type="radio" name="searchmethod" onclick="setSearchMethod(1);">1:n routing</div>
<div class="pure-u-1-3"><input type="radio" name="searchmethod" onclick="setSearchMethod(0);">airline</div>
<div class="pure-u-1-3"><input type="radio" name="searchmethod" checked="true" onclick="setSearchMethod(1);">1:n routing</div>
<div class="pure-u-1-3"><input type="radio" name="searchmethod" onclick="setSearchMethod(2);">isochrone</div>
</div>
<div style="padding-top:6px">Horizon</div>
<div class="pure-g">
<div class="pure-u-1-3"><input type="radio" name="horizon" checked="true" onclick="setHorizon(900);">15 min</div>
<div class="pure-u-1-3"><input type="radio" name="horizon" onclick="setHorizon(1800);">30 min</div>
<div class="pure-u-1-3"><input type="radio" name="horizon" onclick="setHorizon(900);">15 min</div>
<div class="pure-u-1-3"><input type="radio" name="horizon" checked="true" onclick="setHorizon(1800);">30 min</div>
<div class="pure-u-1-3"><input type="radio" name="horizon" onclick="setHorizon(3600);">60 min</div>
</div>
<div style="padding-top:6px">Or find stores by name</div>
Expand Down
70 changes: 23 additions & 47 deletions premium-samples/poi-locator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// url we're sending the request to
var xMapTileUrl = 'https://s0{s}-xserver2-test.cloud.ptvgroup.com/services/rest/XMap/tile/{z}/{x}/{y}?storedProfile={profile}&xtok={token}';
var findAddressUrl = 'https://xserver2-test.cloud.ptvgroup.com/services/rest/XLocate/locations';
var calcIsoUrl = 'https://api-test.cloud.ptvgroup.com/xroute/rs/XRoute/calculateIsochrones';
var calcIsoUrl = 'https://xserver2-europe-test.cloud.ptvgroup.com/services/rs/XRoute/experimental/calculateReachableAreas';
var calcReachableObjectsUrl = 'https://api-test.cloud.ptvgroup.com/xroute/rs/XRoute/calculateReachableObjects';

var searchLocation;
Expand All @@ -11,8 +11,8 @@ var highlightedPois = [];
var isBusy = false;
var marker;
var circle;
var horizon = 900;
var searchMethod = 0;
var horizon = 1800;
var searchMethod = 2;
var index;
var poiData;
var csvRows;
Expand Down Expand Up @@ -364,43 +364,15 @@ map.on('locationerror', function (e) {
setBusy(false);
});

// This is implemtantion is based on xroute2 calculateReachableAreas
function findByIso(latlng, hor) {
setBusy(true);

var request = {
'sink': {
'coords': [{
'point': {
'x': latlng.lng,
'y': latlng.lat
}
}],
'linkType': 'NEXT_SEGMENT'
},
'options': [],
'isoOptions': {
'isoDetail': 'POLYS_ONLY',
'polygonCalculationMode': 'NODE_BASED',
'expansionDesc': {
'expansionType': 'EXP_TIME',
'horizons': [
hor
]
}
},
'callerContext': {
'properties': [{
'key': 'CoordFormat',
'value': 'OG_GEODECIMAL'
}, {
'key': 'ResponseGeometry',
'value': 'WKT'
}, {
'key': 'Profile',
'value': 'carfast'
}]
}
};
var request = {
"storedProfile": "car.xml",
"waypoint":{"$type":"OffRoadWaypoint","location":{"offRoadCoordinate":{"x":latlng.lng,"y":latlng.lat}}},
"reachableAreasOptions":{"horizons":[{"$type":"TravelTimeBasedHorizon","travelTime":hor}],"calculationMode":"PERFORMANCE"},
"geometryOptions":{"responseGeometryTypes":["GEOJSON"]}};

runRequest(
calcIsoUrl,
Expand All @@ -416,7 +388,15 @@ function findByIso(latlng, hor) {
}

response = JSON.parse(response.responseText);
var x = isoToPoly(response.isochrones[0].polys.wkt);

var multiPoly = {
"type": "MultiPolygon",
"coordinates": []
};

for(var i = 0; i < response.polygons.length; i++) {
multiPoly.coordinates.push(JSON.parse(response.polygons[i].geoJSON).coordinates);
}

var feature = {
'type': 'Feature',
Expand All @@ -428,15 +408,11 @@ function findByIso(latlng, hor) {
fillColor: '#fff',
fillOpacity: 0.5
}
}
};

feature.geometry = {
type: 'Polygon',
coordinates: x
},
geometry: multiPoly
};

isoFeature = L.geoJson([feature], {
isoFeature = L.geoJson(feature, {
style: function (feature) {
return feature.properties && feature.properties.style;
}
Expand All @@ -463,7 +439,7 @@ function findByIso(latlng, hor) {
);
}

var kmh = 120;
var kmh = 80;
var ms = kmh / 3.6;
function filterByAirline(latlng, hor) {
var range = hor * ms;
Expand Down Expand Up @@ -594,7 +570,7 @@ function setBounds(features, center) {

if (coords.length) {
map.fitBounds(new L.LatLngBounds(coords), {maxZoom: 16});
}
}
}

function cleanupMarkers(cleanupCirlcle) {
Expand Down

0 comments on commit 7ca5d50

Please sign in to comment.