From 5185db43b2e48f049690fadcee0081aca634cf4d Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 5 Apr 2023 15:13:33 -0400 Subject: Added infobox after pushpin clicked --- src/client/views/nodes/MapBox/MapBox.tsx | 93 ++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/MapBox/MapBox.tsx b/src/client/views/nodes/MapBox/MapBox.tsx index b01426bcd..cc7d12128 100644 --- a/src/client/views/nodes/MapBox/MapBox.tsx +++ b/src/client/views/nodes/MapBox/MapBox.tsx @@ -606,16 +606,64 @@ export class MapBox extends ViewBoxAnnotatableComponent { + this._bingMap.current.setView({ + center: new this.MicrosoftMaps.Location(this.rootDoc.latitude, this.rootDoc.longitude), + // zoom: location + }); + } + + infobox:any; + + @action + createPushpin = (latitude:number, longitude:number) =>{ + var pin = new this.MicrosoftMaps.Pushpin(new this.MicrosoftMaps.Location(latitude, longitude), { + title: this.bingSearchBarContents, + subTitle: 'subtitle here', + text: '1' + }); + + //Create an infobox at the pin + this.infobox = new this.MicrosoftMaps.Infobox(new this.MicrosoftMaps.Location(latitude, longitude), { + visible: false + }); + + //Assign the infobox to a map instance. + this.infobox.setMap(this._bingMap.current); + //Store some metadata with the pushpin. + pin.metadata = { + title: 'Pin Title', + description: 'Pin discription' + }; + //Add a click event handler to the pushpin. + this.MicrosoftMaps.Events.addHandler(pin, 'click', this.pushpinClicked); + //Add pushpin to the map. + this._bingMap.current.entities.push(pin); + } + + + pushpinClicked = (e: { target: { metadata: { title: any; description: any; }; getLocation: () => any; }; }) => { + //Make sure the infobox has metadata to display. + if (e.target.metadata) { + //Set the infobox options with the metadata of the pushpin. // HOW DO I GET THE CORRECT INFOBOX FOR THIS PIN? CAN I use this e? + this.infobox.setOptions({ + location: e.target.getLocation(), + title: e.target.metadata.title, + description: e.target.metadata.description, + visible: true + }); + } + } + /* * For Bing Maps * Called by search button's onClick @@ -631,17 +679,21 @@ export class MapBox extends ViewBoxAnnotatableComponent console.log(e.key)} + onKeyPress={(e: { key: any; }) => console.log(e.key)} />} {!MapBox.UseBing ? null : -- cgit v1.2.3-70-g09d2