How to add layer over full map in apple mapkit JS - mapkit-js

I am trying to customize my apple map on web (Mapkit JS). I know you can set the maps colorScheme (Light or Dark). But is there a better way to customize it with more colors?

Yes, you can use a PolygonOverlay and set a custom color to it. Your map will then appear in your desired color.
// init mapkit
mapkit.init({...});
// init map
const map = new mapkit.Map("mapId", {
colorScheme: mapkit.Map.ColorSchemes.Light, // mapkit.Map.ColorSchemes.Dark
});
// polygon points
const points = [
[89.9,90],
[89.9,0.1],
[89.9,-90],
[89.9,-179.999],
[0,-179.999],
[-89.9,-179.999],
[-89.9,-90],
[-89.9,0.1],
[-89.9,90],
[-89.9,179.999],
[0,179.999],
[89.9,179.999]
];
// Map the coordinate points to Coordinates:
const coordinates = points.map((point) => new mapkit.Coordinate(point[0], point[1]));
const polygon = new mapkit.PolygonOverlay(coordinates, {
style: new mapkit.Style({
lineWidth: 0,
strokeColor: "transparent", // you can define HEX values as you wish
fillColor: "#F00F00", // red overlay
}),
selected: true
})
// add overlay over the whole map
map.addOverlay(polygon);

Related

How can I draw polygons on google maps flutter at my current position as I move My device-Live Location Tracing

