如何总是在右侧制作反应传单标记弹出窗口?

发布于 2025-02-11 07:35:02 字数 1074 浏览 3 评论 0原文

我想在地图屏幕右侧显示一个反应传单标记弹出窗口,但它总是粘在屏幕的左侧。因此,我将感谢您完成此操作的任何帮助。以下是弹出窗口当前状态的屏幕截图。

这是我尝试过的我的CSS。

.leaflet-popup {
  transform: none !important;
  position: absolute !important;
  top: 1px !important;
  bottom: 0px !important;
  right: 0% !important;
  display: flex !important;
  align-items: right !important;
  justify-items: right !important;
}

.leaflet-container .leaflet-popup-content-wrapper .popup_modle {
  z-index: 1000;
  position: absolute;
  right: 0 !important;
  height: 400px;
  width: 300px;
  top: -1px;
  background-color: rgba(5, 5, 5, 0.7) !important;
  background: linear-gradient(
    60deg,
    rgba(134, 134, 134, 0.7) 0%,
    rgba(0, 0, 0, 0.7) 59%
  ) !important;
  align-items: right !important;
  justify-items: right !important;
  justify-content: right !important;
  -webkit-border-radius: 0 !important;
  -moz-border-radius: 0 !important;
}

谢谢

I want to show a React Leaflet Marker popup on the right side of the map screen, but it always sticks to the left side of the screen. Therefore, I would appreciate any help in getting this done. Below is a screenshot of the current state of the popup. enter image description here

this is my CSS that i tried.

.leaflet-popup {
  transform: none !important;
  position: absolute !important;
  top: 1px !important;
  bottom: 0px !important;
  right: 0% !important;
  display: flex !important;
  align-items: right !important;
  justify-items: right !important;
}

.leaflet-container .leaflet-popup-content-wrapper .popup_modle {
  z-index: 1000;
  position: absolute;
  right: 0 !important;
  height: 400px;
  width: 300px;
  top: -1px;
  background-color: rgba(5, 5, 5, 0.7) !important;
  background: linear-gradient(
    60deg,
    rgba(134, 134, 134, 0.7) 0%,
    rgba(0, 0, 0, 0.7) 59%
  ) !important;
  align-items: right !important;
  justify-items: right !important;
  justify-content: right !important;
  -webkit-border-radius: 0 !important;
  -moz-border-radius: 0 !important;
}

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昇り龍 2025-02-18 07:35:02

如果此CSS没有反映您的代码。我建议您将其移至全局CSS文件。为了确保您覆盖反应叶样式。我刚刚更新了 .leaflet-popup 类。而不是右:0%我使用右:0!

.leaflet-popup {
      transform: none !important;
      position: absolute !important;
      top: 1px !important;
      bottom: 0px !important;
      right: 0% !important;
      display: flex !important;
      align-items: right !important;
      justify-items: right !important;
    }
    
    .leaflet-container .leaflet-popup-content-wrapper .popup_modle {
      z-index: 1000;
      position: absolute;
      right: 0 !important;
      height: 400px;
      width: 300px;
      top: -1px;
      background-color: rgba(5, 5, 5, 0.7) !important;
      background: linear-gradient(
        60deg,
        rgba(134, 134, 134, 0.7) 0%,
        rgba(0, 0, 0, 0.7) 59%
      ) !important;
      align-items: right !important;
      justify-items: right !important;
      justify-content: right !important;
      -webkit-border-radius: 0 !important;
      -moz-border-radius: 0 !important;
    }

If this CSS didn't reflect your code. I would recommend for you move it to a global CSS file. to make sure that you override the react-leaflet style. I just updated the .leaflet-popup class. instead of right:0% I used right:0 !important

.leaflet-popup {
      transform: none !important;
      position: absolute !important;
      top: 1px !important;
      bottom: 0px !important;
      right: 0% !important;
      display: flex !important;
      align-items: right !important;
      justify-items: right !important;
    }
    
    .leaflet-container .leaflet-popup-content-wrapper .popup_modle {
      z-index: 1000;
      position: absolute;
      right: 0 !important;
      height: 400px;
      width: 300px;
      top: -1px;
      background-color: rgba(5, 5, 5, 0.7) !important;
      background: linear-gradient(
        60deg,
        rgba(134, 134, 134, 0.7) 0%,
        rgba(0, 0, 0, 0.7) 59%
      ) !important;
      align-items: right !important;
      justify-items: right !important;
      justify-content: right !important;
      -webkit-border-radius: 0 !important;
      -moz-border-radius: 0 !important;
    }
陌路终见情 2025-02-18 07:35:02

最重要的是,该标记我还添加了一个模型来显示数据。

并且该模型像这样将地图排名第一,因此您可以编写自己的弹出窗口。

const [open, setOpen] = React.useState(false);
const [data, setData] = React.useState();

 const handleClose = () => {
    setOpen(false);
  };

  const handleOpen = (datas) => {
    setOpen(true);
    setData(datas);
  };

