微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在nextjs中的标记信息窗口内使用链接组件

如何解决如何在nextjs中的标记信息窗口内使用链接组件

嗨,我正在我的nextjs应用中实现google map 这是我的map.js组件文件

import { AsYouType } from 'libphonenumber-js'
import { useState } from 'react';
import {get_location_slug} from '../utility/calculate_distance'

const phoneFormat = new AsYouType('US')
const Marker = (props,location) => `
  <div class="max-w-sm rounded overflow-hidden shadow-lg">
    <div class="px-2">
      <div class="font-bold text-base mb-2 text-blue-500">
        <a href=${"/data/"+location}>
          ${props.city}
        </a>
      </div>
      <p class="text-dark-400 text-sm">${props.street}</p>
      <p class="text-dark-400 text-sm mb-2">
        ${props.city},${props.stateIso},${props.countryIso},${props.postalCode}
      </p>
      <p class="text-gray-700 font-medium mb-2">
        Phone: <span class="font-light">${phoneFormat.input(props.phone)}</span>
      </p>
      <p>
        <a class="text-blue-500" href="https://www.google.com/maps/dir/'+${props.defaultLat}+','+${props.defaultLng}+'/'+${props.latitude}+','+${props.longitude}+'">
        Directions
        </a>
      </p>
    </div>
  </div>
`

export default function Map(props) {
  const [locations,setLocations ] = useState(props.locations)
  const defaultProps = {
    center: {
    lat: (typeof(props.latitude) === "undefined" ? 12.22 : props.latitude),lng: (typeof(props.longitude) === "undefined" ? -90.22 : props.longitude),},zoom: 7
  }
  const latitude = (typeof(props.latitude) === "undefined" ? 12.22 : props.latitude)
  const longitude = (typeof(props.longitude) === "undefined" ?  -90.22: props.longitude)
  function handleApiLoaded(map,lat,lng){
    let infowindow = new google.maps.InfoWindow()
    let markerCenter = 0
    props.locations.map((location) => {
     let location_slug = get_location_slug(location)
      markerCenter == 0 && map.setCenter(new google.maps.LatLng(location.latitude,location.longitude))
      markerCenter = 1
      let marker = new google.maps.Marker({position: {lat: parseFloat(location.latitude),lng: parseFloat(location.longitude)},map: map,title: location.name})
      marker.setIcon('http://maps.google.com/mapfiles/ms/icons/red-dot.png')
      marker.addListener('click',function() {
        infowindow.close()
        infowindow.setContent(Marker(location,location_slug))
        infowindow.open(map,marker)
      })
    })
  }

  return (
    <div style={{ height: '100%',width: '100%' }}>
      <GoogleMapReact
        bootstrapURLKeys={{ key: `${process.env.GOOGLE_API_KEY}` }}
        defaultCenter={defaultProps.center}
        defaultZoom={defaultProps.zoom}
        yesIWantToUseGoogleMapApiInternals
        onGoogleApiLoaded={({ map }) => handleApiLoaded(map,latitude,longitude)}
        key={props.locations,longitude}
        />
    </div>
  )
}

如您所见,当前我在const标记中使用 a 标记

<a href=${"/data/"+location}>
          ${props.city}
 </a>

对于正在重新加载页面的地图信息窗口,但我想使用 Link 标记,以便它不会重新加载。在我的整个应用程序中,我正在使用 Link 标记,这样它就不会重新加载页面,但是仅对于此标记信息窗口,我无法执行此操作。 我该怎么办?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?