While there exist a variety or recourses already talking about something close to this, I mean this. I want to dynamically trace say a small forest/Building as I go around it live on google maps, I.e., If I stand at the edge of a building in the field with my phone (With my currentlocationenabled: true), I can trace the building from start to end and come back and close it at the starting point. Currently, I can draw any polygon anywhere on the map, but I want a dynamic one: When I go to the edge of a building I call the drawPolygonNow(), then so on and so on. My current sample code, that was guided by this resource:
class _MyMapScreenState extends State<MyMapScreen> {
LatLng latLngPosition = LatLng(userCurrentPosition!.latitude, userCurrentPosition!.longitude);
/* Data: Add point markers, lines, polygons */
Set<Marker> _markers = {};
Set<Polygon> _polygons = HashSet<Polygon>();
List<LatLng> polygonLatLngs1 = <LatLng>[];
// Draw Polygon
void _drawPolygon(LatLng latLngPosition) {
final String polygonIdVal = 'Area ID_$_polygonIdCounter';
_polygons.add(Polygon(
polygonId: PolygonId("1"),
points: polygonLatLngs1,
strokeWidth: 2,
strokeColor: strokeColor,
fillColor: fillColor
));
body: Stack(
children[
GoogleMp(
polygons: _polygons,
onCameraMove: _onCameraMove,
onTap: (latLngPosition) {
if (_isPolygon) {
setState(() {
polygonLatLngs1.add(latLngPosition);
_drawPolygon(latLngPosition);
});
}
},
...

Mapbox GL JS with Maki icons by Marker

I generated a list of Maki Icons I want to use via the original icon editor.
drawMarkers() {
let self = this;
const mapboxgl = require("mapbox-gl");
let data = this.draw.getAll();
data.features.forEach((feature) => {
if (feature.geometry.type == "Point") {
var icon = feature.properties.icon;
var title = feature.properties.title;
if (typeof title === "undefined") {
title = "Info";
} else {
var popup = new mapboxgl.Popup({ offset: 25 }) // add popups
.setHTML(`<h3>${title}</h3>`);
var marker = new mapboxgl.Marker({
color: '#333',
draggable: false,
scale: 1,
})
.setLngLat(feature.geometry.coordinates)
.setPopup(popup)
.addTo(self.map);
}
});
The Markers are showed correctly on the Mapbox.
The GeoJSON is like this:
"type":"FeatureCollection",
"features":[
{
"id":"c749de6a6eac6b1cfdda890e7c665e0d",
"type":"Feature",
"properties":{
"icon":"ferry",
"title":"This should show a Ferry icon",
"portColor":"#d9eb37"
},
"geometry":{
"coordinates":[
6.12,
22.44
],
"type":"Point"
}
},
I want the Maki Icons also added in the Marker, but I cannot find any documentation of how icons can be used inside the Mapbox Marker.
Who can help me out? I'm using the Mapbox GL JS for Web.
It depends on how you've created your map. You can either:
Create your own map style using the Maki icons you've generated. This is done using the Mapbox studio to create your custom map style, then adding it to your application.
Create custom markers that use the maki .svg files you've created. This can be done by passing a custom element to the new mapboxgl.Marker() function. So, instead of:
var marker = new mapboxgl.Marker({
color: '#333',
draggable: false,
scale: 1,
})
you would pass:
var marker = new mapboxgl.Marker(customElement)
where customElement uses the data from your icons variable.
I'm not sure if you're using plain JS here, but there's some examples on the mapbox docs of ways you can do this.
Because you've generated your own list of Maki icons, I'd suggest downloading them and maybe host them somewhere so that you can get away with creating your markers with <img src="link to hosted maki marker"/> or something of the sort

How to apply css on polylines : leaflet

I am working with the application which uses leaflet api.
Introduction
I needed to draw different types of fences, using decorators i can somewhat apply good visuals to the polylines but not much.
Problem
I was willing to show twisted wires instead of dashes, dots or plain lines and I know the twisted wire line will be an image but can't find help about applying custom css to polylines.
Script Example
var fence2Icon = L.icon({
iconUrl: 'xxxx.png',
iconSize: [5, 20]
iconAnchor: [5, 18]
});
// Add coordinate to the polyline
var polylineFence2 = new L.Polyline([], { color: 'red' });
function fencePlace2(e) {
// New marker on coordinate, add it to the map
new L.Marker(e.latlng, { icon: fence2Icon, draggable: false }).addTo(curr);
// Add coordinate to the polyline
polylineFence2.addLatLng(e.latlng).addTo(curr);
var decorator = L.polylineDecorator(polylineFence2, {
patterns:[{offset:5,repeat:'20px',symbol:new L.Symbol.Dash({pixelSize:5})
}]
}).addTo(curr);
}
L.easyButton('fa-flash', function () {
$('.leaflet-container').css('cursor', 'crosshair');
map.on('click', fencePlace2);
polylineFence2 = new L.Polyline([], { color: 'red' });
}).addTo(map);
If someone know anything about polyline or another way please do help.
Thanks for your time:-)
You can add a class in the options of your polyline ...
var polyline = L.polyline(latlngs, { className: 'my_polyline' }).addTo(map);
and add your own settings in the CSS ...
.my_polyline {
stroke: green;
fill: none;
stroke-dasharray: 10,10;
stroke-width: 5;
}
Here is an example: http://jsfiddle.net/FranceImage/9dggfhnc/
You can also access some options directly ...
var polyline = L.polyline(latlngs, { dashArray: '10,10' }).addTo(map);
See Path Options
If you create a polyline you're in fact adding an element to the SVG element which Leaflet uses to draw it's overlays. Styling SVG path elements is different from styling regular HTML elements. There's no such thing as border and background-color etc. It has different properties, if you're interested here's a nice read on the matter:
https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Fills_and_Strokes
You can style Leaflet's path elements when you instanciate them via options or via CSS using the properties (related to styling) described in the documentation here:
http://leafletjs.com/reference.html#path
Via options:
new L.Polyline([...], {
weight: 3,
color: 'red',
opacity: 0.5
}).addTo(map);
Via CSS:
new L.Polyline([...], {
className: 'polyline'
}).addTo(map);
.polyline {
weight: 3,
color: red,
opacity: 0.5
}
However, what you want, using an image simply isn't possible. You can use images as fill for SVG paths, but it would be impossible for your usecase. You'de need to add a pattern definition to the SVG Leaflet is using and then you could use that id as the fill property as outlined in this answer:
https://stackoverflow.com/a/3798797/2019281 but will always fill/tile the image horizontally which won't work if your polyline is vertical.

Icon url in mapbox

How to add a custom icon in mapbox?
var map = L.mapbox.map('map', 'mapbox.streets').setView([0, 0], 1);
var geojson = { type: 'LineString', coordinates: value};
var start = value[0];
var end = value[value.length-1];
geojson.coordinates.push((start,end).slice());
// Add this generated geojson object to the map.
L.geoJson(geojson).addTo(map);
// Create a marker and add it to the map.
var marker = L.marker(end, {
icon: L.mapbox.marker.icon({
"iconUrl": "https://www.mapbox.com/mapbox.js/assets/images/astronaut2.png"
})
}).addTo(map);
});
I can't able to add a custom icon in above code. Please help me..
Thanks.
First you will have to create a var, for example 'myIcon', then simply replace the iconUrl with a path that specifies the custom marker you want to use.
You can use the iconSize option to specify the size of your marker
You can use the iconAnchor option to specify which part of your masker should be placed on the latlng.
myIcon=L.icon({
iconUrl:'img/custom-marker.png',
iconSize: [25,30]
});
Then create the marker, set the lat lng where you want your marker to be placed. And specify the icon you want to use.
var Marker = new L.Marker ( latlng, {icon:myIcon});
Finally add your market to the map:
map.addlayer(Marker);

delete the marker along the circle around it

I am working with Open Street Maps and using leaflet library.
I have a layer group like this:
var testLayer = new L.LayerGroup(); --> declared in a different file
I want to add markers to a marker group, add a circle around each marker, and add the marker group to the map:
var realMarker = L.marker([52.6432, -6.53412 ],{icon: Icon,title:data[choice][key]["name"]
}).bindPopup("Dublin").addTo(testLayer);
var circle = L.circle([52.6432, -6.53412 ],400, {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5
}).addTo(testLayer);
map.addLayer(testLayer);
However, when I delete a particular marker from the marker group by using removeLayer(), the marker is removed from the map but the circle is left behind. How can I delete the circle along with the marker?
I'd store a reference to the circle in the marker:
var realMarker = L.marker([52.6432, -6.53412 ],
{icon: Icon,title:data[choice][key]["name"]}
).bindPopup("Dublin").addTo(testLayer);
var circle = L.circle([52.6432, -6.53412 ],400, {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5
}).addTo(testLayer);
realMarker.circle=circle;
map.addLayer(testLayer);
Then, when removing the marker, also remove its circle
testLayer.removeLayer(markerToRemove);
testLayer.removeLayer(markerToRemove.circle);