Bing Map : Direction Module directionsUpdated event throws error. We can't find directions between one or more waypoints - bing-maps

Bing Map Direction Manager throwing error on directionsUpdated event.
When I try to draw a rout using known source and destination lat & long with address it doesn't draw route on the map but just show source and destination icon and throw following error.
Error: We can't find directions between one or more waypoints.
Response Code: 1
Below is LoadDirection method code.
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', (e) => {
this.directionsManager = new Microsoft.Maps.Directions.DirectionsManager(this.detailMap);
this.directionsManager.clearAll();
// Set Route Mode to driving
this.directionsManager.setRequestOptions({
routeMode: Microsoft.Maps.Directions.RouteMode.driving,
routeDraggable: false
});
this.directionsManager.setRenderOptions({
drivingPolylineOptions: {
strokeThickness: 3
}
});
this.directionsManager.setRenderOptions({
firstWaypointPushpinOptions: { visible: false },
lastWaypointPushpinOptions: { visible: false },
waypointPushpinOptions: { visible: false }
});
const waypoint1 = new Microsoft.Maps.Directions.Waypoint({
address: '2115 Beall St, Houston, TX 77008, US',
location: new Microsoft.Maps.Location(29.8052803, -95.4181495), icon: ''
});
const waypoint2 = new Microsoft.Maps.Directions.Waypoint({
address: '4231 Brightwood Dr, Houston, TX 77068, US',
location: new Microsoft.Maps.Location(30.00005, -95.50392)
});
this.directionsManager.addWaypoint(waypoint1);
this.directionsManager.addWaypoint(waypoint2);
// Add event handler to directions manager.
Microsoft.Maps.Events.addHandler(this.directionsManager, 'directionsUpdated', function (e) {
console.log(e);
this.detailPathLayer.clear();
const routeIndex = e.route[0].routeLegs[0].originalRouteIndex;
const nextLocation = e.route[0].routePath[routeIndex + 1];
const pinLocation = pin.getLocation();
const nextCoord = this.CalculateNextCoord(pinLocation, nextLocation);
});
Microsoft.Maps.Events.addHandler(this.directionsManager, 'directionsError', function (e) {
console.log('Error: ' + e.message + '\r\nResponse Code: ' + e.responseCode);
});
this.directionsManager.calculateDirections();
});

There shouldn't be any problem finding a route between the two locations you provided. This standalone code below works fine, with directionsUpdated event arg printed in console (Note that you have set waypoint pushpins to invisible through render options):
var map = new Microsoft.Maps.Map(<CREATE_YOUR_MAP>);
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', (e) => {
this.directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
this.directionsManager.clearAll();
// Set Route Mode to driving
this.directionsManager.setRequestOptions({
routeMode: Microsoft.Maps.Directions.RouteMode.driving,
routeDraggable: false
});
this.directionsManager.setRenderOptions({
drivingPolylineOptions: { strokeThickness: 3 },
firstWaypointPushpinOptions: { visible: false },
lastWaypointPushpinOptions: { visible: false },
waypointPushpinOptions: { visible: false }
});
const waypoint1 = new Microsoft.Maps.Directions.Waypoint({
address: '2115 Beall St, Houston, TX 77008, US',
location: new Microsoft.Maps.Location(29.8052803, -95.4181495), icon: ''
});
const waypoint2 = new Microsoft.Maps.Directions.Waypoint({
address: '4231 Brightwood Dr, Houston, TX 77068, US',
location: new Microsoft.Maps.Location(30.00005, -95.50392)
});
this.directionsManager.addWaypoint(waypoint1);
this.directionsManager.addWaypoint(waypoint2);
Microsoft.Maps.Events.addHandler(this.directionsManager, 'directionsUpdated', function (e) {
console.log(e);
});
Microsoft.Maps.Events.addHandler(this.directionsManager, 'directionsError', function (e) {
console.log('Error: ' + e.message + '\r\nResponse Code: ' + e.responseCode);
});
this.directionsManager.calculateDirections();
});
Can you check if the error is indeed thrown between these two locations? Is everything happening in directionsUpdated handler intentional? (e.g. CalculateNextCoord perhaps?)

Related

How to stop cursor flickering over mapbox marker icons?

