Drawing custom markers onto leaflet powered maps

During the life cycle of quite a number of web mapping projects, the GI user may want to deploy his or her custom markers or icons to symbolize points on the map.Our demonstration in this post will create a simple script where custom markers in svg format hosted on the web are added onto our leaflet powered map. Custom markers allows the map creator to enhance the cartographic visualization of the end user.

 

Lets create a simple leaflet map with base map tiles provided by Esri. Load point features in geojson file format and draw them to the map.

By default, the markers will appear in blue pin style on the map.

See source code of the map showing default markers

Document2-001

f

 

Next write out the var icon layer below the var points layer.

This will load custom markers on file or from the web.

Replace the previous L.geoJson(points… in the code with the one below.

Use the pointToLayer options to draw the new icons onto

the leaflet map.

 

var icon = L.icon({
iconUrl:”https://lh3.googleusercontent.com/_apJiX06lWEtuQSB2mhunUEV-iw2siA-5eoaIHZTD9g_GZv96ho6W6W_-66sVYwhohQMNBKNPQtRrWPeK3EbCpQJinTl5mtv-4MUTdTiAmTBJM_eMOlgerYayuEhfHEdtYKDMuteH1KqpDLgCZvp3X0qk0igdGEH_WxztSpXTfCPffCeRPYnHVcaSYKNrUoTkFQOrXLhd_8SgczOtA_OczAEKZ14v0ALJ5pfyOsI9Wx6dW7pT0BnDO7DMMswqy51eGyZCzDrVJnCw19x71jAkykBtB4kwDZR33lyF03jfqGoeJbK7FdL8Sw81mYr4gUL-3siPVsBT4Dkx1d5OtkjLFIiV3U_2sBjqHD6pqsJoRs29Xu-WUSxl14fgHD5dRVWj6HVa8oQ4vLQiGWnA0518VJ6R5WflD5rfHIWNgdDdYv7xXJG1kNQVl2MuffhUqFR14sI3nn6qHgMB-gxvBmNUcuMHFyGl7oIPB0dq7QNAnxHS43J5vRVYFWkzRZ6otNotfKhbcVLLyCzvjAMxq06G5AcpIbhb5Qmr3SKNuHdNddkiak9zAd3Wt5I_KDQ02KDUKqt=w119-h109-no”,
iconSize: [30, 30]
});
L.geoJson(points, {
pointToLayer: function(feature, latlng){
marker = L.marker(latlng, {icon: icon})
marker.bindPopup(feature.properties.name_1 + ‘<br>’ + feature.properties.ph)
return marker;}
}).addTo(map);

 

Capture-16

 

View live map at

http://htmlpreview.github.io/?https://github.com/mayotunde/webmap/blob/gh-pages/custommarkers

Download plain text version of the source code https://www.dropbox.com/s/c8eg71vdhwg7xr9/loading%20custom%20markers%20onto%20leaflet%20powered%20maps.txt?dl=0

 

Thank you for following the blog.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s