React/leaflet에서 GMT로 만든 지도 이미지 붙여넣기

7754 단어 GMTleafletReact

React 프로젝트 만들기


$ npx create-react-app sample-app
$ cd sample-app
$ npm install leaflet
$ npm start

지도 이미지 만들기



leaflet 기본 projection는 EPSG:3857.
$ gmt pscoast -JEPSG:3857 -R-180/180/-80/80 -G0/255/0 -S0/0/255 > tmp.eps
$ gmt psconvert tmp.eps -TG -A -P -D/home/yono2844/Workspace/sample-app/src/components/ -Fm
ap.png

이미지 붙여넣기



/sample-app/src/components/Map.js
import React, { useEffect } from "react";
import L from "leaflet";
import "leaflet/dist/leaflet.css";
import icon from "leaflet/dist/images/marker-icon.png";
import shadow from "leaflet/dist/images/marker-shadow.png";
import img from "./map.png";

L.Marker.prototype.options.icon = L.icon({
  iconUrl: icon,
  shadowUrl: shadow,
});

const imageUrl = img;
const imageBounds = [
  [-80, -180], // lowerLeft[lat, lng]
  [80, 180], // upperRight[lat, lng]
];

const Map = () => {
  useEffect(() => {
    // https://leafletjs.com/index.html
    var map = L.map("map").setView([0, 0], 2);
    L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
      attribution:
        '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
    }).addTo(map);

    // https://leafletjs.com/reference0.7.1.html#imageoverlay
    L.imageOverlay(imageUrl, imageBounds, { opacity: 0.4 }).addTo(map);
  }, []);
  return <div id="map" style={{ height: "100vh" }}></div>;
};

export default Map;

js/sample-app/src/components/App.js
import React from "react";
import Map from "./components/Map";

const App = () => {
  return (
    <div>
      <Map />
    </div>
  );
};

export default App;

좋은 웹페이지 즐겨찾기