How do I stop cursor flickering over my Mapbox icons? Here is the live site where you can see the problem when hovering over the marker icons: https://rustic-waters-group.thesparksite.com/lakes/
Here is my code:
mapboxgl.accessToken = 'pk.eyJ1IjoiZG1pdHJpbWFydGluIiwiYSI6ImNreHRobHRmcjVqM3cydmt5NWkxdWNibTcifQ.CuN5Dwc963TW-BKRcowxBA';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/dmitrimartin/ckxtj5aur4fvv15mrhmihala8',
center: [-89.2, 44.33],
zoom: 9.2
});
map.on('load', () => {
const popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});
map.on('mouseenter', 'lakes', (event) => {
map.getCanvas().style.cursor = 'pointer';
const features = map.queryRenderedFeatures(event.point, {
layers: ['lakes']
});
if (event.features.length === 0) return;
popup.setLngLat(features[0].geometry.coordinates);
popup.setHTML('<h3 class="lake-popup">' + features[0].properties.title + '</h3>');
popup.setMaxWidth("calc(100vw - 40px);");
popup.addTo(map);
});
map.on('mouseleave', 'lakes', () => {
map.getCanvas().style.cursor = '';
popup.remove();
});
map.on('click', 'lakes', (event) => {
const features = map.queryRenderedFeatures(event.point, {
layers: ['lakes']
});
if (event.features.length === 0) return;
window.location.href = ('/lakes/' + features[0].properties.url + '/');
});
document.getElementById("lakes-header").onmouseover = function() {
MyMouseOver();
};
function MyMouseOver() {
document.getElementById("wrapper").style.display = "none";
document.getElementById("lakes-header").style.display = "none";
}
});
The issue stems from the popup box on top of the layer and can be fixed by adding the CSS property 'cursor-events: none' to the popup. That should stop the flickering and shouldn't interfere with the layers.

infobox to pushpin via geocode, close all open infoboxs before opening new infobox

ok, here is my code
const members = [
{name: 'Abc Ijk', order: '646545', duration: '1.20h', createdOn: '02/03/2021 09:00 - 10:00', address: '1221 test Avenue Room 112 Portland OR 97204' },
{name: 'Xyz Opq', order: '646546', duration: '3.00h', createdOn: '02/03/2021 08:00 - 11:00', address: '945 nw street 852 Portland OR 97209' }
];
function loadEmpStatus() {
// var navigationBarMode = Microsoft.Maps.NavigationBarMode;
var map = new Microsoft.Maps.Map(document.getElementById('sdy-fserv-map'), {
/* No need to set credentials if already passed in URL */
// navigationBarMode: navigationBarMode.compact,
// supportedMapTypes: [Microsoft.Maps.MapTypeId.road, Microsoft.Maps.MapTypeId.aerial, Microsoft.Maps.MapTypeId.grayscale, Microsoft.Maps.MapTypeId.canvasLight],
supportedMapTypes: [Microsoft.Maps.MapTypeId.road, Microsoft.Maps.MapTypeId.aerial],
center: new Microsoft.Maps.Location(47.624527, -122.355255),
maxZoom: 11,
minZoom: 5
});
for( let row of members ) {
console.log(row);
doGeocode( map, row );
}
}
function doGeocode( map, data ) {
Microsoft.Maps.loadModule('Microsoft.Maps.Search', function () {
var searchManager = new Microsoft.Maps.Search.SearchManager(map);
var requestOptions = {
bounds: map.getBounds(),
where: data.address,
callback: function (answer, userData) {
map.setView({ bounds: answer.results[0].bestView });
var pushpin = new Microsoft.Maps.Pushpin(answer.results[0].location, {
icon: 'https://www.bingmapsportal.com/Content/images/poi_custom.png',
});
// map.entities.push(new Microsoft.Maps.Pushpin(answer.results[0].location));
map.entities.push(pushpin);
var infobox = new Microsoft.Maps.Infobox(answer.results[0].location, {
title: data.name,
description: data.address, visible: false,
actions: [
{ label: 'Handler1', eventHandler: function () { console.log('Handler1'); } },
{ label: 'Handler2', eventHandler: function () { console.log('Handler2'); } },
]
});
infobox.setMap(map);
Microsoft.Maps.Events.addHandler(pushpin, 'click', function () {
infobox.setOptions({ visible: true });
});
map.entities.push(pushpin);/**/
}
};
searchManager.geocode(requestOptions);
});
}
it runs smoothly and I have geocoded pushpins with infoboxes attached and showing up nicely.
But I am failing to figure out how to make all opened infoboxes close before opening new infobox on pushpin click event.
Please help..
I highly recommend creating a single infobox and reusing it as outline in this document: https://learn.microsoft.com/en-us/bingmaps/v8-web-control/map-control-concepts/infoboxes/multiple-pushpins-and-infoboxes

