Coder Social home page Coder Social logo

Comments (2)

yulinscottkang avatar yulinscottkang commented on July 24, 2024

hi @JLittner, there's a (not-so-pretty) workaround by rendering a hidden copy of your styled components outside of the <AzureMapsProvider> container, so that the css can be generated on the page. For example,

image

import * as React from "react";
import * as ReactDOM from "react-dom/client";
import { Button, styled } from "@mui/material";
import {
  AzureMap,
  AzureMapsProvider,
  AzureMapHtmlMarker
} from "react-azure-maps";
import { data } from "azure-maps-control";

const option = {
  zoom: 12,
  center: [-122.335, 47.62],
  authOptions: {
    authType: "subscriptionKey",
    subscriptionKey: "<subscriptionKey>"
  }
};

const position = new data.Position(-122.335, 47.62);

const StyledButton = styled(Button)(() => ({
  fontSize: 25
}));

function MyApp() {
  return (
    <>
      <AzureMapsProvider>
        <div style={{ height: "300px" }}>
          <AzureMap options={option}>
            <AzureMapHtmlMarker
              key="1"
              markerContent={
                <div className="pulseIcon">
                  <StyledButton variant="contained">Hello World</StyledButton>
                </div>
              }
              options={{ position }}
            />
          </AzureMap>
        </div>
      </AzureMapsProvider>
      <StyledButton style={{ display: "none" }} variant="contained"></StyledButton>
    </>
  );
}

ReactDOM.createRoot(document.querySelector("#app")).render(
  <React.StrictMode>
    <MyApp />
  </React.StrictMode>
);

from react-azure-maps.

JLittner avatar JLittner commented on July 24, 2024

Hi,
Thanks for fast answer.

I tried this approach but it didn't work for me. It could be because I had the styled component separated in another component with additional logic and this I tried to render outside of '' and than in the map.

I ended up with css classes and definition of styles for them in the parent component.

'
import * as React from "react";
import * as ReactDOM from "react-dom/client";
import { Button, styled } from "@mui/material";
import {
AzureMap,
AzureMapsProvider,
AzureMapHtmlMarker
} from "react-azure-maps";
import { data } from "azure-maps-control";

const option = {
zoom: 12,
center: [-122.335, 47.62],
authOptions: {
authType: "subscriptionKey",
subscriptionKey: ""
}
};

const position = new data.Position(-122.335, 47.62);

const AzureMapContainer = styled('div')(() => ({
height: '100%',
width: '100%',
overflow: 'hidden',

// Styled button
'& .styled-button': {
    fontSize: 25
},

}));

function MyApp() {
return (


<div style={{ height: "300px" }}>

<AzureMapHtmlMarker
key="1"
markerContent={
Hello World
}
options={{ position }}
/>



<StyledButton style={{ display: "none" }} variant="contained">

);
}

ReactDOM.createRoot(document.querySelector("#app")).render(
<React.StrictMode>

</React.StrictMode>
);
'

Thank you again for your support.

from react-azure-maps.

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.