Changeset 2375904
- Timestamp:
- 09/05/2020 09:07:04 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-mapbox-gl-js/trunk/public/js/wp-mapbox-gl-js-public.js
r2368995 r2375904 157 157 // Add the icon image, then add layer 158 158 if(!map.hasImage(feature.properties.marker_icon_url)) { 159 var canvas = document.createElement('canvas'); 160 var ctx = canvas.getContext('2d'); 161 var img = document.createElement('img'); 162 img.onload = function() { 163 var sizingOfImage = feature.properties.marker_icon_url.split('-wp_mapbox_gl_js_sizing-')[1]; 164 var widthHeight = sizingOfImage ? sizingOfImage.split('-') : [100,100]; 165 canvas.width = widthHeight[0]; 166 canvas.height = widthHeight[1]; 167 ctx.drawImage(img, 0, 0, widthHeight[0], widthHeight[1]); 168 map.addImage(feature.properties.marker_icon_url, ctx.getImageData(0, 0, widthHeight[0], widthHeight[1]) ); 169 var markerOverlap = true; 170 if(typeof data.controls.markerNoDisappear !== 'undefined') { 171 markerOverlap = data.controls.markerNoDisappear; 172 } 173 var lineLayer = map.addLayer({ 174 'id': feature.id, 175 'type': 'symbol', 176 'source' : feature.id, 177 'layout': { 178 'icon-image': feature.properties.marker_icon_url, 179 'icon-anchor' : feature.properties.marker_icon_anchor, 180 'icon-size' : 0.2, 181 'icon-allow-overlap' : markerOverlap 159 if(feature.properties.marker_icon_url.indexOf('http') === -1) { 160 map.loadImage($('#wp_mapbox_gl_js_plugin_url').val()+'/wp-mapbox-gl-js/admin/wp-mapmaker/public/img/'+feature.properties.marker_icon_url, function(error, image) { 161 if (error) throw error; 162 map.addImage(feature.properties.marker_icon_url, image); 163 // default_marker.svg 164 var lineLayer = map.addLayer({ 165 'id': feature.id, 166 'type': 'symbol', 167 'source' : feature.id, 168 'layout': { 169 'icon-image': feature.properties.marker_icon_url, 170 'icon-anchor' : 'bottom', 171 'icon-size' : 0.2 172 } 173 }) 174 if(feature.properties.popup_open) { 175 var popup = new mapboxgl.Popup({ 176 offset : 20 177 }); 178 popup.setLngLat({lat: feature.geometry.coordinates[1], lng: feature.geometry.coordinates[0]}) 179 .setHTML( 180 '<div>'+ 181 '<div>'+feature.properties.description+'</div>'+ 182 '</div>' 183 ).addTo(map); 182 184 } 183 }) 184 if(feature.properties.popup_open) { 185 var popup = new mapboxgl.Popup({ 186 offset : 20, 187 className: 'wp_mapbox_gl_js_frontend_popup' 188 }); 189 popup.setLngLat({lat: feature.geometry.coordinates[1], lng: feature.geometry.coordinates[0]}) 190 .setHTML( 191 '<div>'+ 192 '<div>'+feature.properties.description+'</div>'+ 193 '</div>' 194 ).addTo(map); 195 196 popup._container.style.maxWidth = "66%"; 197 } 198 }; 199 img.src = feature.properties.marker_icon_url.split('-wp_mapbox_gl_js_sizing-')[0]; 185 }); 186 } else { 187 var canvas = document.createElement('canvas'); 188 var ctx = canvas.getContext('2d'); 189 var img = document.createElement('img'); 190 img.onload = function() { 191 var sizingOfImage = feature.properties.marker_icon_url.split('-wp_mapbox_gl_js_sizing-')[1]; 192 var widthHeight = sizingOfImage ? sizingOfImage.split('-') : [100,100]; 193 canvas.width = widthHeight[0]; 194 canvas.height = widthHeight[1]; 195 ctx.drawImage(img, 0, 0, widthHeight[0], widthHeight[1]); 196 map.addImage(feature.properties.marker_icon_url, ctx.getImageData(0, 0, widthHeight[0], widthHeight[1]) ); 197 var markerOverlap = true; 198 if(typeof data.controls.markerNoDisappear !== 'undefined') { 199 markerOverlap = data.controls.markerNoDisappear; 200 } 201 var lineLayer = map.addLayer({ 202 'id': feature.id, 203 'type': 'symbol', 204 'source' : feature.id, 205 'layout': { 206 'icon-image': feature.properties.marker_icon_url, 207 'icon-anchor' : feature.properties.marker_icon_anchor, 208 'icon-size' : 0.2, 209 'icon-allow-overlap' : markerOverlap 210 } 211 }) 212 if(feature.properties.popup_open) { 213 var popup = new mapboxgl.Popup({ 214 offset : 20, 215 className: 'wp_mapbox_gl_js_frontend_popup' 216 }); 217 popup.setLngLat({lat: feature.geometry.coordinates[1], lng: feature.geometry.coordinates[0]}) 218 .setHTML( 219 '<div>'+ 220 '<div>'+feature.properties.description+'</div>'+ 221 '</div>' 222 ).addTo(map); 223 224 popup._container.style.maxWidth = "66%"; 225 } 226 }; 227 img.src = feature.properties.marker_icon_url.split('-wp_mapbox_gl_js_sizing-')[0]; 228 } 200 229 } else { 201 230 var lineLayer = map.addLayer({
Note: See TracChangeset
for help on using the changeset viewer.