Code migration from tinymce 4 to tinymce 5 - problem with action function (true / false)

I have a problem with migrating the plugin from tinymce 4 to tinymka 5. The console tells me "Uncaught (in promise) TypeError: btn.active is not a function"
I can not find an equivalent for tinymce 5. Can someone replace it?
Code below:
tinymce.PluginManager.add('phonelink', function(editor, url) {
// Add a button that opens a window
var linkText = "";
var linkTitle = "";
var link = "";
// tinymce.DOM.loadCSS(url + '/css/phonelink.css');
editor.ui.registry.addButton('phonelink2', {
text: 'asddas',
icon: 'image-options',
onSetup: updateOnSelect,
onAction: onClickPhoneButton
});
// Adds a menu item to the tools menu
editor.ui.registry.addMenuItem('phonelink', {
text: 'asddas',
icon: 'image-options',
context: 'tools',
onAction: onClickPhoneButton,
onSetup: updateOnSelect
});
function onClickPhoneButton(){
editor.windowManager.open({
title: '123213123',
body: {
type: 'panel',
items: [
{type: 'input', name: 'phone', label: 'Teléfono', value: link},
{type: 'input', name: 'showtext', label: 'Texto a mostrar', value: linkText},
{type: 'input', name: 'title', label: 'Título', value: linkTitle}
]
},
buttons: [
{
text: 'Close',
type: 'cancel',
onclick: 'close'
},
{
type: 'submit',
name: 'submitButton',
text: 'Stwórz',
primary: true
}
],
onAction: function(e) {
alert('Toggle menu item clicked');
},
onSubmit: function(e) {
var data = e.getData();
var hrefLink = '<a title="' + data .title + '" href="tel:+34' + data .phone + '">' + data .showtext + '</a>';
if(link !== ''){
editor.setContent(hrefLink);
}else{
editor.insertContent(hrefLink);
}
e.close();
}
});
}
function updateOnSelect() {
var btn = this;
const editorEventCallback = function (e) {
var node = editor.selection.getNode();
var isTelLink = node.href !== undefined && node.href.indexOf('tel:+') !== -1
btn.active(isTelLink);
if(isTelLink){
link = node.href;
link = link.replace("tel:+34", "");
linkTitle = node.title;
linkText = node.text;
}
};
editor.on('NodeChange', editorEventCallback);
return function (btn) {
editor.off('NodeChange', editorEventCallback);
}
}
});
I searched the documentation for a replacement, but found nothing.
TinyMCE 5 no longer passes the button and menu instance via this. Instead it passes an API instance as the first parameter, so you'll want to change your updateOnSelect function to something like this:
function updateOnSelect(api) {
const editorEventCallback = function (e) {
var node = editor.selection.getNode();
var isTelLink = node.href !== undefined && node.href.indexOf('tel:+') !== -1
api.setActive(isTelLink);
if(isTelLink){
link = node.href;
link = link.replace("tel:+34", "");
linkTitle = node.title;
linkText = node.text;
}
};
editor.on('NodeChange', editorEventCallback);
return function (btn) {
editor.off('NodeChange', editorEventCallback);
}
}
You'll note var btn = this has been removed and that the API to set an item as active is setActive instead of active. This can be found in the documentation here: https://www.tiny.cloud/docs/ui-components/typesoftoolbarbuttons/#togglebutton and https://www.tiny.cloud/docs/ui-components/menuitems/#togglemenuitems (see the API section in both links).
In the above, you may have noticed both reference "Toggle" items. That's another change in TinyMCE 5, as different types of buttons/menu items have a separate registration API. So you'll also need to swap to using editor.ui.registry.addToggleButton and editor.ui.registry.addToggleMenuItem. More details about that can be found here if needed: https://www.tiny.cloud/docs/migration-from-4x/#customtoolbarbuttons
Here's an example fiddle showing the changes mentioned above: https://fiddle.tiny.cloud/B5haab.
Hopefully that helps!

Bug in Bing Map API SDK Direction Module

