Comments (7)
Hi @dandical,
Im tried to reproduce your issue, but I can't. Can you show us how you mutate bounds
in parent component?
Anyway I update example in https://github.com/WiredSolutions/react-azure-maps-playground and you can find this example named Change Options in Child
on bottom of list.
The code you can find here: Azure/react-azure-maps-playground@f79a6d1 - i use state and useState to mutate bounds and pass to child.
from react-azure-maps.
hi @psrednicki thanks for the reply.
So the difference in your version is you pass in a complete cameraOptions object as props to the child, I tried this and it works, the camera adjust accordingly. However, when I create the cameraOptions object in the component, using a bounds value passed in from the parent as in my example above it doesn't work. I also mutate bounds with useState in the parent component.
So to summarise requiring a parent to pass in cameraOptions object works. The alternate method of requiring a parent to pass in camera values and then creating a cameraOptions object in the component with these values does not.
from react-azure-maps.
@dandical Ok i got your point now.
Now I set all like you and its still work as expected. You can find it on example/bounds-option
branch in playground.
Can you show your parent component and show how exactly you mutate this bound so I can better understand how to help you.
from react-azure-maps.
Thanks for the reply again, I will try and find my example with cameraOptions not causing rerender, but for now I have the trivial example below which is kind of similar except with image sprites. Changing the image sprites props does not cause AzureMap and it's children to rerender. The symbols do not appear to start, which is acceptible since the image sprites aren't loaded in the map. After 3 seconds the setLocalSprites
should cause a rerender of Wrapper
, SpritesMutationExample
and AzureMap
along with it's children with the sprites now loaded. However, the rerender does not occur as I expect it should and the map remains empty.
const option: IAzureMapOptions = {
authOptions: {
authType: AuthenticationType.subscriptionKey,
subscriptionKey: key,
},
};
const markerBSprite: IAzureMapImageSprite = {
id: "b",
icon: ImageB,
};
const markerASprite: IAzureMapImageSprite = {
id: "a",
icon: ImageA,
};
const SpritesMutationExample = (props: { sprites: IAzureMapImageSprite[] }) => {
return (
<>
<div style={{ height: "300px" }}>
<AzureMapsProvider>
<AzureMap imageSprites={props.sprites} options={option}>
<AzureMapDataSourceProvider id={"data source provider"}>
<AzureMapLayerProvider
options={{
iconOptions: {
image: "a",
},
}}
type={"SymbolLayer"}
/>
<AzureMapFeature type="Point" coordinate={[120, 120]}></AzureMapFeature>
</AzureMapDataSourceProvider>
<AzureMapDataSourceProvider id={"new provider"}>
<AzureMapLayerProvider
options={{
iconOptions: {
image: "b",
},
}}
type={"SymbolLayer"}
/>
<AzureMapFeature type="Point" coordinate={[0, 0]}></AzureMapFeature>
</AzureMapDataSourceProvider>
</AzureMap>
</AzureMapsProvider>
</div>
</>
);
};
const Wrapper: React.FC = () => {
// sprites start off as empty
const [localSprites, setLocalSprites] = useState<IAzureMapImageSprite[]>([]);
// sprites 3 seconds after initial render
useEffect(() => {
setTimeout(() => {
setLocalSprites([markerASprite, markerBSprite]);
}, 3000);
}, []);
return <SpritesMutationExample sprites={localSprites} />;
};
export default Wrapper;
from react-azure-maps.
@dandical About this imageSprites props - its should be initialised on map init. So all sprites that you want to use should be added on map mount. I think dynamically changing sprites can cause side effect - but its possible to implement and add effect for that.
If you want to add dynamically adding sprites please open new issue and we will start work on it.
About dynamically changing props in <AzureMap />
component: for now in 0.1.2 version you can changing
trafficOptions
userInteraction
cameraOptions
userInteraction
In 0.1.3 we will add: styleOptions
and serviceOptions
If you need some more just open issue and tell us what you need. We will appreciate that!
from react-azure-maps.
Thanks @psrednicki I can't find the cameraOptions example again and your example is working for me so I assume I had something wrong so I closed the issue.
from react-azure-maps.
Also thanks you @dandical. Fell free to open new issue if you have any improvements or feature that you need.
from react-azure-maps.
Related Issues (20)
- "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
- Support for JS project HOT 3
- Custom cluster HOT 2
- AzureMapPopup Error: TypeError: Cannot read properties of undefined (reading 'getCurrentStack') HOT 6
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.