<div className="map_data w-full">
      <Modal
        open={open}
        onClose={handleClose}
        className="modal_container"
        BackdropProps={{
          timeout: 0,
          invisible: true,
        }}
      >
        <div className="popup_modle pl-3 ">
          <button
            onClick={handleClose}
            className="text-md absolute  right-3   text-lightDarkGreen  font-bold top-3"
            id="myModal"
          >
            X <button />
          </button>
          <div className="relative top-10">
            <div className="pb-4 ">
              <p className="text-white text-sm opacity-80">Name</p>
              <p className="text-white font-bold text-4xl relative top-2">
                {date?.name}
              </p>
            </div>
            <div className="border-t border-deepDark relative pt-4 ">
              <p className="text-white text-2xl relative  opacity-80">
                Geographic index
              </p>
              <p className="text-white text-lg font-bold relative top-5 ">
                {date?.location?.country_name}, {"  "}
                {date?.location?.city}
              </p>
            </div>
          </div>
          <br />
        </div>
      </Modal>
      <Map
        ref={mapRefs}
        center={center}
        zoom={2}
        onPopupopen={centerMapView}
        maxZoom={19}
        position={center}
        bounceAtZoomLimits={true}
        maxBoundsViscosity={0.95}
        scrollWheelZoom={false}
        zoomAnimation={true}
        maxBounds={[
          [-180, -90],
          [180, 90],
        ]}
        zoomSnap={0.5}
        style={{ width: "100%", height: "400px" }} //zIndex: -10
      >
        <TileLayer
          url={`https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}{r}.png?api_key=${process.env.REACT_APP_STADIA_API_KEY}`}
          attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        />
        {data.length > 0 && (
          <FeatureGroup ref={groupRef}>
            {data?.map((location, i) => (
              <>
 

                <Circle
                  center={[
                    parseFloat(location?.location?.lat_lon?.lat),

                    parseFloat(location?.location?.lat_lon?.lon),
                  ]}
                  fillOpacity={0.6}
                  color={"#32E8C3"}
                  fillColor={"#32E8C3"}
                  radius={355 * 2000}
                  eventHandlers={{ click: () => handleOpen(location) }}
                ></Circle>
              </>
            ))}
          </FeatureGroup>
        )}
      </Map>

和CSS

.popup_modle {
  position: absolute;
  right: 0 !important;
  top: 65px !important;
  height: 400px;
  width: 300px;
  background-color: rgba(5, 5, 5, 0.7) !important;
  background: linear-gradient(
    60deg,
    rgba(134, 134, 134, 0.7) 0%,
    rgba(0, 0, 0, 0.7) 59%
  ) !important;
}

On top that that marker I have added a model to show data.

and the model goes top of the map like this so you can write your own popup.

const [open, setOpen] = React.useState(false);
const [data, setData] = React.useState();

 const handleClose = () => {
    setOpen(false);
  };

  const handleOpen = (datas) => {
    setOpen(true);
    setData(datas);
  };

<div className="map_data w-full">
      <Modal
        open={open}
        onClose={handleClose}
        className="modal_container"
        BackdropProps={{
          timeout: 0,
          invisible: true,
        }}
      >
        <div className="popup_modle pl-3 ">
          <button
            onClick={handleClose}
            className="text-md absolute  right-3   text-lightDarkGreen  font-bold top-3"
            id="myModal"
          >
            X <button />
          </button>
          <div className="relative top-10">
            <div className="pb-4 ">
              <p className="text-white text-sm opacity-80">Name</p>
              <p className="text-white font-bold text-4xl relative top-2">
                {date?.name}
              </p>
            </div>
            <div className="border-t border-deepDark relative pt-4 ">
              <p className="text-white text-2xl relative  opacity-80">
                Geographic index
              </p>
              <p className="text-white text-lg font-bold relative top-5 ">
                {date?.location?.country_name}, {"  "}
                {date?.location?.city}
              </p>
            </div>
          </div>
          <br />
        </div>
      </Modal>
      <Map
        ref={mapRefs}
        center={center}
        zoom={2}
        onPopupopen={centerMapView}
        maxZoom={19}
        position={center}
        bounceAtZoomLimits={true}
        maxBoundsViscosity={0.95}
        scrollWheelZoom={false}
        zoomAnimation={true}
        maxBounds={[
          [-180, -90],
          [180, 90],
        ]}
        zoomSnap={0.5}
        style={{ width: "100%", height: "400px" }} //zIndex: -10
      >
        <TileLayer
          url={`https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}{r}.png?api_key=${process.env.REACT_APP_STADIA_API_KEY}`}
          attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        />
        {data.length > 0 && (
          <FeatureGroup ref={groupRef}>
            {data?.map((location, i) => (
              <>
 

                <Circle
                  center={[
                    parseFloat(location?.location?.lat_lon?.lat),

                    parseFloat(location?.location?.lat_lon?.lon),
                  ]}
                  fillOpacity={0.6}
                  color={"#32E8C3"}
                  fillColor={"#32E8C3"}
                  radius={355 * 2000}
                  eventHandlers={{ click: () => handleOpen(location) }}
                ></Circle>
              </>
            ))}
          </FeatureGroup>
        )}
      </Map>

and css

.popup_modle {
  position: absolute;
  right: 0 !important;
  top: 65px !important;
  height: 400px;
  width: 300px;
  background-color: rgba(5, 5, 5, 0.7) !important;
  background: linear-gradient(
    60deg,
    rgba(134, 134, 134, 0.7) 0%,
    rgba(0, 0, 0, 0.7) 59%
  ) !important;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文