Comments (2)
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,
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.
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)
- AzureMapHtmlMarker not rendering with the correct html template HOT 2
- Custom Styling for Region Color Change at Zoom Level 2 HOT 2
- getting mapContext for AzureMapFeature HOT 3
- "source '[layer name]-RasterSource" not found" when using Tile Layer HOT 1
- @sangeetha321 , can you try our [`v1.0.0-beta.3` version](https://www.npmjs.com/package/react-azure-maps/v/1.0.0-beta.3)? You should be able to see consistent map style. We'll release our formal `v1.0.0` soon in case you want to use it on production site.
- Error after updating to version 1.0.0 from 0.1.4 - Cannot read properties of undefined (reading 'Map') HOT 3
- Error, after updating to version 1.0.0 from 0.1.4 - uncaught ReferenceError: _wrapNativeSuper is not defined HOT 2
- Error, after updating to version 1.0.0 from 0.1.4 - Error in azure-maps-indoor module HOT 3
- Is thre a reason for removing the dependency @testing-library/react-hooks in version 1.0.0 HOT 1
- After migrating to version 1.0.0 - Error encountered while running the test case: 'Cannot find module 'react-azure-maps' from 'src/map/Componentx.tsx'. HOT 1
- Popup content is non-interactive (react components are rendered as static markup in Popup content) HOT 6
- Animation does not work when using mapRef.setCamera with animation HOT 2
- Map not loading HOT 7
- azure map not loading in production with subscription key HOT 9
- Azure Map not loading correct in prod HOT 4
- Azure Map Popup rendering issue HOT 5
- Popup is showing bottom of the screen with latest version HOT 4
- IAzureMapLayerType and SymbolLayerOptions not found HOT 1
- Map loads in local, but does not load in azure dev environment HOT 4
- Control containers are outside of the map canvas HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-azure-maps.