Git Product home page Git Product logo

test-arcgis's Introduction

初始化项目

1、初始化 npx create-react-app test-arcgis

2、新建页面 在页面层级建map需要的container

import React, { useEffect } from 'react';
import Map from '@arcgis/core/Map';
import MapView from '@arcgis/core/views/MapView';
import Basemap from '@arcgis/core/Basemap';
import TileLayer from '@arcgis/core/layers/TileLayer';

const MapComponent = () => {
  useEffect(() => {
    const map = new Map({
      basemap: new Basemap({
        baseLayers: [
          new TileLayer({
            url: 'https://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer',
          }),
        ],
      }),
    });

    const view = new MapView({
      container: 'mapView',
      map: map,
      center: [121, 31],
      zoom: 13,
    });
  }, []);

  return <div id="mapView" style={{ height: '100vh' }}></div>;
};

export default MapComponent;

3、添加search ui, 发现样式不对 导入css

// map-component.js
import './index.css';

// index.css
@import "~@arcgis/core/assets/esri/themes/light/main.css";

4、点击图层 添加popup ,发现无法显示 popup arcgis js API

    view.popupEnabled = false;  // 添加这一行就可以显示popup: 禁止自动展示,通过openPopup唤起
    view.on("click", (event) => {
      const lat = Math.round(event.mapPoint.latitude * 1000) / 1000;
      const lon = Math.round(event.mapPoint.longitude * 1000) / 1000;

      view.openPopup({
        title: "Reverse geocode: [" + lon + ", " + lat + "]",
        location: event.mapPoint // Set the location of the popup to the clicked location
      });
    });

5、添加天气组件


  const view = new SceneView({
      container: 'mapView',
      map: map,
      center: [121, 31],
      zoom: 12,
    });

    const weatherWidget = new Weather({
      view: view,
    });

    view.ui.add(weatherWidget, 'top-left');


test-arcgis's People

Contributors

qqxu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.