In application I have Bing Maps API (Release Branch). Today suddenly I saw something wrong with direction module. I have set below mentioned direction modules option which were working earlier but not now. In below code I am trying to hide route and waypoints. It works for waypoints but not for route.
So I tried bing map SDK online example where I try to set routeDraggable : false but in the SDK example is not working.
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', () => {
that.directionsManager = new Microsoft.Maps.Directions.DirectionsManager(that.map);
// Set Route Mode to driving
that.directionsManager.setRequestOptions({
routeMode: Microsoft.Maps.Directions.RouteMode.driving,
routeDraggable: false
});
that.directionsManager.setRenderOptions({
drivingPolylineOptions: {
strokeColor: 'green',
strokeThickness: 3,
visible: false
},
waypointPushpinOptions: { visible: false },
viapointPushpinOptions: { visible: false },
autoUpdateMapView: false
});
const waypoint1 = new Microsoft.Maps.Directions.Waypoint({
location: new Microsoft.Maps.Location(startLoc.latitude, startLoc.longitude), icon: ''
});
const waypoint2 = new Microsoft.Maps.Directions.Waypoint({
location: new Microsoft.Maps.Location(endLoc.latitude, endLoc.longitude)
});
this.directionsManager.addWaypoint(waypoint1);
this.directionsManager.addWaypoint(waypoint2);
// Add event handler to directions manager.
Microsoft.Maps.Events.addHandler(this.directionsManager, 'directionsUpdated', function (e) {
// const that = this;
console.log(e);
var routeIndex = e.route[0].routeLegs[0].originalRouteIndex;
var nextIndex = routeIndex;
if (e.route[0].routePath.length > routeIndex) {
nextIndex = routeIndex + 1;
}
var nextLocation = e.route[0].routePath[nextIndex];
var pin = that.map.entities.get(index);
// var bearing = that.calculateBearing(startLoc,nextLocation);
that.MovePinOnDirection(that, e.route[0].routePath, pin, truckUrl, truckIdRanId);
});
this.directionsManager.calculateDirections();
});
https://www.bing.com/api/maps/sdk/mapcontrol/isdk/directionsgetrequestoptions
#rbrundritt Can you help me in this issue ?

Leafletjs: How to have new marker in first click then update the latlng of marker in second click

I have list of markers that want to render in the map, but I want it one by one. In first click I want to make new marker. Then when I click to another location, I want my marker to just move to the new latLng not to create another marker. Here is my code:
function (licon, coord, data) {
var self = jQuery(this);
var map = self.data("map");
var latlng = new L.LatLng(coord[0], coord[1]);
//Create Marker
if (licon) {
var leafIcon = L.icon(licon);
console.log(typeof (marker));
if (typeof (marker) === 'undefined') {
var marker = L.marker(latlng, {
icon: leafIcon,
"markerData": data,
draggable: true
});
} else {
console.log('not undefined');
map.removeLayer(marker);
marker = L.marker(latlng, {
icon: leafIcon,
"markerData": data,
draggable: true
});
}
} else {
var marker = L.marker(latlng, {
"markerData": data,
draggable: true
});
}
marker.addTo(map);
return marker;
}
A quick example of the result: http://jsfiddle.net/ve2huzxw/43/
var currentMarker;
map.on("click", function (event) {
if (currentMarker) {
currentMarker.setLatLng(event.latlng);
return;
}
currentMarker = L.marker(event.latlng, {
draggable: true
}).addTo(map).on("click", function () {
event.originalEvent.stopPropagation();
});
});
document.getElementById("done").addEventListener("click", function () {
currentMarker = null;
});
You can also add a smooth transition to show the marker moving to the new position:
if (currentMarker) {
currentMarker._icon.style.transition = "transform 0.3s ease-out";
currentMarker._shadow.style.transition = "transform 0.3s ease-out";
currentMarker.setLatLng(event.latlng);
setTimeout(function () {
currentMarker._icon.style.transition = null;
currentMarker._shadow.style.transition = null;
}, 300);
return;
}
a slightly more consolidated solution some years later.
var currentMarker;
map2.on('click', function(e) {
if (currentMarker){
currentMarker.setLatLng(e.latlng)
} else {
currentMarker = new L.marker(e.latlng).addTo(map2);
};
//console.log('lat, lon: ', e.latlng.lat, e.latlng.lng);
});
leaflet now defaults to smoothly dragging the point over to the new coords.