Giter Site home page Giter Site logo

Comments (3)

rimzzlabs avatar rimzzlabs commented on May 26, 2024

this is just a small app for test assignment at my college, I know forking a repository is a bit complicated, so here's a demo video

ini.mp4

from react-leaflet.

rimzzlabs avatar rimzzlabs commented on May 26, 2024

Update

I decided to put code snippet instead here

Here's my GIS component

import { useGis } from '@/hooks/use-gis'

import { GisAreaItem } from './gis-area-item'

import type { LatLngExpression } from 'leaflet'
import { Loader2Icon } from 'lucide-react'
import { MapContainer, TileLayer } from 'react-leaflet'

export function Gis() {
  const query = useGis()

  const centerMap = [-6.118547, 106.153355] as LatLngExpression

  if (query.status === 'pending') {
    return (
      <div className='py-4'>
        <div className='flex flex-col items-center justify-center gap-2 w-full h-96 md:h-[30rem] aspect-square md:aspect-video rounded-md overflow-hidden bg-gray-100'>
          <Loader2Icon size='4rem' className='animate-spin' />
          <p className='text-sm'>Memuat Data</p>
        </div>
      </div>
    )
  }

  if (query.status === 'error') {
    return <p className='text-center py-4'>Terjadi error ketika memuat data</p>
  }

  return (
    <section className='py-4'>
      <div className='rounded-md overflow-hidden'>
        <MapContainer
          zoom={13}
          center={centerMap}
          scrollWheelZoom={false}
          className='w-full h-96 md:h-[30rem] '
        >
          <TileLayer
            attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
            url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
          />

          {query.data.map((item, i) => (
            <GisAreaItem {...item} key={item.location + i} />
          ))}
        </MapContainer>
      </div>
    </section>
  )
}

And here's my vector layer component

import { useGisDialog } from '@/hooks/use-gis-dialog'

import { TCoordinateItem } from '@/~types'

import type { LatLngExpression } from 'leaflet'
import { CircleMarker } from 'react-leaflet'

function getColor(level: TCoordinateItem['level']) {
  switch (level) {
    case 'high':
      return 'red'
    case 'medium':
      return 'orange'
    default:
      return 'yellow'
  }
}

export function GisAreaItem(props: TCoordinateItem) {
  const openGis = useGisDialog((store) => store.openDialog)

  const color = getColor(props.level)

  function onClickLayer() {
    openGis(props)
  }

  return (
    <CircleMarker
      eventHandlers={{
        click: onClickLayer,
      }}
      center={props.coordinates as LatLngExpression}
      pathOptions={{ color }}
      radius={props.radius}
    />
  )
}

from react-leaflet.

rimzzlabs avatar rimzzlabs commented on May 26, 2024

I am so embarrassed right now, I'll close this issue

In case anyone do this in the future
Solution:

  1. Check the documentation site again
  2. Make sure to use <Circle /> and not <CircleMarker />

Have a great day everyone

from react-leaflet.

Related Issues (20)

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.